2 Replies Latest reply on Nov 3, 2008 5:28 PM by nbelaevski

    How bind object with multiple fields?

    nunya

      How does one bind an object that has >1 field in a rich:picklist or other tag requiring a converter?

      I have an ExperimentSpec object, that has a List of LabEquipment objects. LabEquipment has multiple fields: int id, String name, String vendor, String imageLink.

      I'm trying to create an addExperimentSpec.xhtml page, where the user can add a new ExperimentSpec to the database. In this page the user would select from a rich:picklist of LabEquipment objects, displayed by name, like this:

      <rich:picklist>
      <c:forEach var="equip" items="#{labEquipment}">
      <f:selectItem itemValue="#{equip}" itemLabel="#{equip.name}"/>
      </c:forEach>
      </rich:picklist>

      This doesn't work, because I need a converter. Unfortunately, I can't see how to create a converter, because I have >1 field... I can convert the LabEquipment to a String name, but I can't convert the String name to a LabEquipment object - I lose the id, vendor, imageLink fields...

      Is it even possible to bind multi-field objects to a RichFaces tag, other than a DataTable? It would be nice to be able to do this, b/c all of the objects I'm attempting to bind fit easier in my complex many-many data model.

      Thanks,
      Nunya

        • 1. Re: How bind object with multiple fields?
          justinmbirch

          I had to do something similar with a Converter to get a listShuttle to work.

          i.e.

           /**
           * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
           */
           public Object getAsObject( FacesContext context, UIComponent component, String value ) throws ConverterException {
           String[] vals = value.split( ":" );
           return new LabEquipmentId( vals[0], vals[1] );
           }
          
           /**
           * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
           */
           public String getAsString( FacesContext context, UIComponent component, Object value ) throws ConverterException {
           LabEquipmentId id = (LabEquipmentId)value;
           return id.getId() + ":" + id.getVendor();
           }
          


          Hope that helps

          • 2. Re: How bind object with multiple fields?
            nbelaevski

            Hello,

            Maybe that will help also: http://www.jboss.org/community/docs/DOC-12018?