This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rob Micah
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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?
 
Maks Besida
Greenhorn
Posts: 13
Chrome Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18163
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic