5 Replies Latest reply on Aug 27, 2007 4:50 AM by mrohad

    reRender dataTable

    mrohad

      I've a dataTable and a modalPanel
      in the modalPanel I add and edit rows from the dataTable

      when clicking "save" in the modalPanel I call in ajax to the bean.save() method which persist or merge the row.
      after the modalPanle is getting hide(using richfaces javascript function) I reRender the dataTable
      the datatable get reRendered only after merge , after persist the new row doesn't apper...
      any idea why?

        • 1. Re: reRender dataTable

          I had implementation like your (with adding, removing and merging functionality) and it works correctly.
          I think a problem in your code.
          Provide your code as example for more details.

          • 2. Re: reRender dataTable
            mrohad

            thanks for the quick reply , here is my code:
            xhtml

            <?xml version="1.0" encoding="Windows-1255" ?>
            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
            
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:s="http://jboss.com/products/seam/taglib"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
             template="/layout/template.xhtml">
            
             <ui:define name="body">
            
             <h:messages globalOnly="true" styleClass="message" id="globalMessages" />
             <!-- FILTER -->
             <a4j:form styleClass="edit" dir="rtl" id="mainForm">
             <rich:panel id="customerTable">
             <f:facet name="header">customer</f:facet>
             <div class="results" id="customerList"><a4j:region>
             <rich:dataTable
             onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
             onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
             id="customerListTable" var="customer"
             value="#{customerList.resultList}" rowKey="#{customer.id}"
             rowKeyVar="custId">
            
            
             <rich:column>
             <f:facet name="header">
             <a4j:commandLink styleClass="columnHeader" action="#{customerList.setOrder(customerList.order=='id desc' ? 'id asc' : 'id desc')}"
             reRender="customerTable" value="id #{customerList.order=='id asc' ? messages.down : ( customerList.order=='id desc' ? messages.up : '()' )}"/>
             </f:facet>
             <a4j:commandLink
             action="#{customerHome.setCustomerId(customer.id)}"
             value="#{customer.id}" reRender="customerTabs">
             <s:conversationId />
             </a4j:commandLink>
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <a4j:commandLink styleClass="columnHeader" action="#{customerList.setOrder(customerList.order=='code desc' ? 'code asc' : 'code desc')}"
             reRender="customerTable" value="??? #{customerList.order=='code asc' ? messages.down : ( customerList.order=='code desc' ? messages.up : '()' )}"/>
             </f:facet>
             #{customer.code}
             </rich:column>
            
             <rich:column>
             <f:facet name="header">EDIT</f:facet>
             <a4j:commandButton value="edit" name="editCust"
             image="/img/edit_icon.gif"
             oncomplete="javascript:Richfaces.showModalPanel('custPanel');"
             reRender="custPanel"
             action="#{customerHome.setCustomerId(customer.id)}" >
            
             <s:conversationId />
             </a4j:commandButton>
             </rich:column>
            
            
            
             </rich:dataTable>
             <a4j:commandButton actionListener="#{customerHome.newCustomer}"
             value="NEW ROW(poUP)"
             oncomplete="javascript:Richfaces.showModalPanel('custPanel');"
             reRender="custPanel" />
             </a4j:region></div>
             </rich:panel>
            
             <!-- POPUP -->
             </a4j:form>
             <rich:modalPanel id="custPanel" width="300" height="300">
            
             <f:facet name="header">
             <h:outputText value="edit/insert client" />
             </f:facet>
             <h:form id="popUpForm">
            
             <h:panelGrid columns="2">
            
             <h:outputLabel value="code" for="code" />
             <h:inputText id="code" value="#{customerHome.instance.code}" />
            
             <h:outputLabel value="name" for="name" />
             <h:inputText id="name" value="#{customerHome.instance.name}" />
            
             <rich:separator /><rich:separator />
            
             <a4j:commandButton id="updateCustomerButton"
             reRender="customerTable"
             action="#{customerHome.update()}" value="save"
             oncomplete="javascript:Richfaces.hideModalPanel('custPanel');alert('after save');" />
             <h:commandButton value="close"
             onclick="avascript:Richfaces.hideModalPanel('custPanel')"></h:commandButton>
             </h:panelGrid>
             </h:form>
            
            
             </rich:modalPanel>
            
            
            
             </ui:define>
            </ui:composition>
            


            EntityHome:

            package com.metalogic.superfine.entity;
            
            import java.util.ArrayList;
            import java.util.List;
            
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.faces.event.ActionEvent;
            import javax.persistence.FlushModeType;
            
            
            import org.hibernate.FlushMode;
            import org.hibernate.Session;
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.*;
            
            import com.metalogic.superfine.entity.helpers.BaseEntityHome;
            
            @Scope(ScopeType.CONVERSATION)
            @Name("customerHome")
            @Stateful
            
            
            public class CustomerHome extends BaseEntityHome<Customer> implements CustomerLocalHome{
            
            
             @Override
             public void setId(Object id) {
             ((Session)(getPersistenceContext().getDelegate())).setFlushMode(FlushMode.MANUAL) ;
             super.setId(id);
             }
             private String customerId;
            
             @Override
             public Customer getInstance() {
             // TODO Auto-generated method stub
             return super.getInstance();
             }
             @Remove
             public void destroy() {
             }
             @Override
             protected Customer createInstance() {
             Customer customer = new Customer();
             return customer;
             }
             public Customer getDefinedInstance() {
             return isIdDefined() ? getInstance() : null;
             }
            
            
            
            
             @Begin(join=true)
             public void selectCustomerFromTable(ActionEvent event){
            
             String id = getCustomerId();
             setId(new Integer(id));
             getInstance();
            
             }
            
             @Begin(join = true)
             public void newCustomer(ActionEvent event) {
             setId(null);
             instance = new Customer();
             }
            
             @Override
             @End
             public String update() {
            
             String result = "";
             if (getId() == null)
             result = persist();
             else{
             result = super.update();
             //super.render("customerListTable");
             }
             return result;
             }
            
             public String getCustomerId() {
             return customerId;
             }
            
            
             public void setCustomerId(String customerId) {
             this.customerId = customerId;
             }
            
             @Begin(join=true)
             public void setCustomerId(Integer customerId) {
             setId(customerId);
             }
            
            }
            


            • 3. Re: reRender dataTable

              Hi!
              I'd not see implementation "#{customerList.resultList}". Maybe problem in the "customerList" Managed Bean?
              But in my code I generate for all new items a temporary Id for ability after removing and editing new items without saving in database.

              • 4. Re: reRender dataTable

                P.S. I don't use and know JBoss Seam

                • 5. Re: reRender dataTable
                  mrohad

                  oh , I'm using Jboss seam , and EntityQuery implements getResultList
                  when I call EntityQuery.refresh , it works fine..