开发者

jsf selectonemenu error

H开发者_开发百科i: I am developing a jsf project, I am having touble with getting selectOneMenu to work.

<h:selectOneMenu value="#{employeeEditBean.employeeBean}">
      <f:selectItems value="#{employeeEditBean.branchList}" />
     </h:selectOneMenu>
public class EmployeeEditHandler
{
 private String paramEmPK;
 private Employee employeeBean;
 private List<Branch> branchList;

 private int branchFK;


 public EmployeeEditHandler()
 {
  paramEmPK = FacesContext.getCurrentInstance().getExternalContext()
    .getRequestParameterMap().get("emPK");
  int emPK = Integer.parseInt(paramEmPK);
  branchList = new ArrayList<Branch>();
  employeeBean = new Employee();
  FacesContext context = FacesContext.getCurrentInstance();
  try 
  {
   employeeBean = DaoFactory.getEmployeeDao().lookupEmployeeByPK(emPK);
   branchFK = employeeBean.getBranchFK();
   branchList = DaoFactory.getBranchDao().findAllBranch();

  } 
  catch (Exception e) {
   FacesMessage msg = new FacesMessage(e.getMessage());
   msg.setSeverity(FacesMessage.SEVERITY_ERROR);
   context.addMessage("employeeEditForm", msg);
  }
 }

The error is:javax.servlet.ServletException: Argument Error: An option for component j_id8 was not an instance of javax.faces.model.SelectItem. Type found: java.util.ArrayList. javax.faces.webapp.FacesServlet.service(FacesServlet.java:277) org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206) org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)


Actually, i found another way to do this. I add a tomahawk12 library.

<h:selectOneMenu value="#{employeeEditBean.branchFK}">
    <t:selectItems value="#{employeeEditBean.branchList }" var="br" itemLabel="#{br.branchName}" itemValue="#{br.branchPK }" />
</h:selectOneMenu>

I did not change code in employeeEditBean.

Thanks all


You need your employeeEditBean.branchList to be of type List<SelectItem>, where each SelectItem has a value (the string that will be transferred as a post parameter) and a label.

So you'd need to create that list based on your original branch list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜