3 Replies Latest reply on Sep 11, 2007 5:12 AM by ilya_shaikovsky

    Need help - new user

      Hi

      I tried converting my standard datatable into a rich:datatable.
      I'm using Seam 1.2.1GA with myfaces

      I have a simple CRUD page with all records in a datatable, one of the cols in is a name(hyperlink) and the other a disabled checkbox pointing to this

      @Column (name="active", nullable=false, length=1)
      @Type(type="yes_no")
      private boolean active;

      in my hibernate entity. When the name link is clicked, a detail form allows edit and when a save button is pressed, the name & checkbox in the list should reflect changed values. The name reflects changes but not the checkbox. The other problem (if I use the rich:datatable) is that multiple updates to the same row causes javax.persistence.OptimisticLockException - Note if I do not have the rich:datatable in my page, I don't see this problem.

      This is the code for standard and rich datatables

       <h:dataTable id="catalogs" var="_catalog" value="#{catalogs}"
       styleClass="listing" columnClasses=",,fixed,,actions" footerClass="hide" rendered="#{not empty(catalogs)}" >
       <f:facet name="footer">
       <!-- -->
       </f:facet>
      
       <h:column>
       <f:facet name="header">Catalog Name</f:facet>
       <h:commandLink value="#{_catalog.name}" action="#{catalogList.select()}"/>
      
       </h:column>
       <h:column>
       <f:facet name="header">Active</f:facet>
       <h:selectBooleanCheckbox id="activeflag" value="#{_catalog.active}" disabled="true" />
       </h:column>
      
       </h:dataTable>
      
      <-- rich datatable with same cols as standard dattable above -->
       <rich:dataTable id="dtCatalogList"
       onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
       onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
       cellpadding="0" cellspacing="0" width="500" border="0"
       var="_catalog" value="#{catalogs}" rendered="#{catalogs.rowCount>0}">
      
       <f:facet name="header">
       <rich:columnGroup>
       <rich:column>
       <h:outputText value="Catalog Name" />
       </rich:column>
       <rich:column>
       <h:outputText value="Active" />
       </rich:column>
      
       </rich:columnGroup>
       </f:facet>
      
       <rich:column> <h:commandLink value="#{_catalog.name}" action="#{catalogList.select()}"/></rich:column>
       <rich:column align="center" > <h:selectBooleanCheckbox value="#{_catalog.active}" disabled="true" /></rich:column>
      
      
       </rich:dataTable>
      



      This is my table definition (Oracle) if that matters
      CREATE TABLE CATALOG
      (
       CATALOG_ID NUMBER(19) NOT NULL,
       CATALOG_NAME VARCHAR2(200 CHAR) NOT NULL,
       ACTIVE CHAR(1 BYTE) DEFAULT 'N',
       OBJ_VERSION INTEGER
      )
      


      This is my Seam components in SFSB which work fine with standard datatable.
       @PersistenceContext
       private EntityManager em;
      
       @DataModel
       private List<Catalog> catalogs;
      
      
       @DataModelSelection
       @Out(required=false)
       @In (required=false)
       private Catalog catalog ;
      





        • 1. Re: Need help - new user

          I'm sorry my misstated something - the disabled checkbox in the rich:datatable does not reflect a change immediately after an update. When i click that name link or any other name link row, the value displays correctly.

          • 2. Re: Need help - new user

            Perhaps i don't understand how to use it correctly.

            This is my detail form

            <rich:panel id="pnlCatalogDetail" rendered="#{showDetail eq true}">
            
             <table> <!-- class="detail" -->
             <colgroup>
             <col width="20%" />
             <col width="80%" />
             </colgroup>
             <tr>
             <th><h:outputLabel for="catalogName" value="Catalog Name" /></th>
             <td>
             <h:inputText id="catalogName" value="#{catalog.name}" size="40" maxlength="200" > </h:inputText>
             </td>
             </tr>
             <tr>
             <th><h:outputLabel for="catalogActive" value="Activate ?" /></th>
             <td>
             <h:selectBooleanCheckbox id="catalogActive" value="#{catalog.active}" />
             </td>
             </tr>
            
            
             </table>
             <h:commandButton value="Save" action="#{catalogList.save()}" /> #{spacer}
             <h:commandButton value="Cancel" action="#{catalogList.cancel()}" />
             </rich:panel>
            


            Do I need to use a4j:commandButton for save
            and reRender the datatable ?




            • 3. Re: Need help - new user
              ilya_shaikovsky

              You should use ajax action components - in the same way as standard ones.

              The only differences is - you need to reRender affected areas, and you can optimize the request by ajax related attributes.