3 Replies Latest reply on Mar 11, 2011 2:06 PM by godoy

    Problems with conversion rich: orderingList

    godoy

      Problems with conversion rich: orderingList
      see my code:

      page:

      <rich:orderingList value="#{mbParametroUT.listParametros}" var="lib" listHeight="300" listWidth="350"

              id="orderList" converter="orderingListConverter" >

              <rich:column width="120">

                  <f:facet name="header">

                      <h:outputText value="Parâmetros" />

                  </f:facet>

                  <h:outputText value="#{lib.tipoParametroAgua}" />

              </rich:column>

              <rich:column width="120">

                  <f:facet name="header">

                      <h:outputText value="Descrição" />

                  </f:facet>

                  <h:outputText value="#{lib.descricao}" />

              </rich:column>

              <rich:column width="75">

                  <f:facet name="header">

                      <h:outputText value="Limite Sup." />

                  </f:facet>

                  <h:outputText value="#{lib.limiteSuperior}" />

              </rich:column>

              <rich:column width="75">

                  <f:facet name="header">

                      <h:outputText value="Limite Inf." />

                  </f:facet>

                  <h:outputText value="#{lib.limiteInferior}" />

              </rich:column>

              <rich:column width="75" >

                  <f:facet name="header">

                      <h:outputText value="ID" />

                  </f:facet>

                  <h:outputText value="#{lib.id}" />

              </rich:column>

          </rich:orderingList>



      listParametros

      public List<ParametroAgua> getListParametros() {

          if (model != null) {

              if ((listParametros == null) && model.isRowAvailable()) {

              this.parametro = (ParametroUT) model.getRowData();

              }

          }

       

          if (parametro != null) {

              try {

              listParametros = parametroUtdao.listParametrosAgua(parametro

                  .getId());

              } catch (DaoException e) {

              e.printStackTrace();

              }

              return listParametros;

          }

          return new ArrayList<ParametroAgua>();

          }



      Converter:

      @Override

          public Object getAsObject(FacesContext fc, UIComponent ui, String value) {

          try {

              this.parametroUtdao = (ParametroUtDaoEjbLocal) ServiceLocator

                  .getInstance().lookup("sci_EjbEAR",

                      ParametroUtDaoEjbLocal.class);

              String[] values = value.split(":");

              Long id = new Long(values[values.length - 1]);

              ParametroAgua p = new ParametroAgua();

              p.setTipoParametroAgua(Enum.valueOf(TipoParametroAgua.class,

                  values[0].toUpperCase()));

              p.setDescricao(values[1]);

              p.setLimiteSuperior(new Double(values[2]));

              p.setLimiteInferior(new Double(values[3]));

              p.setId(id);

              return p;

          } catch (Exception e) {

              e.printStackTrace();

          }

          return null;

          }

       

          @Override

          public String getAsString(FacesContext fc, UIComponent ui, Object object) {

          ParametroAgua p = (ParametroAgua) object;

          StringBuilder sb = new StringBuilder();

          sb.append(p.getTipoParametroAgua().getDescricao()).append(":");

          sb.append(p.getDescricao()).append(":");

          sb.append(p.getLimiteSuperior()).append(":");

          sb.append(p.getLimiteInferior()).append(":");

          sb.append(p.getId());

          return sb.toString();

          }

       

       



      I am with the following error:
      "Component paramCadModalForm: orderlist has invalid value expression Fluor Normal: 10.0:1.0:1"

      Has anyone used this component and can help me?
      Thanks

        • 1. Problems with conversion rich: orderingList
          ilya_shaikovsky

          Besides the converter - hashCode and equals methods for the object should be properly implemented also.

          • 2. Problems with conversion rich: orderingList
            godoy

            This is my equals and hashCode:

            @Override

                public int hashCode() {

                final int prime = 31;

                int result = getId().hashCode();

                result = prime * result

                    + ((getId() == null) ? 0 : getId().hashCode());

                return result;

                }

             

                @Override

                public boolean equals(Object obj) {

                if (this == obj)

                    return true;   

                if (getClass() != obj.getClass())

                    return false;

                ParametroAgua other = (ParametroAgua) obj;

                if (getId() == null) {

                    if (other.getId() != null)

                    return false;

                } else if (!getId().equals(other.getId()))

                    return false;

                return true;

                }

             

            The something else I should do?, I'm a little confused as to the values expected by the component.

            All help and welcome at this time.
            Thanks

            • 3. Problems with conversion rich: orderingList
              godoy

              One of a super class of my object was not a proper implementation
              of equals and hashCode, so you were right ilya.
              Thank you.