This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Adding a value to the current list in a dropdown JSF1.2 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 a value to the current list in a dropdown JSF1.2" Watch "Adding a value to the current list in a dropdown JSF1.2" New topic
Author

Adding a value to the current list in a dropdown JSF1.2

Akash Sharma
Greenhorn

Joined: Aug 20, 2012
Posts: 6


Hi, I am new to JSF1.2 and enjoying learning the framework. Today while studying I stumbled upon an Idea and will be very amused to know if that's possible.

Suppose I have a list of values in a drop-down which I am fetching from DB, is it possible to give a link next to the drop-down if the user wants to add a value to the current list and as soon as he adds the value the new value starts reflecting in the drop-down immediately.

If someone can guide me towards the approach to achieve this I will feel very elated and motivated.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

Actually, I highly recommend moving up to JSF 2.0. There are significant advantages and it isn't that hard.

I'm not sure if I truly understood what you are suggesting, but it is a common practice to cascade dropdown lists, as for example, country, state, city. There are some interesting ways to do this in JSF.


Customer surveys are for companies who didn't pay proper attention to begin with.
Akash Sharma
Greenhorn

Joined: Aug 20, 2012
Posts: 6
Thank you very much for your prompt reply. I'll try to make myself more clear this time.

Suppose I have a drop-down list for a field ,say, country and currently it has 2 values India and Australia. Suppose the user wants to add another country to the current list say England.
What I am thinking is can there be a link provided next to the drop-down list of countries, and when user clicks on the link he/she gets say a pop-up window to add any country to the current list of values.
When the user adds the new country it immediately starts to display in the list of countries.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

OK. I think I've got that.

Let's start off with the initial list:


If you attach an AJAX onchange event to this control, it will fire an event when the list selection is changed. If the value of the selection equals the "Add a Country" value, your AJAX handler can be part of a process that displays the dialog you want (details will vary, depending on framework and implementation). If the dialog adds a SelectItem to the initial list for the new country, then triggers a re-render event on that control, the updated list will be made available on the client.
 
 
subject: Adding a value to the current list in a dropdown JSF1.2
 
Similar Threads
Displaying 2D array using data tables
Dynamic drop down list from an array
Can I add JSF components through Ajax?
Reg : Drop-down box
Struts2 : How to display full text of the drop down item when selecting the item in the drop down