0 Replies Latest reply on Dec 21, 2010 6:02 AM by Ruben Lopez

    Multiple selection with ExtendedDataTable and EntityQuery

    Ruben Lopez Newbie


      I'm trying to use extendedDataTable instead of dataTable on an application generated by seam-gen. I followed the example in RichFaces Live Demo, but I can´t make the multiple selection work.

      This is what I´m trying to do:

      public interface BaseEntity {
           public Object getKey();

      public class ExtendedEntityQuery<T extends BaseEntity> extends EntityQuery<T> {
           private static final long serialVersionUID = 1L;
           private String sortMode = "multi";
           private String selectionMode = "multi";
           private Object tableState;
           private Selection selection = new SimpleSelection();
           private ExtendedTableDataModel<T> dataModel;
           private List<T> selectedList = new ArrayList<T>();
           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 ExtendedEntityQuery() {
           public void takeSelection(){
                Iterator<Object> iterator = getSelection().getKeys();
                while (iterator.hasNext()) {
                     Object key = iterator.next();
           public ExtendedTableDataModel<T> getDataModel() {
                if (dataModel == null) {
                     dataModel = new ExtendedTableDataModel<T>(new DataProvider<T>(){
                          private static final long serialVersionUID = 1L;
                          public T getItemByKey(Object key) {
                               for(T c : getResultList()){
                                    if (key.equals(getKey(c))){
                                         return c;
                               return null;
                          public List<T> getItemsByRange(int firstRow, int endRow) {
                               return getResultList().subList(firstRow, endRow);
                          public Object getKey(T item) {
                               return item.getKey();
                          public int getRowCount() {
                               return getResultList().size();
                return dataModel;
           public Object getTableState() {
                return tableState;
           public void setTableState(Object tableState) {
                this.tableState = tableState;
           public Selection getSelection() {
                return selection;
           public void setSelection(Selection selection) {
                this.selection = selection;
           public List<T> getSelectedList() {
                return selectedList;
           public void setSelectedList(List<T> selectedList) {
                this.selectedList = selectedList;

      As you can see is just a copy-paste of the ExtendeTableBean.java (from the RF example) but using generics.

      The code generated by seam is:

      public class DepartamentoList extends ExtendedEntityQuery<Departamento> {
           private static final long serialVersionUID = -3548296613352342917L;
           private static final String EJBQL = "select departamento from Departamento departamento";
           private static final String[] RESTRICTIONS = {"blah, blah"};
           private Departamento departamento = new Departamento();
           public DepartamentoList() {
           public Departamento getDepartamento() {
                return departamento;

      I changed the scope to PAGE and extended from ExtendedEntityQuery.

      My view is:

      <rich:extendedDataTable width="786px" height="200px"
           rendered="#{not empty departamentoList.resultList}"
           noDataLabel="No existen datos">
           <rich:column sortable="true" width="70px"
                <f:facet name="header">Código</f:facet>
                <h:outputText value="#{_departamento.codigo}"/>
           <rich:column sortable="true" width="700px"
                <f:facet name="header">Descripción</f:facet>
                <h:outputText value="#{_departamento.descripcion}"/>
           <a:support reRender="selectiontable"
                event="onselectionchange" />
      <s:div styleClass="actionButtons" rendered="#{empty from}">
      <s:button view="/DepartamentoEdit.xhtml"
           id="create" propagation="none" value="Nuevo Departamento">
                 <f:param name="departamentoId"/>
      <rich:dataTable value="#{departamentoList.selectedList}"
           var="sel" id="selectiontable">
                <h:outputText value="#{sel.codigo}" />
                <h:outputText value="#{sel.descripcion}" />

      SimpleSelection.getKeys() always returns the index of the selected rows instead of the keys of the selected entities. I don´t know how to make it work, if anyone have an example of how to do this it would be very helpfull for me. 

      Thanks in advance