Skip to main content

JSF 2.0 support of Facelets TagHandler

16 replies [Last post]
martinahrer
Offline
Joined: 2010-01-01

For a JSF 1.2 (with facelets 1.1.14) based application I had implemented a few "custom tags" based on the abstract com.sun.facelets.tag.TagHandler class. These tags are kind of providing conditional rendering of child content (Described in my blog at http://www.martinahrer.at/blog/2009/10/20/control-rendering-of-ui-elemen...).

After migrating that application to JSF 2.0.2 I experience a very different behaviour. TagHandlers now seem to be executed during the RESTORE_VIEW phase while in the JSF 1.2 version it was executed during the RENDER_RESPONSE phase. This change breaks my tags as they evaluate validation messages to provide the conditional rendering logic.

So I'd like to know what the current state of the facelets API is. What features from the initial facelets library are supposed to be supported in JSF 2?

I have found this posting from Ed http://weblogs.java.net/blog/edburns/archive/2009/10/15/jsf2-facelet-tag... which makes me assume that the standardization of facelets is not quite completed?

Is there any workaround currently available to make my tags work with some acceptable amount of required changes?

Thanks for your feedback!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
martinahrer
Offline
Joined: 2010-01-01

Ed,

thanks for your very detailed answer and confirming what I suspected. And, yes I have already started with creating a custom component but it used to be much easier with facelets taghandlers.

Martin

Ed Burns

On 1/1/10 8:09 AM, webtier@javadesktop.org wrote:

MA> After migrating that application to JSF 2.0.2 I experience a very
MA> different behaviour. TagHandlers now seem to be executed during the
MA> RESTORE_VIEW phase while in the JSF 1.2 version it was executed
MA> during the RENDER_RESPONSE phase. This change breaks my tags as they
MA> evaluate validation messages to provide the conditional rendering
MA> logic.

Yes, we needed to make this change to implement many of the new features
in JSF 2.0, including partial state saving, view metadata, and
bookmarkability.

MA> So I'd like to know what the current state of the facelets API
MA> is. What features from the initial facelets library are supposed to
MA> be supported in JSF 2?

Our goal with facelets in JSF 2.0 was to have 100% backwards
compatibility at the markup layer. Specifically, if the string "import
com.sun.facelets" does not appear in any of the source code of your
application, or in the source code of any of the dependencies of your
application, your facelet pages will work 100% without modification.

If "import com.sun.facelets" *does* appear in your application or
dependencies, your options all start with what I show in my blog entry,
which you have alreaady cited.

Regarding current state, we still have more work to do regarding the tag
layer of the Facelets API. We have plans to expand on what facelets
offers and give even greater control at runtime for the construction of
the UIComponent tree. Ken Paulsen and Imre Osswald have done some
excellent prototype work they are calling View Abstract Syntax Tree
(VAST) based on the best ideas from JSFTemplating and Facelets. This
work was not mature enough to include in JSF 2.0

MA> For a JSF 1.2 (with facelets 1.1.14) based application I had
MA> implemented a few "custom tags" based on the abstract
MA> com.sun.facelets.tag.TagHandler class. These tags are kind of
MA> providing conditional rendering of child content (Described in my
MA> blog at
MA>
http://www.martinahrer.at/blog/2009/10/20/control-rendering-of-ui-elemen...).

As you have discovered, this is a tricky problem. There are several
kinds of corner cases that must be considered when trying to solve this
problem. The first, and possibly most difficult, is the class of
problems that deals with modifications to the tree that would cause your
conditional values to evaluate differently between refreshes of the
component tree. Generally, we want to always have the complete tree
built, as if every condition evaluated to true, then only traverse the
parts that need to be rendered. However, this is impractical when you
have gigantic numbers of components.

You're right, we haven't figured out the most general solution yet.

MA> Is there any workaround currently available to make my tags work
MA> with some acceptable amount of required changes?

Your tag is supposed to cause a subtree to be rendered only if there are
FacesMessages on the FacesContext, right?

I recommend doing a custom component behind the tag and do the check in
its encodeBegin() method.

Others on this list may have helpful ideas too.

Ed

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Celinio Fernandes

Hi,
I have what i believe is a simple question for those who are familiar with JSF.
I am not too familiar so before digging any further in the documentation i thought i'd ask here for advice.

My problem is quite simple: I want to display in a table the result of a JPQL query.
That query looks like this :
select a.name, b.title,  b.age from table1 a, table2 b where a.id = b.id

So it returns a "list of lists" that looks like this:
((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),

If i store the result of that query in an ArrayList (myList) in my Managed Bean, I can then do this in my XHTML page:


   
        
   

That of course does not work.
First because it displays the listing in one column only whereas there are 3 elements in each list. Secondly because item points to the list object, not an element of the list.

How do i do that in JSF 2 ? Maybe with EL ?

Thanks for helping.

[att1.html]

Lincoln Baxter, III

If I'm reading this correctly. #{item} is a List object. You could use
another nested or another nested to iterate over
the results (columns) of #{item}.

I think your situation is that you're trying to display a multidimensional
array with an uni-dimensional table.

--Lincoln

On Sat, Jan 2, 2010 at 12:55 PM, Celinio Fernandes
wrote:

> Hi,
> I have what i believe is a simple question for those who are familiar with
> JSF.
> I am not too familiar so before digging any further in the documentation i
> thought i'd ask here for advice.
>
> My problem is quite simple: I want to display in a table the result of a
> JPQL query.
> That query looks like this :
> select a.name, b.title, b.age from table1 a, table2 b where a.id = b.id
>
> So it returns a "list of lists" that looks like this:
> ((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),
>
> If i store the result of that query in an ArrayList (myList) in my Managed
> Bean, I can then do this in my XHTML page:
>
>
>
>
>

>
>
> That of course does not work.
> First because it displays the listing in one column only whereas there are
> 3 elements in each list. Secondly because item points to the list object,
> not an element of the list.
>
> How do i do that in JSF 2 ? Maybe with EL ?
>
> Thanks for helping.
>
>
>
>
[att1.html]

Celinio Fernandes

thanks for your help.
Well, i have multiple entities in the result of my SELECT.
My question is similar to this one in the Sun forum : http://72.5.124.102/thread.jspa?threadID=5397095&messageID=10763941

Not sure how to properly handle a list that contains multiple entities.
Any idea ?

--- On Sun, 1/3/10, Lincoln Baxter, III
wrote:

From: Lincoln Baxter, III
Subject: Re: [webtier] How to handle a list in JSF 2
To: webtier@glassfish.dev.java.net
Date: Sunday, January 3, 2010, 12:00 AM

If I'm reading this correctly. #{item} is a List object. You could use another nested or another nested to iterate over the results (columns) of #{item}.

I think your situation is that you're trying to display a multidimensional array with an uni-dimensional table.

--Lincoln

On Sat, Jan 2, 2010 at 12:55 PM, Celinio Fernandes
wrote:

Hi,
I have what i believe is a simple question for those who are familiar with JSF.
I am not too familiar so before digging any further in the documentation i thought i'd ask here for advice.

My problem is quite simple: I want to display in a table the result of a JPQL query.

That query looks like this :
select a.name, b.title,  b.age from table1 a, table2 b where a.id = b.id

So it returns a "list of lists" that looks like this:
((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),

If i store the result of that query in an ArrayList (myList) in my Managed Bean, I can then do this in my XHTML page:


   
         />
   

That of course does not work.
First because it displays the listing in one column only whereas there are 3 elements in each list. Secondly because item points to the list object, not an element of the list.

How do i do that in JSF 2 ? Maybe with EL ?

Thanks for helping.

[att1.html]

Lincoln Baxter, III

Ahh... good point.

I'm not sure there's a good way to do this. You could, however, look in to
extending the UIData class for use in the datatable value="" binding from
your backing bean. Perhaps providing some basic reflection-based property
discovery in order to properly iterate over fields in each entity.

--Lincoln

On Sat, Jan 2, 2010 at 1:52 PM, Celinio Fernandes
wrote:

> thanks for your help.
> Well, i have multiple entities in the result of my SELECT.
> My question is similar to this one in the Sun forum :
> http://72.5.124.102/thread.jspa?threadID=5397095&messageID=10763941
>
> Not sure how to properly handle a list that contains multiple entities.
> Any idea ?
>
>
> --- On *Sun, 1/3/10, Lincoln Baxter, III
* wrote:
>
>
> From: Lincoln Baxter, III
> Subject: Re: [webtier] How to handle a list in JSF 2
> To: webtier@glassfish.dev.java.net
> Date: Sunday, January 3, 2010, 12:00 AM
>
>
> If I'm reading this correctly. #{item} is a List object. You could use
> another nested or another nested to iterate over
> the results (columns) of #{item}.
>
> I think your situation is that you're trying to display a multidimensional
> array with an uni-dimensional table.
>
> --Lincoln
>
> On Sat, Jan 2, 2010 at 12:55 PM, Celinio Fernandes
> > wrote:
>
>> Hi,
>> I have what i believe is a simple question for those who are familiar with
>> JSF.
>> I am not too familiar so before digging any further in the documentation i
>> thought i'd ask here for advice.
>>
>> My problem is quite simple: I want to display in a table the result of a
>> JPQL query.
>> That query looks like this :
>> select a.name, b.title, b.age from table1 a, table2 b where a.id = b.id
>>
>> So it returns a "list of lists" that looks like this:
>> ((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),
>>
>> If i store the result of that query in an ArrayList (myList) in my Managed
>> Bean, I can then do this in my XHTML page:
>>
>>
>>
>>
>>

>>
>>
>> That of course does not work.
>> First because it displays the listing in one column only whereas there are
>> 3 elements in each list. Secondly because item points to the list object,
>> not an element of the list.
>>
>> How do i do that in JSF 2 ? Maybe with EL ?
>>
>> Thanks for helping.
>>
>>
>>
>>
>
>
[att1.html]

Celinio Fernandes

Thanks again for helping.
Well,
I used a DTO to handle the result of the query. It works. I do not like that method though.

I am surprised that JSF 2 does not automatically handle that kind of list. I mean it's a standard type of result. Not all queries can return just one entity.

Unless someone has another idea or approach to handle it, i might check other implementations of the datatable component from third-parties.

By the way, i know i should check the documentation first, which i will pretty soon, but do you know if the Ajax features that have been integrated in JSF 2.0 bring anything new to the datatable component ?

Thanks

--- On Sun, 1/3/10, Lincoln Baxter, III
wrote:

From: Lincoln Baxter, III
Subject: Re: [webtier] How to handle a list in JSF 2
To: webtier@glassfish.dev.java.net
Date: Sunday, January 3, 2010, 1:42 AM

Ahh... good point.

I'm not sure there's a good way to do this. You could, however, look in to extending the UIData class for use in the datatable value="" binding from your backing bean. Perhaps providing some basic reflection-based property discovery in order to properly iterate over fields in each entity.

--Lincoln

On Sat, Jan 2, 2010 at 1:52 PM, Celinio Fernandes
wrote:

thanks for your help.
Well, i have multiple entities in the result of my SELECT.
My question is similar to this one in the Sun forum : http://72.5.124.102/thread.jspa?threadID=5397095&messageID=10763941

Not sure how to properly handle a list that contains multiple entities.
Any idea ?

--- On Sun, 1/3/10, Lincoln Baxter, III
wrote:

From: Lincoln Baxter, III

Subject: Re: [webtier] How to handle a list in JSF 2
To: webtier@glassfish.dev.java.net
Date: Sunday, January 3, 2010, 12:00 AM

If I'm reading this correctly. #{item} is a List object. You could use another nested or another nested
to iterate over the results (columns) of #{item}.

I think your situation is that you're trying to display a multidimensional array with an uni-dimensional table.

--Lincoln

On Sat, Jan 2, 2010 at 12:55 PM, Celinio Fernandes
wrote:

Hi,
I have what i believe is a simple question for those who are familiar with JSF.
I am not too familiar so before digging any further in the documentation i thought i'd ask here for advice.

My problem is quite simple: I want to display in a table the result of a JPQL query.

That query looks like this :
select a.name, b.title,  b.age from table1 a, table2 b where a.id = b.id

So it returns a "list of lists" that looks like this:
((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),

If i store the result of that query in an ArrayList (myList) in my Managed Bean, I can then do this in my XHTML page:


   
         />
   

That of course does not work.
First because it displays the listing in one column only whereas there are 3 elements in each list. Secondly because item points to the list object, not an element of the list.

How do i do that in JSF 2 ? Maybe with EL ?

Thanks for helping.

[att1.html]

Lincoln Baxter, III

>
> By the way, i know i should check the documentation first, which i will
> pretty soon, but do you know if the Ajax features that have been integrated
> in JSF 2.0 bring anything new to the datatable component ?
>

They do not, but of course, can now be ajaxified ;)

If you think this is something JSF should be doing for you, consider filing
an enhancement request here:

https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues

or you can post a thread here:

http://wiki.jcp.org/boards/index.php?b=jsr-314-public (you need a JCP.org
account)

these links are all available here:

http://www.javaserverfaces.org/home

--Lincoln
[att1.html]

Celinio Fernandes

I posted that issue (enhancement)  :
Issue 713 postedEmail sent to: issues@javaserverfaces-spec-public, javaserverfowner, longbeach, lidia

Not sure i posted it right, this is the first time i do it.

--- On Sun, 1/3/10, Lincoln Baxter, III
wrote:

From: Lincoln Baxter, III
Subject: Re: [webtier] How to handle a list in JSF 2
To: webtier@glassfish.dev.java.net
Date: Sunday, January 3, 2010, 2:34 AM

By the way, i know i should check the documentation first, which i will
pretty soon, but do you know if the Ajax features that have been
integrated in JSF 2.0 bring anything new to the datatable component ?

They do not, but of course, can now be ajaxified ;)

If you think this is something JSF should be doing for you, consider filing an enhancement request here:

https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues

or you can post a thread here:

http://wiki.jcp.org/boards/index.php?b=jsr-314-public (you need a JCP.org account)

these links are all available here:

http://www.javaserverfaces.org/home

--Lincoln

[att1.html]

Jason Lee

UIData is designed to handle multiple entry data sets, including Lists.
What's the data type in the List? You say this:

((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN)

Are those JPA entities? If so, you should be able to use #{item.name}, etc.

Unless I'm missing something...

On 1/2/10 3:34 PM, Celinio Fernandes wrote:
> I posted that issue (enhancement) :
> Issue 713 posted
> *Email sent to:* issues@javaserverfaces-spec-public, javaserverfowner,
> longbeach, lidia
>
> Not sure i posted it right, this is the first time i do it.
>
> --- On *Sun, 1/3/10, Lincoln Baxter, III /
/*
> wrote:
>
>
> From: Lincoln Baxter, III
> Subject: Re: [webtier] How to handle a list in JSF 2
> To: webtier@glassfish.dev.java.net
> Date: Sunday, January 3, 2010, 2:34 AM
>
> By the way, i know i should check the documentation first,
> which i will pretty soon, but do you know if the Ajax features
> that have been integrated in JSF 2.0 bring anything new to the
> datatable component ?
>
>
> They do not, but of course, can now be ajaxified ;)
>
> If you think this is something JSF should be doing for you,
> consider filing an enhancement request here:
>
> https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues
>
> or you can post a thread here:
>
> http://wiki.jcp.org/boards/index.php?b=jsr-314-public (you need a
> JCP.org account)
>
> these links are all available here:
>
> http://www.javaserverfaces.org/home
>
> --Lincoln
>
>

--
Jason Lee
Senior Java Developer
GlassFish Administration Console

Sun Microsystems, Inc.
Phone x31197/+1 405-343-1964
Email jasondlee@sun.com
Blog http://blogs.sun.com/jasondlee
Blog http://blogs.steeplesoft.com

[att1.html]

Celinio Fernandes

Thanks.
Although I have already found a solution, I am open to new ones.
I am not familiar with the UIData  component yet.
To try to explain things better when i say "results with multiple entities", here is an example of a query that looks like the one i use
and that i want to feed to my h:datatable :

SELECT a.id, c.name, t.address FROM Car a, Owner t, Bank c where a.id = t.id and t.id = c.id ;

Here the result is not mapped to a single existing entity (or DAO).

So, would it still work with UIData ? If yes, is there an example somewhere ? I suppose i'd have to create a DTO anyway.
Thanks.

--- On Sun, 1/3/10, Jason Lee wrote:

From: Jason Lee
Subject: Re: [webtier] How to handle a list in JSF 2
To: webtier@glassfish.dev.java.net
Date: Sunday, January 3, 2010, 4:56 AM

UIData is designed to handle multiple entry data sets, including
Lists.  What's the data type in the List?  You say this:

((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN,
ageN)

Are those JPA entities?  If so, you should be able to use #{item.name},
etc.

Unless I'm missing something...

On 1/2/10 3:34 PM, Celinio Fernandes wrote:

I posted that issue (enhancement)  :

Issue 713 posted
Email sent to:
issues@javaserverfaces-spec-public, javaserverfowner, longbeach, lidia

Not sure i posted it right, this is the first time i do it.

--- On Sun, 1/3/10, Lincoln Baxter, III
wrote:

From: Lincoln Baxter, III

Subject: Re: [webtier] How to handle a list in JSF 2

To: webtier@glassfish.dev.java.net

Date: Sunday, January 3, 2010, 2:34 AM

By the way, i know i should check the
documentation first, which i will
pretty soon, but do you know if the Ajax features that have been
integrated in JSF 2.0 bring anything new to the datatable component ?

They do not, but of course, can now be ajaxified ;)

If you think this is something JSF should be doing for you, consider
filing an enhancement request here:

https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues

or you can post a thread here:

http://wiki.jcp.org/boards/index.php?b=jsr-314-public
(you need a JCP.org account)

these links are all available here:

http://www.javaserverfaces.org/home

--Lincoln

--
Jason Lee
Senior Java Developer
GlassFish Administration Console

Sun Microsystems, Inc.
Phone x31197/+1 405-343-1964
Email jasondlee@sun.com
Blog http://blogs.sun.com/jasondlee
Blog http://blogs.steeplesoft.com

[att1.html]

Imre Osswald

if it is a list of list you can do the following:



#{item[0]}


#{item[1]}


#{item[2]}

Hope this helps,
Imre

(I wrote that before, but it does not seem to got through)

On 03.01.2010, at 00:44, Celinio Fernandes wrote:

> Thanks.
> Although I have already found a solution, I am open to new ones.
> I am not familiar with the UIData component yet.
> To try to explain things better when i say "results with multiple
> entities", here is an example of a query that looks like the one i use
> and that i want to feed to my h:datatable :
>
> SELECT a.id, c.name, t.address FROM Car a, Owner t, Bank c where
> a.id = t.id and t.id = c.id ;
>
> Here the result is not mapped to a single existing entity (or DAO).
>
> So, would it still work with UIData ? If yes, is there an example
> somewhere ? I suppose i'd have to create a DTO anyway.
> Thanks.
>
>
> --- On Sun, 1/3/10, Jason Lee wrote:
>
> From: Jason Lee
> Subject: Re: [webtier] How to handle a list in JSF 2
> To: webtier@glassfish.dev.java.net
> Date: Sunday, January 3, 2010, 4:56 AM
>
> UIData is designed to handle multiple entry data sets, including
> Lists. What's the data type in the List? You say this:
>
> ((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN,
> ageN)
>
> Are those JPA entities? If so, you should be able to use
> #{item.name}, etc.
>
> Unless I'm missing something...
>
> On 1/2/10 3:34 PM, Celinio Fernandes wrote:
>>
>> I posted that issue (enhancement) :
>> Issue 713 posted
>> Email sent to: issues@javaserverfaces-spec-public,
>> javaserverfowner, longbeach, lidia
>>
>> Not sure i posted it right, this is the first time i do it.
>>
>> --- On Sun, 1/3/10, Lincoln Baxter, III
>> wrote:
>>
>> From: Lincoln Baxter, III
>> Subject: Re: [webtier] How to handle a list in JSF 2
>> To: webtier@glassfish.dev.java.net
>> Date: Sunday, January 3, 2010, 2:34 AM
>>
>> By the way, i know i should check the documentation first, which i
>> will pretty soon, but do you know if the Ajax features that have
>> been integrated in JSF 2.0 bring anything new to the datatable
>> component ?
>>
>> They do not, but of course, can now be ajaxified ;)
>>
>> If you think this is something JSF should be doing for you,
>> consider filing an enhancement request here:
>>
>> https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues
>>
>> or you can post a thread here:
>>
>> http://wiki.jcp.org/boards/index.php?b=jsr-314-public (you need a
>> JCP.org account)
>>
>> these links are all available here:
>>
>> http://www.javaserverfaces.org/home
>>
>> --Lincoln
>>
>
>
> --
> Jason Lee
> Senior Java Developer
> GlassFish Administration Console
>
> Sun Microsystems, Inc.
> Phone x31197/+1 405-343-1964
> Email jasondlee@sun.com
> Blog http://blogs.sun.com/jasondlee
> Blog http://blogs.steeplesoft.com
>

[att1.html]

Celinio Fernandes

Hi,
I am using Eclipse Galileo and there is not tag completion when I edit the XHTML pages.
I include the libraries like this in the pages :

    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">

Yes it does not offer any completion. JSF libraries (jboss-faces.jar, jsf-impl.jar and jsf-api.jar) are of course in the build path of my project.

Any idea how to enable completion ?

thanks

[att1.html]

Jim Driscoll

AFAIK, Eclipse doesn't have JSF 2 support yet.

Both Netbeans and IntelliJ do.

Jim

On 1/3/10 7:16 AM, Celinio Fernandes wrote:
> Hi,
> I am using Eclipse Galileo and there is not tag completion when I edit
> the XHTML pages.
> I include the libraries like this in the pages :
>
> > 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">
>
> Yes it does not offer any completion. JSF libraries (jboss-faces.jar,
> jsf-impl.jar and jsf-api.jar) are of course in the build path of my project.
>
> Any idea how to enable completion ?
>
> thanks
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Celinio Fernandes

Hi,
I am just wondering if JSF 2.0 has any logo ?
Does anyone know ?

Thanks.

[att1.html]

Lincoln Baxter, III

Hi Celinio,

It's ironic that you should ask this -- JSF does not currently have a logo,
but we're announcing something in the next week or so! Keep a look out on
http://www.javaserverfaces.org, and a variety of blogs (http://ocpsoft.com,
http://in.relation.to, http://www.javaserverfaces.org/news) for more info!

I'm not yet sure if it will be announced here.

Thanks,
Lincoln

On Sat, Jan 2, 2010 at 5:40 AM, Celinio Fernandes
wrote:

> Hi,
> I am just wondering if JSF 2.0 has any logo ?
> Does anyone know ?
>
> Thanks.
>
>
[att1.html]