aspose file tools
The moose likes JSF and the fly likes How to fill an selectOneMenu and selectManyMenu from my database and retrieve the option selected Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "How to fill an selectOneMenu and selectManyMenu from my database and retrieve the option selected" Watch "How to fill an selectOneMenu and selectManyMenu from my database and retrieve the option selected" New topic
Author

How to fill an selectOneMenu and selectManyMenu from my database and retrieve the option selected

Tom Ram
Greenhorn

Joined: May 28, 2011
Posts: 1
Hello
I am new to programming world
I want to fill an selectOneMenu and selectManyMenu from my database.
I have found a simple of code that fill selectonemenu , so I have cutomised it to my need . but I haven't really understand it, I dont know how to retrieve the choice done by the user. (For selectManyMenu I dont know how to do that)
Do I need a button to validate to retrieve data choosed , because I nees the option choosed as a parameter for another request.
the code is:
MY JSF:
<form>
<h:selectOneMenu value=" #{BeanSelectItem.maValeur}" >
<f:selectItems value="#{BeanSelectItem.mesElements}"/>
</h:selectOneMenu>
<hutputLabel value="#{BeanSelectItem.maValeur}" />

</form>


MY BEAN:


public class BeanSelectItem {
private List<SelectItem> mesElements;
private String maValeur;

public String getMaValeur() {
return maValeur;
}

public void setMaValeur(String maValeur) {
this.maValeur = maValeur;
}



public void setMesElements(List<SelectItem> mesElements) {
this.mesElements = mesElements;
}

public Iterable<String> remplireItem() throws ClassNotFoundException, SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbcracle:thin:@localhost:1521:xe"," "," ");
PreparedStatement statement = con.prepareStatement("SELECT pname from issuestatus");
ResultSet rs = statement.executeQuery();
String var;
ArrayList<String> list = new ArrayList<String>();
while(rs.next())
{
var= rs.getString("pname");
list.add(var);

}


return list;
}

public List<SelectItem> getMesElements() throws SQLException, ClassNotFoundException {

if (mesElements == null) {
mesElements = new ArrayList<SelectItem>();
for (String val : remplireItem()) {
mesElements.add(new SelectItem(val));
}
}
return mesElements;
}

}

Thank you
 
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: How to fill an selectOneMenu and selectManyMenu from my database and retrieve the option selected
 
Similar Threads
Bean Value is always Null
SelectItems + IllegalArgumentException + help
selectOneMenu from database
fill selectOneMenu from database
JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)