wood burning stoves 2.0*
The moose likes JSF and the fly likes Adding UI controlls dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Adding UI controlls dynamically" Watch "Adding UI controlls dynamically" New topic
Author

Adding UI controlls dynamically

ved gunjan
Ranch Hand

Joined: May 17, 2003
Posts: 86
Hi Experts
Im new to JSF world and have come across the following scenarion.


I have following UI controlls on the jsp page: textfield, drop down.


The drop down has following values :Mercedes,BMW,GM,Ford.


So when the user selects any value, the selected value goes to the server and based on the response from the server, I have to show different UI controlls on the page for example lets say when the user selects Ford i have to show 2 textfields, 2 drop down, and 3 Check boxes and when the user selects Mercedes i have to show 4 textfields, 3 drop downs and 2 list.



Im struggling about the ways through which i can implement this.



Hope im able to explain my situations.



Any help/suggestions will be great.



Thanks and Regards

Ved
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Depending on how different the forms are from one choice to another, there are a couple of ways you could do this.

1:
If the choices are very similar. For example, textfields 1 and 2 are the same for Ford and BMW but BMW just has an additional textfield, and so on with the other components, simple use the rendered attribute of the components with a or more boolean properties in your backing bean to turn them on or off depending on the selection.

2:
If the textfields and other components are for the majority completely different for each choice, use panelGroup components (or somethind similar) to group all the components for each choice to a specific panel (DIV). Then use the rendered attribute on the panel to decide which to show.

If you are using MyFaces, they have a really nifty panelStack component that makes option #2 pretty simple.

HTH


GenRocket - Experts at Building Test Data
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding UI controlls dynamically
 
Similar Threads
Cascading dropdowns using Ajax
Dropdown values for JSP
how to show same row for each click on a link
group of checkboxes with multi select dropdown
saving preselected drop down value