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

JSF - dynamic tag choice

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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="<c:out value="${myProperty.type"} />" ....>

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

sheep.
 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 child proofed my house but they still get in. Distract them with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic