2 Replies Latest reply on Mar 31, 2008 11:22 AM by jl7791

    Errors when trying to edit JSF admin pages with custom compo

    jl7791

      I have successfully added an attribute to the user profile object, but I want to be able to pull a list from a database and display it back to the user so that they may select from it.

      <h:selectOneMenu id="company" value="#{manager.uiUser.attribute.company}" required="#{metadataservice.company.required}">
       <f:selectItems value="#{customerManager.customerNames}" />
       </h:selectOneMenu>
      


      Backing bean:

      package com.mycompany.ui;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.faces.model.SelectItem;
      
      import com.mycompany.data.Customer;
      import com.mycompany.service.CustomerManager;
      
      public class CustomerBean {
      
       private List<SelectItem> customerNames;
      
       public void setCustomerNames(List<SelectItem> customerNames) {
       this.customerNames = customerNames;
       }
      
       public List<SelectItem> getCustomerNames() {
       if (customerNames == null) {
       customerNames = initNames();
       }
      
       return customerNames;
       }
      
       private List<SelectItem> initNames() {
       List<SelectItem> custNamesSelectItem = new ArrayList<SelectItem>();
       try {
       List<Customer> customerListFromDb = CustomerManager.getAllCustomers();
       for (Customer c : customerListFromDb) {
       custNamesSelectItem.add(new SelectItem(c.getId(), c.getName()));
       }
       } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      
       return custNamesSelectItem;
       }
      }
      


      When I access the page, I get the following exception. What causes this, since I am returning a list of SelectItem objects?

      Caused by: java.lang.IllegalArgumentException: Collection referenced by UISelectItems with binding '#{customerManager.customerNames}' and Component-Path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /WEB-INF/jsf/admin/editProfile.xhtml][Class: javax.faces.component.html.HtmlForm,Id: _id26jbpns_2fadmin_2fMembers_2fIdentityAdminPortletWindowsnpbj][Class: javax.faces.component.html.HtmlPanelGrid,Id: _id43jbpns_2fadmin_2fMembers_2fIdentityAdminPortletWindowsnpbj][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: company][Class: javax.faces.component.UISelectItems,Id: _id85jbpns_2fadmin_2fMembers_2fIdentityAdminPortletWindowsnpbj]} does not contain Objects of type SelectItem
       at org.apache.myfaces.shared_impl.util.SelectItemsIterator.next(SelectItemsIterator.java:184)
       at org.apache.myfaces.shared_impl.renderkit.RendererUtils.internalGetSelectItemList(RendererUtils.java:451)
       at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getSelectItemList(RendererUtils.java:428)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.internalRenderSelect(HtmlRendererUtils.java:294)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.renderMenu(HtmlRendererUtils.java:267)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlMenuRendererBase.encodeEnd(HtmlMenuRendererBase.java:59)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
       at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:419)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:229)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:101)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:242)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:540)
       at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
       at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:498)
       ... 236 more