0 Replies Latest reply on May 7, 2010 11:13 AM by simonc2009

    problem sorting on extended datatable with new row added

    simonc2009

      Dear All,

       

      I have a web page, with extended datatable. A click button which add a row to extended-datatable. It works fine.

       

      But, if I click column sort first and then click add button. Strange behaviour found in extended-datatable.

      For example, I entering a value in column 1 of the new row, once lose focus,

      the "entered value" will change automatically and replace by the value of the previous row of that column 1.

       

      More strange, when the whole datable is rendered (say a save action and trigger table rendered).

      Values in each row of table key column is mismatched with the corresponding row of non-key columns.

       

      So, can anyone help. Thanks.

       

      Information

      ========

      UI : richfaces 3.3.0 ga, backend: jboss-seam 2.1.2 ga

       

      entity

      ====

      @Embeddable
      public class GlSectCodePK implements Serializable{

        private static final long serialVersionUID = 1L;

      @Column(name="comp_code")
      private String compCode;

      @Column(name="sect_ident")
      private String sectIdent;

      public GlSectCodePK() {
      }

      public GlSectCodePK(String compCode, String sectIdent) {
        super();
        this.setCompCode(compCode);
        this.setSectIdent(sectIdent);
      }

      public void setCompCode(String compCode) {
        this.compCode = compCode;
      }

      public String getCompCode() {
        return compCode;
      }

      public void setSectIdent(String sectIdent) {
        this.sectIdent = sectIdent;
      }

      public String getSectIdent() {
        return sectIdent;
      }

      @Override
      public boolean equals(Object o) {
        if (o == this) {
         return true;
        }
        if ( ! (o instanceof GlSectCodePK)) {
         return false;
        }
        GlSectCodePK other = (GlSectCodePK) o;
        return (this.compCode == other.compCode)
         && (this.sectIdent.equals(other.sectIdent));
      }

       

      @Override
      public int hashCode() {
        final int prime = 31;
        int hash = 17;
       
        if (sectIdent==null)
         sectIdent="";
       
        hash = hash * prime + this.compCode.hashCode();
        hash = hash * prime + this.sectIdent.hashCode();
       
        return hash;
          }

      }

       

      =========

      xhtml

       

      <rich:extendedDataTable
          value="#{glSectCodes}"
          var="hot"
          id="glSectCodesTable" 
          height="250px"
          sortMode="single"
          selectionMode="multi"   
          enableContextMenu="false"
                      rowClasses="odd-row, even-row"      
                      onRowMouseOver="this.style.backgroundColor='#E6E8FA'"
                      onRowMouseOut="this.style.backgroundColor='#{rowKeyVar}'"
                      rowKeyVar="rcounter"    
         >

       

      <rich:column id="column1" style="#{hot.recStyle};text-align:center"  width="120px"  sortBy="#{hot.sectIdentTran}"   filterBy="#{hot.sectIdentTran}" filterEvent="onkeyup">
          <f:facet id="NameFacet" name="header"><h:outputText value="#{bundle.tblMaintSectCodeColheadingSectionCode}"/></f:facet>
           <h:panelGroup>  
            <h:inputText  id="sectIdent" value="#{hot.sectIdentTran}" size="1" maxlength="1"
              style="text-align:center"
                  >
             <f:converter converterId="itemBeanToUpperCaseConverter"/>          
                <a:support event="onchange"
                  reRender="sectIdent, column1"                 
               actionListener="#{hot.statusListener}"/>                                    
            </h:inputText>
           </h:panelGroup>
         </rich:column>

      ..

      </rich:extendedDataTable>

       

      ===========

      EJB

      ===

       

      public class GlSectCodeList implements GlSectCodeListLocal, Serializable {

      /*  db */
      @PersistenceContext(unitName = "FisProjectDatabase")
      private EntityManager em;

      /*  related header */
      /*  related details table */
      @DataModel
      private List<GlSectCode> glSectCodes = new ArrayList<GlSectCode>();
       
      private List<GlSectCode> deletedGlSectCodes = new ArrayList<GlSectCode>();
      private List<GlSectCodePK> deletedGlSectCodesBackUp = new ArrayList<GlSectCodePK>();

      @DataModelSelection
      private GlSectCode glSectCode;

       

      @SuppressWarnings("unchecked")
      public void getSectionCodeList() { 
        glSectCodes = em
        .createQuery(
          "select g from GlSectCode g where g.pk.compCode = :compCode")
        .setParameter("compCode", fISSessionParm.getCompCode())
        .getResultList();
        initValues();
      }

       

       

      public void addRows() {

      GlSectCode t = new GlSectCode();
         GlSectCodePK tpk = new GlSectCodePK();
         tpk.setCompCode(fISSessionParm.getCompCode());
         tpk.setSectIdent("-");
         t.setPk(tpk);
         t.setNewRecord(true);
         t.setDirty(true);
         glSectCodes.add(t);

      }