aspose file tools
The moose likes JSF and the fly likes JSF - dynamic tag choice Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "JSF - dynamic tag choice" Watch "JSF - dynamic tag choice" New topic
Author

JSF - dynamic tag choice

Kevin McMahon
Greenhorn

Joined: Nov 03, 2008
Posts: 19
Hi all.
I'm fairly new to JSF, and wondered if anyone might be able to give me a pointer in the right direction for this scenario...

I have a dynamic list of properties which I need to display on a page. However, the properties have a dynamic type - so for some properties I will need a checkbox to allow the user to select on/off, others will be a text input field etc. There will be a mix of types per page, but I don't know in advance how many or what type they will be, as this comes from a database.

If I were doing this in jstl, I could use something like
<c:if test="${myProperty.type == 'checkbox'}>
<input type="checkbox" ...>
</if>

or even
<input type="<cut value="${myProperty.type"} />" ....>

Can anyone get me started on the right path to achieve a similar thing in JSF?

sheep.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 434
Could you take advantage of the input element's rendered attribute? For example, for each property output both a checkbox and a text field, but depending on your logic, the rendered attribute would evaluate to true for one and false for the other.

- Dave
Kevin McMahon
Greenhorn

Joined: Nov 03, 2008
Posts: 19
Yes, that's not a bad idea.

Alternatively, could I use the backing bean to create the correct UIInput types dynamically, according to the data?

For example, my backing bean can have



I think I can then create the correct UIInput for each attribute in the collection, and add them as children to the UIPanel dynamically? Can I use the valueBinding methods on the UIInput to bind to my Attribute list objects?

Then, in the jsp have



I can't test this until later, but the only thing I'm not sure about it whether the data will bind back to the list element Attribute object ok?


[ November 06, 2008: Message edited by: Kevin McMahon ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: JSF - dynamic tag choice
 
Similar Threads
Struts2: I want to use <s:textfield> inside <s:checkbox>, is it possible?
JSTL and Checkbox
delete multiple records using checkboxes
Why is onclick value getting lost?
actionlistener for selectBooleanCheckbox doubt?