File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSF
Bookmark "Adding UI controlls dynamically" Watch "Adding UI controlls dynamically" New topic

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

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

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

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.

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.


GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: Adding UI controlls dynamically
It's not a secret anymore!