Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Can we assign JSF Ajax Render attribute dynamically?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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} )
 
Saloon Keeper
Posts: 24531
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Buddhika Ariyaratne
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
 
Ranch Hand
Posts: 218
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 218
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24531
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic