1 Reply Latest reply on Oct 3, 2011 11:47 PM by Chris Martin

    Convert Entity in SelectOneMenu help needed

    Chris Martin Newbie

      I created an application using seam-gen as a starting point for further enhancement. One of the changes I am implementing is to add a select one menu for certain fields, for example, a list of Contractors. Since seam-gen created extensions of the EntityList for these objects I used the contractorList.resultList as the value for my select items. This all works well, however when I submit my form by clicking on a h:commandButton I get the error:
      20:17:53,151 SEVERE [component] /MainSearchDetails.xhtml @96,84 value="#{productionHeaderHome.instance.constrContractorId}": java.lang.IllegalArgumentException: argument type mismatch []
      java.lang.IllegalArgumentException: argument type mismatch
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
              at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:69)
              at com.sun.faces.el.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:100)
              at org.jboss.el.parser.AstPropertySuffix.setValue(AstPropertySuffix.java:73)
              at org.jboss.el.parser.AstValue.setValue(AstValue.java:84)
              at org.jboss.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
              at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:93)
              at javax.faces.component.UIInput.updateModel(UIInput.java:771)



      I believe this is because the Entity  that is backing contractorList does not contain types of the entity that is being converted in the list  simply has an Id for contractor which is an Integer. so

      I select a value here
      ...

      <s:decorate id="constrContractorIdField" template="layout/edit.xhtml">
            <ui:define name="label">Contractor Id</ui:define>
            <h:selectOneMenu id="selectOneMenuContractorList"
                             value="#{productionHeaderHome.instance.constrContractorId}">
              <s:selectItems id="selectContractor" var="contractor"
                             value="#{contractorList.resultList}" label="#{contractor.companyName}"

                             noSelectionLabel="Please select..."
                             hideNoSelectionLabel="false"/>
              <s:convertEntity />

            </h:selectOneMenu>
          </s:decorate>
      ...

      Then I click the save , and the error above is throw, I don't believe the persist on the entity home is ever called.
      ...

      <h:commandButton id="save"
                           value="Save"
                           action="#{productionHeaderHome.persist}"
                           disabled="#{!productionHeaderHome.wired}"
                           rendered="#{!productionHeaderHome.managed}"/>

      ...






      ...
      @Entity
      @Table(name = "tbProductionHeader",  uniqueConstraints = @UniqueConstraint(columnNames = {
                      "TrackingNbr", "TrackRevision", "ConstrContractorID"}))
      public class ProductionHeader implements java.io.Serializable {

              private Integer productionHeaderId;
              private Integer hubId;
              private Integer constrContractorId;
              private Integer budgetCatDetailId;


      ...


      ...

      @Entity
      @Table(name = "trConstrContractors",)
      public class Contractor implements java.io.Serializable {

              private int constrContractorId;
              private String contractorCode;
              private Integer contractorNbr;
              private String companyName;

      ...

      I believe the convert entity is taking the entity Id for the contractor that is part of the s:selectItems and initializing the contractor object and then trying to set the select on menu value( value="#{productionHeaderHome.instance.constrContractorId}") with the Contractor object instead of the contractor id.



      I am fairly new to seam so I am wondering advice on this. Should I abandon this approach and use a more standard JSF  SelectItem object rather than relying on the s:convertEntity. Then I would have to use a factor method to build the select one menus. It seems a shame since seam-gen has already created these list objects.

      Do I need a custom converter ?

      Any advice is appreciated