0 Replies Latest reply on Sep 22, 2011 5:27 AM by pangbuddy

    extendedDataTable selection problem

    pangbuddy

      Dears,

      In my recent project, i have one page which contains 4 extendedDataTable,  I use them as a filter selections.

       

      the problem is, for each table the selector always returns a collection of all 4 tables, for example, i select rows (1,2) in table1, then I only select row (3) in table2, but the listener catch the table2 has selected (1,2,3).

       

      i tried to search similar issue for two days, but on result yet, here is my last hope, someone help thanks!

       

       

       

      <div xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:mj="http://mojarra.dev.java.net/mojarra_ext"
           xmlns:ui="http://java.sun.com/jsf/facelets">
          <f:view>
              <ui:composition template="../template/template.xhtml">
                  <ui:define name="title">Scope Option</ui:define>
                  <ui:define name="main_body">
      
                  <h:panelGrid columns="4">
                      <h:form>
                      <rich:extendedDataTable value="#{marketScopeBean.countryInitials}" 
                                              var="filterItem"
                                              id="filter-country-initial"
                                              selection="#{marketScopeBean.countryInitialSelection}"
                                              frozenColumns="2" 
                                              selectionMode="multipleKeyboardFree"
                                              style="height: 500px">
                          <a4j:ajax execute="@form" event="selectionchange" listener="#{marketScopeBean.selectionListener}" />
                          <f:facet name="header"><h:outputText value="Country" /></f:facet>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Code" /></f:facet>
                              <h:outputText value="#{filterItem.code}" />
                          </rich:column>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Description" /></f:facet>
                              <h:outputText value="#{filterItem.description}" />
                          </rich:column>
                      </rich:extendedDataTable>
      
                      <rich:extendedDataTable value="#{marketScopeBean.activitySectors}" 
                                              var="filterItem"
                                              id="filter-activity-sector"
                                              selection="#{marketScopeBean.activitySectorSelection}"
                                              frozenColumns="2" 
                                              selectionMode="multipleKeyboardFree"
                                              style="height: 500px">
                          <a4j:ajax execute="@form" event="selectionchange" listener="#{marketScopeBean.selectionListener}" render="activity-sectors"/>
                          <f:facet name="header"><h:outputText value="Activity Sector" /></f:facet>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Code" /></f:facet>
                              <h:outputText value="#{filterItem.code}" />
                          </rich:column>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Description" /></f:facet>
                              <h:outputText value="#{filterItem.description}" />
                          </rich:column>
                      </rich:extendedDataTable>
      
                      <rich:extendedDataTable value="#{marketScopeBean.companyTypes}" 
                                              var="filterItem"
                                              id="filter-company-type"
                                              selection="#{marketScopeBean.companyTypeSelection}"
                                              frozenColumns="2" 
                                              selectionMode="multipleKeyboardFree"
                                              style="height: 500px">
                          <a4j:ajax execute="@form" event="selectionchange" listener="#{marketScopeBean.selectionListener}" />
                          <f:facet name="header"><h:outputText value="Company Type" /></f:facet>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Code" /></f:facet>
                              <h:outputText value="#{filterItem.code}" />
                          </rich:column>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Description" /></f:facet>
                              <h:outputText value="#{filterItem.description}" />
                          </rich:column>
                      </rich:extendedDataTable>
      
                      <rich:extendedDataTable value="#{marketScopeBean.companySizes}" 
                                              var="filterItem"
                                              id="filter-company-size"
                                              selection="#{marketScopeBean.companySizeSelection}"
                                              frozenColumns="2" 
                                              selectionMode="multipleKeyboardFree"
                                              style="height: 500px">
                          <a4j:ajax execute="@form" event="selectionchange" listener="#{marketScopeBean.selectionListener}" />
                          <f:facet name="header"><h:outputText value="Company Size" /></f:facet>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Code" /></f:facet>
                              <h:outputText value="#{filterItem.code}" />
                          </rich:column>
                          <rich:column>
                              <f:facet name="header"><h:outputText value="Description" /></f:facet>
                              <h:outputText value="#{filterItem.description}" />
                          </rich:column>
                      </rich:extendedDataTable>
                      </h:form>
                  </h:panelGrid>
      
                  </ui:define>
              </ui:composition>
          </f:view>
      </div>
      

       

      @ManagedBean
      @SessionScoped
      public class MarketScopeBean extends SpringBeanAutowiringSupport implements Serializable{
      
          private static final long serialVersionUID = -6165030480785247375L;
          //private static Logger log = Logger.getLogger(ProjectBean.class);
      
          @Autowired
          @Qualifier("daoService")
          private DaoService daoService;
      
          @Autowired
          @Qualifier("dbCache")
          private DBCache dbCache;
      
          @ManagedProperty(value="#{userBean}")
          private UserBean userBean;
      
          @ManagedProperty(value="#{projectBean}")
          private ProjectBean projectBean;
      
          private Collection<Object> countryInitialSelection;
          private Collection<Object> activitySectorSelection;
          private Collection<Object> companyTypeSelection;
          private Collection<Object> companySizeSelection;
      
          private List<CountryInitial> countryInitialSelectionItems = new ArrayList<CountryInitial>();
          private List<String> activitySectorSelectionItems = new ArrayList<String>();
          private List<String> companyTypeSelectionItems = new ArrayList<String>();
          private List<String> companySizeSelectionItems = new ArrayList<String>();
      
      
          public void selectionListener(AjaxBehaviorEvent event) {
              UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
              Object originalKey = dataTable.getRowKey();
              //System.out.println(dataTable.getId());
              if(dataTable.getId().equals("filter-country-initial")){
                  countryInitialSelectionItems.clear();
                  for (Object selectionKey : countryInitialSelection) {
                      dataTable.setRowKey(selectionKey);
                      if (dataTable.isRowAvailable()) {
                          countryInitialSelectionItems.add((CountryInitial) dataTable.getRowData());
                      }
                  }
              }else if(dataTable.getId().equals("filter-activity-sector")){
                  activitySectorSelectionItems.clear();
                  for (Object selectionKey : activitySectorSelection) {
                      dataTable.setRowKey(selectionKey);
                      if (dataTable.isRowAvailable()) {
                          activitySectorSelectionItems.add(((ActivitySector) dataTable.getRowData()).getCode());
                      }
                  }
              }else if(dataTable.getId().equals("filter-company-type")){
                  companyTypeSelectionItems.clear();
                  for (Object selectionKey : companyTypeSelection) {
                      dataTable.setRowKey(selectionKey);
                      if (dataTable.isRowAvailable()) {
                          companyTypeSelectionItems.add(((CompanyType) dataTable.getRowData()).getCode());
                      }
                  }
              }else if(dataTable.getId().equals("filter-company-size")){
                  companySizeSelectionItems.clear();
                  for (Object selectionKey : companySizeSelection) {
                      dataTable.setRowKey(selectionKey);
                      if (dataTable.isRowAvailable()) {
                          companySizeSelectionItems.add(((CompanySize) dataTable.getRowData()).getCode());
                      }
                  }
              }
              dataTable.setRowKey(originalKey);
          }
      
      
          public Collection<Object> getCountryInitialSelection() {
              return countryInitialSelection;
          }
          public void setCountryInitialSelection(
                  Collection<Object> countryInitialSelection) {
              this.countryInitialSelection = countryInitialSelection;
          }
          public Collection<Object> getActivitySectorSelection() {
              return activitySectorSelection;
          }
          public void setActivitySectorSelection(
                  Collection<Object> activitySectorSelection) {
              this.activitySectorSelection = activitySectorSelection;
          }
          public Collection<Object> getCompanyTypeSelection() {
              return companyTypeSelection;
          }
          public void setCompanyTypeSelection(Collection<Object> companyTypeSelection) {
              this.companyTypeSelection = companyTypeSelection;
          }
          public Collection<Object> getCompanySizeSelection() {
              return companySizeSelection;
          }
          public void setCompanySizeSelection(Collection<Object> companySizeSelection) {
              this.companySizeSelection = companySizeSelection;
          }
      
      }