Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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.

Posted on 2008-10-25
5
2,594 Views
Last Modified: 2013-12-02
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
0
Comment
Question by:lasanac
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22802921
what is the exception are you getting?
0
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 500 total points
ID: 22806412
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
 

Author Comment

by:lasanac
ID: 22840280
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
 

Author Comment

by:lasanac
ID: 22840438
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
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 22842071
Hi,
Do you have problem yet? Are you sure to accept the solution?

-FA
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question