Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
475
gridView refresh problem
posted

Hi,

 I have made new discovery, the problem is ig:gridEditing tag. If I have gridEditing in gridView as the following: 

<ig:gridEditing id="#{tab}GridEditing" enableOnMouseClick="single" editMode="cell"

cellValueChangeListener="#{transacBean.onCellValueChange}"  />

 

<ig:columnSelectRow id="#{tab}SelectRow" showSelectAll="true"></ig:columnSelectRow>

 ...

Then the grid will not be refresh.

 

old posting:

 If I use gridView in a regular HTML form:

<form id="idCaseTransactionTestForm" name="CaseTransactionTestForm">

<input type="submit" value="submit"/>

 

<ig:gridView id="idGridView" dataSource="#{transacBean.caseTran}" binding="#{transacBean.gridView}"

selectedRowsChangeListener="#{transacBean.onSelectedRowsChange}"

columnHeaderStyleClass="gridHeader" styleClass="ccTextSytleClass" rendered="true" >

 

..

</ig:gridView>

</form>

 the event handler onSelectedRowsChange() will not be called if you select rows. If the submit button is pressed, the page will be submitted and the view will be refreshed.

Trying to get onSelectedRowsChange() called, I use

<h:form>

<gridView ..../>

</h:form>

 where h:form is of

http://java.sun.com/jsf/html

The event handler onSelectedRowsChange() will be called correctly, but the page will not be refreshed even the backing bean is called, it shows the initial data.

 The problem exists for other ig controls. It doesn't refresh or event handler doesn't got called. Please help.

 Thanks.

 

  • 1765
    posted

    Hi yzbythesea , Attached below is the sample GridView application. In order to refresh grid we need to call 'grid.dataBind()' in our backing bean under action method.

    Thank you! 

    1) gridReload.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>

    <%@ taglib prefix="ig" uri="http://ko.infragistics.com/faces/netadvantage" %>   
    <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Grid Reload Example</title>
    </head>
    <body>
     <f:view>
      <h:form> 
       <ig:gridView
                binding="#{gridReload.grid}"
                dataSource="#{gridReload.gridData}"
                 styleClass="gridView"
                 dataKeyName="email"
                 selectedRowsChangeListener="#{gridReload.onSelectedRowsChange}"
                 pageChangeListener="#{gridReload.onPageChange}"
                 pageSize="5">
                 <ig:column resizable="true">
                   <h:outputText value="#{DATA_ROW.lastName}"></h:outputText>
                   <f:facet name="header">
                     <h:outputText value="Last Name"></h:outputText>
                   </f:facet>
                 </ig:column>
                 <ig:column resizable="true">
                   <h:outputText value="#{DATA_ROW.firstName}"></h:outputText>
                   <f:facet name="header">
                     <h:outputText value="First Name"></h:outputText>
                   </f:facet>
                 </ig:column>
                 <ig:column resizable="true">
                   <h:outputText value="#{DATA_ROW.email}"></h:outputText>
                   <f:facet name="header">
                     <h:outputText value="Email"></h:outputText>
                   </f:facet>
                 </ig:column>
                 <ig:column resizable="true">
                   <h:outputText value="#{DATA_ROW.phone}"></h:outputText>
                   <f:facet name="header">
                     <h:outputText value="Phone"></h:outputText>
                   </f:facet>
                 </ig:column>
                 <ig:column resizable="true">
                   <h:outputText value="#{DATA_ROW.type}"></h:outputText>
                   <f:facet name="header">
                     <h:outputText value="Category"></h:outputText>
                   </f:facet>
                 </ig:column>
                 <ig:column resizable="true">
                   <h:outputText value="#{DATA_ROW.salary}"></h:outputText>
                   <f:facet name="header">
                     <h:outputText value="Salary"></h:outputText>
                   </f:facet>
                 </ig:column>
               </ig:gridView>
             
               <h:commandButton action="#{gridReload.action}" value="Click"/>
               
            </h:form>
     </f:view>
     

    </body>
    </html>

     2) CustomerSimpleGridWithRowSelectionPageBean.java

    package com.infragistics.gridreload;

    import java.util.ArrayList;
    import java.util.Iterator;

    import javax.faces.component.UIOutput;
    import javax.faces.context.FacesContext;

    import com.infragistics.faces.grid.component.GridView;
    import com.infragistics.faces.grid.component.RowItem;
    import com.infragistics.faces.grid.event.SelectedRowsChangeEvent;
    import com.infragistics.faces.shared.event.PageChangeEvent;
    import com.infragistics.faces.shared.smartrefresh.SmartRefreshManager;
    import com.infragistics.gridreload.GridDataDAO;

    public class CustomerSimpleGridWithRowSelectionPageBean {
      
       GridDataDAO data;
      
       //Components for binding.
       GridView grid;
       UIOutput showSelected;
       boolean dat = true;
      
       public ArrayList getGridData() {
         
          // This is the simplest method for retrieving data.
          // We check to see if data is null, in case its being
          // held in the session.
        if(dat){
           if(data == null) data = new GridDataDAO();
           return data.getGridData();
        }else {
         if(data == null) data = new GridDataDAO();
            return data.getGridData2(); 
        }    
       }
      
       public String action() {
        System.out.println("action method called");
        if(dat)
         dat = false;
        else
         dat = true;   
       
        grid.dataBind();

        return "success";
       }
      
       public void onSelectedRowsChange(SelectedRowsChangeEvent event) {
          System.out.println("onSelectedRowsChange fired");     
       }
      
       public void onPageChange(PageChangeEvent event) {
          System.out.println("onPageChangeListener fired");
       }

       public GridView getGrid() {
          return grid;
       }

       public void setGrid(GridView grid) {
          this.grid = grid;
       }

       public UIOutput getShowSelected() {
          return showSelected;
       }

       public void setShowSelected(UIOutput showSelected) {
          this.showSelected = showSelected;
       }

     public boolean isDat() {
      return dat;
     }
     
     public void setDat(boolean dat) {
      this.dat = dat;
     }
      
      
    }

    3) EmployeeBean.java

    package com.infragistics.gridreload;

    import java.util.ArrayList;

    import com.infragistics.gridreload.GridDataDAO;

    public class EmployeeBean {

     private String firstName, lastName, email, phone, type;
     private int recordCounter;
     private float salary;
     private String bgColor;

     public EmployeeBean() {
     }

     // This non-standard bean constructor is inserted to

     // simplify the example code.

     public EmployeeBean(int recordCounter,  String firstName, String lastName, String email,
       String phone, String type, float salary ) {

      this.recordCounter = recordCounter;
      this.firstName = firstName;
      this.lastName = lastName;
      this.email = email;
      this.phone = phone;
      this.type = type;
      this.salary = salary;
     }

     public String getFirstName() {
      return firstName;
     }

     public void setFirstName(String firstName) {
      this.firstName = firstName;
     }

     public String getLastName() {
      return lastName;
     }

     public void setLastName(String lastName) {
      this.lastName = lastName;
     }

     public String getEmail() {
      return email;
     }

     public void setEmail(String email) {
      this.email = email;
     }

     public String getPhone() {
      return phone;
     }

     public void setPhone(String phone) {
      this.phone = phone;
     }

     public int getRecordCounter() {
      return recordCounter;
     }

     public void setRecordCounter(int recordCounter) {
      this.recordCounter = recordCounter;
     }

     public String getType() {
      return type;
     }

     public void setType(String type) {
      this.type = type;
     }

     public String getBgColor() {
      if (type.equalsIgnoreCase("hourly"))
       return "#FFCCCC";
      else if (type.equalsIgnoreCase("salaried"))
       return "#CCCCFF";
      return "white";
     }

     public void setBgColor(String bgColor) {
      this.bgColor = bgColor;
     }

     public float getSalary() {
      return salary;
     }

     public void setSalary(float salary) {
      this.salary = salary;
     }

    }

    4) GridDataDAO.java

    package com.infragistics.gridreload;

    import java.util.ArrayList;

    import com.infragistics.gridreload.EmployeeBean;


    public class GridDataDAO {

     private ArrayList data;
     private ArrayList data2;

     public GridDataDAO() {

      data = new ArrayList();
      data2 = new ArrayList();

      data.add(new EmployeeBean(1, "John", "Smith", "jsmith@abc.com",
        "555-1234", "hourly", 25000.00F));
      data.add(new EmployeeBean(2, "Jane", "Doe", "jdoe@def.com", "555-4321",
        "salaried", 35000.00F));
      data.add(new EmployeeBean(3, "Bob", "Green", "bgreen.fre.com",
        "555-1324", "hourly", 45000.00F));
      data.add(new EmployeeBean(4, "Sally", "Brown", "sbrown.wsx.com",
        "555-0897", "hourly", 80000.00F));
      data.add(new EmployeeBean(5, "Joe", "Armstrong", "jarmstrong@rfv.com",
        "555-4653", "salaried", 65000.00F));
      
      
      data2.add(new EmployeeBean(6, "Bill", "Feldman", "bfeldman@rfv.com",
        "555-0098", "hourly", 25000.00F));
      data2.add(new EmployeeBean(7, "Victor", "Joy", "vjoy@tgb.com",
        "555-7890", "salaried", 100000.00F));
      data2.add(new EmployeeBean(8, "Martin", "Chase", "mchase@ujm.com",
        "555-1123", "salaried", 90000.00F));
      data2.add(new EmployeeBean(9, "Steve", "Short", "sshort@mju.com",
        "555-0765", "hourly", 55000.00F));
      data2.add(new EmployeeBean(10, "Alice", "Baker", "abaker@plm.com",
        "555-1029", "salaried", 120000.00F));
     }

     public ArrayList getGridData() {
      return data;
     }
     
     public ArrayList getGridData2() {
      return data2;
     }

     public ArrayList getHourly() {
      ArrayList x = new ArrayList();
      int i = 0;
      while (i < data.size()) {
       if (((EmployeeBean) data.get(i)).getType().equals("hourly"))
        x.add(data.get(i));
       i++;
      }

      return x;

     }

     public ArrayList getSalaried() {
      ArrayList x = new ArrayList();
      int i = 0;
      while (i < data.size()) {
       if (((EmployeeBean) data.get(i)).getType().equals("salaried"))
        x.add(data.get(i));
       i++;
      }

      return x;
     }

    }