6 Replies Latest reply on Jun 10, 2009 10:03 AM by Serhiy Zastavnyy

    Wrong selection when filter using

    Serhiy Zastavnyy Novice

      I created modalPanel, created HtmlExtendedDataTable on panel.
      When I make double click on some row - action is fireing.
      When I do not use filter - everything works fine, but when I type something in filter field - SimpleSelection object has wrong value.
      My code:

       HtmlExtendedDataTable l = new HtmlExtendedDataTable();
       eF.createValueExpression(eC, "#{bean.selectionData}", List.class));
       eF.createValueExpression(eC, "#{bean.selectionCurrentItem}", SimpleSelection.class));
       l.getChildren().add(createListNameColumn(listId, "310px"));

       public static HtmlColumn createListNameColumn(String lId, String width){
       HtmlColumn c = new HtmlColumn();
       ValueExpression nameExpr = eF.createValueExpression(eC, "#{item.name}", String.class);
       c.setValueExpression("filterBy", nameExpr);
       c.setValueExpression("sortBy", nameExpr);
       HtmlOutputText cc = new HtmlOutputText();
       cc.setValueExpression("value", nameExpr);
       HtmlOutputText ch = new HtmlOutputText();
       c.getFacets().put("header", ch);

       public Object getCurrentSelectionObject(){
       Iterator<Object> iterator = getSelectionCurrentItem().getKeys();
       while (iterator.hasNext()){
       Object key = iterator.next();
       return getSelectionData().get(Integer.parseInt(key.toString()));
       return null;

      When filter is useing , getCurrentSelectionObject returns wrong value.
      Please help me, what I am doing wrong. I use RF 3.3.1

        • 1. Re: Wrong selection when filter using
          Ilya Shaikovsky Master

          rowKey which stored in simpleSelection isn't the same as index in the collection because data is filtered. check our sample for scrollableDataTable. It contains the code which will works with filtering.

          • 2. Re: Wrong selection when filter using
            Serhiy Zastavnyy Novice

            Ilya, looks like example works correctly only with ScrollableTable.
            I tried to use code from demo with ExtendedDataTable and I have exception when I rerendered table.
            My scenario:
            1. Started action. Tried to get current row data of the extended table. Method bindingTable.setRowKey( some Key ) must be called. It is the cause.
            2. Tried to rerendered table after action.
            I had exception in ajax log:

            error[my_time]: New node for ID MY_TABLE_ID :j_id303_menu_script is not present in response.

            Could you please cjeck it with ExtendedDataTabele ? Looks like method table.setRowKey(key) do not want work correctly with ExtendedDataTable.

            • 4. Re: Wrong selection when filter using
              Serhiy Zastavnyy Novice

              Could someone please help me on this ?

              • 5. Re: Wrong selection when filter using
                Ilya Shaikovsky Master

                sorry for the delay.

                this works fine for me for filtered table.(just changed demo code)

                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml"
                 <h:panelGrid columns="2" columnClasses="top,top">
                 value="#{extendedTableBean.capitalsDataModel}" var="cap" id="tablesource"
                 width="580px" height="400px"
                 <rich:column sortable="false" label="Flag">
                 <f:facet name="header">
                 <h:outputText value="Flag" />
                 <h:graphicImage value="#{cap.stateFlag}" />
                 <rich:column sortable="true" sortBy="#{cap.state}"
                 filterBy="#{cap.state}" filterEvent="onkeyup" width="170px"
                 label="State Name">
                 <f:facet name="header">
                 <h:outputText value="State Name" />
                 <h:outputText value="#{cap.state}" />
                 <rich:column sortable="true" sortBy="#{cap.name}"
                 filterBy="#{cap.name}" filterEvent="onkeyup" width="170px"
                 label="State Capital">
                 <f:facet name="header">
                 <h:outputText value="State Capital" />
                 <h:outputText value="#{cap.name}" />
                 <rich:column sortable="false" label="Time Zone">
                 <f:facet name="header">
                 <h:outputText value="Time Zone" />
                 <h:outputText value="#{cap.timeZone}" />
                 <f:facet name="header">
                 <h:outputText value="Sort/Selection modes changing" />
                 <h:panelGrid columns="2">
                 <h:outputText value="Sort Mode:" />
                 <h:selectOneMenu value="#{extendedTableBean.sortMode}">
                 <f:selectItem itemLabel="Single" itemValue="single" />
                 <f:selectItem itemLabel="Multi" itemValue="multi" />
                 <a4j:support event="onchange" ajaxSingle="true" reRender="table" />
                 <h:outputText value="Selection Mode:" />
                 <h:selectOneMenu value="#{extendedTableBean.selectionMode}">
                 <a4j:support ajaxSingle="true" event="onchange" reRender="table" />
                 <f:selectItem itemLabel="Single" itemValue="single" />
                 <f:selectItem itemLabel="Multi" itemValue="multi" />
                 <f:selectItem itemLabel="None" itemValue="none" />
                 <a4j:commandButton value="Show Current Selection" reRender="table"
                 oncomplete="javascript:Richfaces.showModalPanel('panel');" />
                 <rich:modalPanel id="panel" autosized="false" keepVisualState="false"
                 width="315" height="230">
                 <f:facet name="header">
                 <h:outputText value="Selected Rows" />
                 <f:facet name="controls">
                 <span style="cursor: pointer"
                 <h:panelGroup layout="block" styleClass="scrolls">
                 <rich:dataTable value="#{extendedTableBean.selectedCapitals}"
                 var="sel" id="table">
                 <f:facet name="header">
                 <h:outputText value="Make" />
                 <h:outputText value="#{sel.name}" />

                package org.richfaces.demo.extendedDataTable;
                import java.util.ArrayList;
                import java.util.Iterator;
                import java.util.List;
                import org.richfaces.demo.capitals.Capital;
                import org.richfaces.demo.datafilterslider.DemoInventoryItem;
                import org.richfaces.model.DataProvider;
                import org.richfaces.model.ExtendedTableDataModel;
                import org.richfaces.model.selection.Selection;
                import org.richfaces.model.selection.SimpleSelection;
                 * @author Ilya Shaikovsky
                public class ExtendedTableBean {
                 private String sortMode = "single";
                 private String selectionMode = "multi";
                 private List<Capital> selectedCapitals = new ArrayList<Capital>();
                 public List<Capital> getSelectedCapitals() {
                 return selectedCapitals;
                 public void setSelectedCapitals(List<Capital> selectedCapitals) {
                 this.selectedCapitals = selectedCapitals;
                 public Selection getSelection() {
                 return selection;
                 public void setSelection(Selection selection) {
                 this.selection = selection;
                 private Selection selection = new SimpleSelection();
                 private ExtendedTableDataModel<Capital> dataModel;
                 private List<Capital> capitals = new ArrayList<Capital>();
                 public String getSortMode() {
                 return sortMode;
                 public void setSortMode(String sortMode) {
                 this.sortMode = sortMode;
                 public String getSelectionMode() {
                 return selectionMode;
                 public void setSelectionMode(String selectionMode) {
                 this.selectionMode = selectionMode;
                 public ExtendedTableBean() {
                 public void takeSelection() {
                 Iterator<Object> iterator = getSelection().getKeys();
                 while (iterator.hasNext()) {
                 Object key = iterator.next();
                 getSelectedCapitals().add((Capital) getCapitalsDataModel().getObjectByKey(key));
                 public ExtendedTableDataModel<Capital> getCapitalsDataModel() {
                 if (dataModel == null) {
                 dataModel = new ExtendedTableDataModel<Capital>(
                 new DataProvider<Capital>() {
                 private static final long serialVersionUID = 5054087821033164847L;
                 public Capital getItemByKey(Object key) {
                 for (Capital c : capitals) {
                 if (key.equals(getKey(c))) {
                 return c;
                 return null;
                 public List<Capital> getItemsByRange(int firstRow,
                 int endRow) {
                 return capitals.subList(firstRow, endRow);
                 public Object getKey(Capital item) {
                 return item.getName();
                 public int getRowCount() {
                 return capitals.size();
                 return dataModel;
                 public void setCapitals(List<Capital> capitals) {
                 this.capitals = capitals;

                • 6. Re: Wrong selection when filter using
                  Serhiy Zastavnyy Novice

                  Thank you,
                  using ExtendedTableDataModel it works fine for me now.