It's not a secret anymore!*
The moose likes JSF and the fly likes Can we assign JSF Ajax Render attribute dynamically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Can we assign JSF Ajax Render attribute dynamically?" Watch "Can we assign JSF Ajax Render attribute dynamically?" New topic
Author

Can we assign JSF Ajax Render attribute dynamically?

Buddhika Ariyaratne
Greenhorn

Joined: Dec 18, 2011
Posts: 6
I am using JSF ajax as shown below.



Is it possible to give the list of web components for render attribute through el from a managed bean? (Like render=#{bean.controlList} )
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Well, we don't like to say "RTFM" here, because it tends to sound unfriendly, but if you look here: http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/ajax.html you might notice that the "type" for the "render" attribute is a javax.el.ValueExpression .

So, in short, yes.


Customer surveys are for companies who didn't pay proper attention to begin with.
Buddhika Ariyaratne
Greenhorn

Joined: Dec 18, 2011
Posts: 6
Thank you.
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
What you should find (I've not tested this recently with the most recent Mojarra versions) is that it doesn't
quite work as you'd expect with f:ajax. The problem has always been that on the current request cycle
the EL expression is resolved, but only on the next request is the render target updated, and this is probably
not quite what you wanted.

The workaround involves not using render= on the f:ajax tag, but instead adding the component to be
rendered from a listener. In this case instead of using f:ajax render="yourtarget", or more specifically
f:ajax render="#{bean.propertyContainingTheStringYourTarget}", you'd do it like this:



If you're using the richfaces a4j:ajax, the developers had the good common sense to handle this situation
and you don't require the workaround.

Regards,
Brendan.
Buddhika Ariyaratne
Greenhorn

Joined: Dec 18, 2011
Posts: 6
Brendan Healey wrote:What you should find (I've not tested this recently with the most recent Mojarra versions) is that it doesn't
quite work as you'd expect with f:ajax. The problem has always been that on the current request cycle
the EL expression is resolved, but only on the next request is the render target updated, and this is probably
not quite what you wanted.

The workaround involves not using render= on the f:ajax tag, but instead adding the component to be
rendered from a listener. In this case instead of using f:ajax render="yourtarget", or more specifically
f:ajax render="#{bean.propertyContainingTheStringYourTarget}", you'd do it like this:



If you're using the richfaces a4j:ajax, the developers had the good common sense to handle this situation
and you don't require the workaround.

Regards,
Brendan.


That solved my issue when using JSF without any library. I am using PrimeFaces when necessary and will check on that.
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
Here is a suggestion from Cagatay to use RequestContext.getCurrentInstance().addPartialUpdateTarget("clientIdHere"):

http://forum.primefaces.org/viewtopic.php?f=3&t=12992&p=39246&hilit=partialviewcontext#p39246
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Brendan Healey wrote:Here is a suggestion from Cagatay to use RequestContext.getCurrentInstance().addPartialUpdateTarget("clientIdHere"):

http://forum.primefaces.org/viewtopic.php?f=3&t=12992&p=39246&hilit=partialviewcontext#p39246


Any solution that requires invoking esoteric JSF code rings alarm bells for me. It usually indicates that the wrong solution is being applied. I'd check around carefully be4fore assuming that there's no more straightforward solution than something like that. As Brendan noted, it's trivial to do what you want using RichFaces a4j, and a4j not only existed long before JSF2, but the RichFaces people were (so I understand) heavy contributors to the development of the JSF2 standard. I cannot believe that they'd inflict such punishment on non-RichFaces developers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we assign JSF Ajax Render attribute dynamically?
 
Similar Threads
Ajax support in Jsf 2.0
Re-Execute Javascript on Ajax Render
Executing two f:ajax in h:commandButton
Who has the focus?
dynamic changing of h:inputText value based on change value in other h:inputText