| 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>
<h utputLabel 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("jdbc racle: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
|
 |
 |
|
|
subject: How to fill an selectOneMenu and selectManyMenu from my database and retrieve the option selected
|
|
|