I am using JSF 1.2 and when I try to access my page I get this error: was not an instance of javax.faces.model.SelectItem. Type found: java.util.ArrayList.

I am creating this simple web page that has a drop down list, the data is coming from the database and should display but I get this error:


Here is the code from the jsf

                        <h:selectOneMenu value="#{clients.code1}">
                              <f:selectItem value="#{clients.selectItems}"></f:selectItem>
                  </h:selectOneMenu>

Here is the code from the backing bean:

            try{
                  System.out.println("Test in list");
                  if( selectItems == null ) {
                        selectItems = new ArrayList<SelectItem>();
                        SearchUtilDao sutil = new SearchUtilDao();
                        System.out.println("Test in list");
                        ResultSet rs = sutil.doSearchAll("Codes", con);
                        while(rs.next()){
                              Codes cd = new Codes();
                              cd.setCode(rs.getString("CODE"));
                              cd.setId(rs.getInt("CODEID"));
                              selectItems.add(new SelectItem(cd.getId(), cd.getCode()));
                              System.out.println("returned data: " + cd.getCode());
                        }
                  }

                  return selectItems;


I am using JSF 1.2 on tomcat 6.  Thank you

LC
lasanacAsked:
Who is Participating?
 
Farzad AkbarnejadConnect With a Mentor DeveloperCommented:
Hello,
Try the following code:


    public SelectItem[] getSelectItems() {
        List selectItemsList = new ArrayList<Codes>();
        ResultSet rs = sutil.doSearchAll("Codes", con);
        SearchUtilDao sutil = new SearchUtilDao();            
        while(rs.next()){
            Codes cd = new Codes();
            cd.setCode(rs.getString("CODE"));
            cd.setId(rs.getInt("CODEID"));
            selectItemsList.add(cd);
        }        
        SelectItem[] selctItems = new SelectItem[selectItemsList.size()];
        int i = 0;
        for (Object o : selectItemsList) {
            Codes c = (Codes) o;
            selctItems[i++] = new SelectItem(c.getId(), c.getCode());
        }
        return selctItems;
    } 
    

Open in new window

0
 
chaitu chaituCommented:
what is the exception are you getting?
0
 
lasanacAuthor Commented:
Here is the stack trace:

java.lang.IllegalArgumentException: Argument Error: An option for component j_id7 was not an instance of javax.faces.model.SelectItem.  Type found: java.util.ArrayList.
      at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:296)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.getOptionNumber(MenuRenderer.java:647)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:763)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:278)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:849)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:946)
      at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:578)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
      at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:696)
      at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:667)
      at org.apache.jsp.index_jsp._jspService(index_jsp.java:59)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
0
 
lasanacAuthor Commented:
FarzadA,

I tried your suggestion and I got basically the same error.  Do I have to right an conversion?

Stack Trace:

java.lang.IllegalArgumentException: Argument Error: An option for component j_id7 was not an instance of javax.faces.model.SelectItem.  Type found: [Ljavax.faces.model.SelectItem;.
      at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:296)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.getOptionNumber(MenuRenderer.java:647)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:763)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:278)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:849)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:946)
      at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:578)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
      at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:696)
      at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:667)
      at org.apache.jsp.index_jsp._jspService(index_jsp.java:59)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
0
 
Farzad AkbarnejadDeveloperCommented:
Hi,
Do you have problem yet? Are you sure to accept the solution?

-FA
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.