dev@jsftemplating.java.net

Re: JSF Templating Problem Demo App (RISTRETTO)

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Thu, 19 Jun 2008 11:53:43 -0700

Hi Jaco,

No problem! However, I suggest sending JSFT questions to the
dev_at_jsftemplating email list (I've cc'd that list) so that you can get
help from the whole team and so others can learn from your questions.

To create a component which repeats the "text" property the number of
times specified by the "count" property, you can do this in the
"template" format:

  <!while #{idx}<$property{count}>
      <!beforeLoop
          setAttribute(key="idx" value="0");
      />
      <!encode
          inc(number="#{idx}" value=>$attribute{idx});
      />
      "$property{text}
  </while>

The same thing in the XML format:

<!DOCTYPE layoutDefinition SYSTEM "/jsftemplating/layout.dtd" >

<layoutDefinition>
    <layout>
        <while condition="$property{count}>#{idx}">
            <event type="beforeLoop">
                <handler id="setAttribute">
                    <input name="key" value="idx" />
                    <input name="value" value="0" />
                </handler>
            </event>
            <event type="encode">
                <handler id="inc">
                    <input name="number" value="#{idx}" />
                    <outputMapping outputName="value"
targetType="attribute" targetKey="idx" />
                </handler>
            </event>

            <!-- Render the static text -->
            <staticText>$property{text}</staticText>
        </while>
    </layout>
</layoutDefinition>

You only need to do 1 of the 2 above example. I provided them both b/c
I created the XML one based off the while.xml implementation checked
into JSFTemplating's source tree... but then decided it was too ugly :)
(it's JSFT's first format and is very verbose -- I don't recommend using
it). So I decided to convert it to the "template" format which is the
fastest and most efficient format JSFT supports. The facelets format
*should* also work, although I haven't tested it as much so there may be
some bugs.

I ran both of the above example on my machine and they both work, for
example:

    <my:customComponent text="Hello World!" count="2" />

Produces:

    Hello World!Hello World!

I hope this helps!

Ken

Jaco Prinsloo wrote:
> Hi Ken, sorry to bother you again.
>
> I'm trying to do the following, but I'm not sure how to do it or if it
> is even possible in JSFT:
> I'd like to create a custom tag which looks like this
> <my:customComponent text="Hello World!" count="2" />.
> That tag should be parsed to return two <h:outputText /> elements,
> both containing the text "Hello World!".
> In other words, the text attribute determines what to display and the
> count attribute how many times to display it.
>
> I understand the article examples which create HTML markup
> dynamically, but how can I do the same for other JSF components (in
> this case h:outputText)?
>
> Thank you,
> Jaco
>
> On Wed, Jun 18, 2008 at 5:16 PM, Jaco Prinsloo <jmprinsloo_at_gmail.com
> <mailto:jmprinsloo_at_gmail.com>> wrote:
>
> I used exactly the same app that I sent you - I only added the
> slash and then modified the Template.xhtml to contain valid JSF
> markup in order to get it to work. Thanks for all your help - I'll
> definitely be giving the debug mode a try.
>
> Once again, thanks a lot!
> Jaco
>
>
> On Wed, Jun 18, 2008 at 4:54 PM, Ken Paulsen <Ken.Paulsen_at_sun.com
> <mailto:Ken.Paulsen_at_sun.com>> wrote:
>
>
> What was the jsf mapping in your web.xml file? I noticed it
> was *.xhtml in the example you sent me. So using that mapping
> and having the file named Template.xhtml, it worked. If you
> tried *.jsf and named the file *.xhtml, it would not have
> found it (b/c the default suffix for that format is *.jsf, so
> it wouldn't have looked for *.xhtml).
>
> Otherwise, you just needed to restart your server to make it
> work. If you enabled debug mode, you can now switch back and
> forth between the 2 formats w/o restarting the server and you
> will see any changes you make.
>
>
> Ken
>
> Jaco Prinsloo wrote:
>> Hi Ken,
>>
>> Nevermind, I got it to work.
>> I replaced the template content with the following:
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
>> Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>> <html xmlns="http://www.w3.org/1999/xhtml"
>> xmlns:h="http://java.sun.com/jsf/html"
>> xmlns:f="http://java.sun.com/jsf/core"
>> xmlns:ui="http://java.sun.com/jsf/facelets">
>>
>> <h:outputText value="IT WORKS!"/>
>>
>> </html>
>>
>> Any idea why just "IT WORKS! didn't work?
>>
>> Thank you,
>> Jaco
>>
>> On Wed, Jun 18, 2008 at 12:19 PM, Jaco Prinsloo
>> <jmprinsloo_at_gmail.com <mailto:jmprinsloo_at_gmail.com>> wrote:
>>
>> Thanks for the response, Ken.
>> Unfortunately that didn't solve my problem:
>>
>> A LayoutDefinition was not provided for
>> '/Templates/Template.xhtml'! This is required.
>>
>> Anything else that I might be missing?
>> Does the WAR work correctly on your server?
>>
>> Thank you,
>> Jaco
>>
>>
>> On Wed, Jun 18, 2008 at 10:04 AM, Ken Paulsen
>> <Ken.Paulsen_at_sun.com <mailto:Ken.Paulsen_at_sun.com>> wrote:
>>
>>
>> Hi Jaco,
>>
>> You are right, it was a *very* small mistake. :) I
>> should have caught this right away when you asked
>> yesterday, but sometimes the small mistakes are the
>> hardest to find.
>>
>> In "src/com/test/TestComponent.java" add a leading
>> '/' character in front of the path so that it looks
>> like this:
>>
>> setLayoutDefinitionKey("/Templates/Template.xhtml");
>>
>> That's it!
>>
>> You don't need the factory class
>> (src/com/test/TestFactory.java) at all if you're
>> using a facelets taglib file. Also, if you want use
>> the factory you need to compile with "apt" instead of
>> "javac". I can then show you how to use the factory
>> w/o a facelets taglib file.
>>
>> Good luck!
>>
>> Ken
>>
>>
>>
>> Jaco Prinsloo wrote:
>>
>> Hi Ken,
>>
>> Thanks for taking the time to have a look at my
>> demo app.
>> I just can't shake the feeling that my problem is
>> caused by a small, stupid mistake - but I can't
>> find it.
>> Have a look at the build file, there's one
>> property that you'll need to change.
>>
>> Thanks a lot,
>> Jaco Prinsloo
>>
>>
>>
>
>