aspose file tools*
The moose likes JSF and the fly likes How can I dynamically choose which component to use at render-time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How can I dynamically choose which component to use at render-time?" Watch "How can I dynamically choose which component to use at render-time?" New topic
Author

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

Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
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

Joined: May 26, 2011
Posts: 13

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

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I dynamically choose which component to use at render-time?