aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 15290
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding UI controlls dynamically
 
Similar Threads
Cascading dropdowns using Ajax
group of checkboxes with multi select dropdown
saving preselected drop down value
how to show same row for each click on a link
Dropdown values for JSP