• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I dynamically choose which component to use at render-time?

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a bean that holds an array of Object parameters. When I render the view I want to choose between using a textbox or a select list for each one of those objects based on their attributes. At first glance this appeared to be simple using JSTL tags but after reading that JSTL tags evaluate only to build the component tree and not to render it, I don't think it will work (ref: http://www.ninthavenue.com.au/blog/c:foreach-vs-ui:repeat-in-facelets).

So how can I accomplish this using JSF?
 
Greenhorn
Posts: 13
Oracle Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Micah wrote:I have a bean that holds an array of Object parameters. When I render the view I want to choose between using a textbox or a select list for each one of those objects based on their attributes. At first glance this appeared to be simple using JSTL tags but after reading that JSTL tags evaluate only to build the component tree and not to render it, I don't think it will work (ref: http://www.ninthavenue.com.au/blog/c:foreach-vs-ui:repeat-in-facelets).

So how can I accomplish this using JSF?


as I understand you want to choose the component to be rendered based on some condition? Almost all jsf tags have such an attribute as rendered, where you can specify whether to render that component or not. So in your backing bean you have to write a property(means jsf property as getXXX() or isXXX()) and use it in rendered attribute.
In your situation it will look like this:

where is method in your backing bean which determines whether to render the specified component or not
 
Saloon Keeper
Posts: 27762
196
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
Like Maks said, any JSF tag that produces visible output on the page - which is pretty much all of the "h:" namespace tags - has a "rendered" attribute that you can employ.

As for JSTL... Hang around here very long and you'll hear the piteous cries of others who thought JSF and JSTL could get along. And my admonishments to them to not do that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic