I am newbie in JSF 2.0, I worked in JSF 1.1 and 1.2 and I populate selectOneMenu in constructor of Managed bean's page. For when users to acces to page the List is populate. example below. I put the same in JSF 2.0 but is not work, the selectOneMenu appears empty.
<h:selectOneMenu id="cboStatus" value="#{PersonBean.idStatus}">
<f:selectItems value="#{PersonBean.status}"/>
</h:selectOneMenu>
In constructor's managed bean I put:
public class PersonBean {
private SelectItem[] status=new SelectItem[0];
public PersonBean () {
detallePersonas= new ArrayList();
status= new SelectItem[3];
status[0]=new SelectItem("S","Single");
status[1]=new SelectItem("M","Married");
status[2]=new SelectItem("D","Divorced");
}
}
Thanks for helps
Thanks for your help
- Editor Netbeans 6.8 (JSF 2.0 default configuration wizard)
- No Exception Error
- Never run the constructor PersonBean (I put a breakpoint and never stops)
- There are other ways to populate selects to load the page
This is the complete code:
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Person</title>
</h:head>
<h:body>
<h:form id="frmPerson">
<h:outputLabel id="lblStatus" value="Status:"/>
<h:selectOneMenu id="cboStatus" value="#{PersonBean.idStatus}">
<f:selectItems value="#{PersonBean.status}"/>
</h:selectOneMenu>
</h:form>
</h:body>
</html>
PersonBean.java
package com.prueba.backingbean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;
/**
*
* @author Administrador
*/
@ManagedBean(name = "Person")
@ViewScoped
public class PersonBean {
private String idStatus;
private SelectItem[] status = new SelectItem[0];
public PersonBean() {
status = new SelectItem[3];
status[0] = new SelectItem("S", "Single");
status[1] = new SelectItem("M", "Married");
status[2] = new SelectItem("D", "Divorced");
}
/**
* @return the idStatus
*/
public String getIdStatus() {
return idStatus;
}
/**
* @param idStatus the idStatus to set
*/
public void setIdStatus(String idStatus) {
this.idStatus = idStatus;
}
/**
* @return the status
*/
public SelectItem[] getStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(SelectItem[] status) {
this.status = status;
}
}
Help me please