jQuery in Action, 2nd edition
The moose likes JSF and the fly likes Is it possible to refresh the dropdown h:selectOneMenu    Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Is it possible to refresh the dropdown h:selectOneMenu    " Watch "Is it possible to refresh the dropdown h:selectOneMenu    " New topic
Author

Is it possible to refresh the dropdown h:selectOneMenu

Bansilal Haudakari
Greenhorn

Joined: Jun 28, 2004
Posts: 15
Here is my requirement

The user creates new record by selecting "New" value from the dropdown. Then user enters values on form fields and clicks the Submit button. The result is new Record gets created in the database and also gets populated in the dropdown. But the dropdown still shows the "New" value whereas I want the drop down to dynamically change from "New" to newly created value in the drop down

The dropdown is populated from the database as shown below

<hutputText value="Manufacturer" /> <h:selectOneMenu id="manufList" value="#{manufacturerBean.selectedManufacturer}" > <f:selectItem itemLabel="New" itemValue="New" /> <f:selectItems value="#{manufacturerBean.manufacturerList}" /> <a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="t3,t4,t5,t6,t7,t8,t9,t10" /> </h:selectOneMenu>




Here is the backing bean

public List getManufacturerList(){ logger.info(" *** In getManufacturerList Backing Bean*** "); List<Manufacturer> models = new ArrayList<Manufacturer>(); List<SelectItem> manufacturers = new ArrayList<SelectItem>(); models = manufManager.getManufacturerList(); logger.info(" *** manufManager List Size=*** "+models.size()); for (Iterator it = models.iterator(); it.hasNext();) { Object[] row = (Object[]) it.next(); manufacturers.add(new SelectItem(row[0]+"",row[1]+"")); } return manufacturers; }





Any pointers/suggestions will be highly appreciated
Regards
Bansi
Andres Quinones
Ranch Hand

Joined: Oct 09, 2006
Posts: 57
Originally posted by Bansilal Haudakari:
Here is my requirement

The user creates new record by selecting "New" value from the dropdown. Then user enters values on form fields and clicks the Submit button. The result is new Record gets created in the database and also gets populated in the dropdown. But the dropdown still shows the "New" value whereas I want the drop down to dynamically change from "New" to newly created value in the drop down

The dropdown is populated from the database as shown below

<hutputText value="Manufacturer" /> <h:selectOneMenu id="manufList" value="#{manufacturerBean.selectedManufacturer}" > <f:selectItem itemLabel="New" itemValue="New" /> <f:selectItems value="#{manufacturerBean.manufacturerList}" /> <a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="t3,t4,t5,t6,t7,t8,t9,t10" /> </h:selectOneMenu>




Here is the backing bean

public List getManufacturerList(){ logger.info(" *** In getManufacturerList Backing Bean*** "); List<Manufacturer> models = new ArrayList<Manufacturer>(); List<SelectItem> manufacturers = new ArrayList<SelectItem>(); models = manufManager.getManufacturerList(); logger.info(" *** manufManager List Size=*** "+models.size()); for (Iterator it = models.iterator(); it.hasNext();) { Object[] row = (Object[]) it.next(); manufacturers.add(new SelectItem(row[0]+"",row[1]+"")); } return manufacturers; }





Any pointers/suggestions will be highly appreciated
Regards
Bansi


Bansi I think that you can do it filling again the list after the creation of the new record. Maybe if you post the code of your Bean it would be easier to help you.
AnandRenga
Greenhorn

Joined: Feb 14, 2007
Posts: 1
The f:selectItem value="New" will always select that item in the dropdown whatever value you entered. The "New" item need to be added as the first element in the backing bean when the manufacturerList is populated. And the variable selectedManufacturer has to be set the value of whatever needs to be displayed as default in the JSF dropdown. As Andres said it will be better if you could send the backing bean code.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Is it possible to refresh the dropdown h:selectOneMenu
 
Similar Threads
JSF drop down Converter issues
Problem with dynamic drop down
JSF drop down problems again
JSF drop down Converter issues
selectManyListBox to add/remove user Roles