5 Replies Latest reply on Apr 5, 2011 5:29 AM by adballeras

    Problem with rich:extendedDatatable and Selection

    dominic89

      Hi all

       

      I try to get a extenedDataTable working with selection.

       

      I found this discussion http://community.jboss.org/message/54384 and copy some bean-code from it.

      Now there ist the Problem that my Selection is always NULL so the Iterator is null and none Selection is shown in my SeletedItems Table.

       

      Here is my bean:

      /*
      *
      *
      */
      @Name ("staffMemberHome")
      public class StaffMemberHome extends EntityHome<StaffMember>
      {
      
          private static final long    serialVersionUID    = 3588202934854216071L;
          @In (create = true)
          StaffMemberFunctionHome        staffMemberFunctionHome;
          @In (create = true)
          MoviePersonHome                moviePersonHome;
      
          private List<MoviePerson>    selectedPersons    = new ArrayList<MoviePerson>();
          private SimpleSelection        selection;
          private String                    string;
          private ExtendedTableDataModel<MoviePerson> movieDataModel;
          private List<MoviePerson> persons = new ArrayList<MoviePerson>();
      
          public void setStaffMemberId(Integer id)
          {
              setId(id);
          }
      
      
      
          public Integer getStaffMemberId()
          {
              return (Integer) getId();
          }
      
      
      
          @Override
          protected StaffMember createInstance()
          {
              StaffMember staffMember = new StaffMember();
              return staffMember;
          }
      
      
      
          public void load()
          {
              if (isIdDefined())
              {
                  wire();
              }
          }
      
      
      
          public void wire()
          {
              getInstance();
              StaffMemberFunction function = staffMemberFunctionHome.getDefinedInstance();
              if (function != null)
              {
                  getInstance().setFunction(function);
              }
              MoviePerson person = moviePersonHome.getDefinedInstance();
              if (person != null)
              {
                  getInstance().setPerson(person);
              }
          }
      
      
      
          public boolean isWired()
          {
              return true;
          }
      
      
          public StaffMember getDefinedInstance()
          {
              return isIdDefined() ? getInstance() : null;
          }
      
      
      
          public void setString(String string)
          {
              this.string = string;
          }
      
      
      
          public String getString()
          {
              return string;
          }
      
      
      
          public void setSelectedPersons(List<MoviePerson> selectedPersons)
          {
              this.selectedPersons = selectedPersons;
          }
      
      
      
          public List<MoviePerson> getSelectedPersons()
          {
              return selectedPersons;
          }
      
      
      
          public void setSelection(SimpleSelection selection)
          {
              this.selection = selection;
          }
      
      
      
          public SimpleSelection getSelection()
          {
              return selection;
          }
      
      
      
          public void setMovieDataModel(ExtendedTableDataModel<MoviePerson> movieDataModel)
          {
              this.movieDataModel = movieDataModel;
          }
      
      
      
          public ExtendedTableDataModel<MoviePerson> getMovieDataModel()
          {
              if(movieDataModel == null)
              {
                  movieDataModel = new ExtendedTableDataModel<MoviePerson>(new DataProvider<MoviePerson>() {
      
      
                      private static final long    serialVersionUID    = 3053506095034086071L;
      
                      public MoviePerson getItemByKey(Object key){
                          for(MoviePerson mP : persons)
                          {
                              if (key.equals(getKey(mP)))
                              {
                                  return mP;
                              }
                          }
                          return null;
                      }
      
                       public Object getKey(MoviePerson item){
                           return item.getName();
                       }
                       @Override
                       public List<MoviePerson> getItemsByRange(int firstRow, int endRow)
                       {
                           return persons.subList(firstRow, endRow);
                       }
      
                       @Override
                       public int getRowCount()
                       {
                           return persons.size();
                       }
      
                  });
              }
              return movieDataModel;
          }
      
           public void takeSelection() {
               getSelectedPersons().clear();
               Iterator<Object> iterator = getSelection().getKeys();
               while (iterator.hasNext()){
               Object key = iterator.next();
               getMovieDataModel().setRowKey(key);
               getSelectedPersons().add((MoviePerson) getMovieDataModel().getRowData());
               }
               }
      
      }
      

       

      And here my WebPage:

       

       

      <rich:panel id="searchPanel">
                              <f:facet name="header">Person Panel</f:facet>
                                  <s:decorate id="dtest" template="/layout/edit.xhtml">
                                      <ui:define name="label">Person</ui:define>
                                      <h:inputText id="title" styleClass="inputFieldLong"
                                      value="#{moviePersonList.personStr}" />
                                  </s:decorate>
                                  <a:commandButton value="Search" reRender="personShuttle"  ajaxSingle="true" action="#{moviePersonList.getPersonByName()}">
                                      <a:actionparam name="name" value="$('movieDataForm:dtest:title').value" assignTo="#{moviePersonList.personStr}" noEscape="true" />
                                  </a:commandButton>
                              <div style="clear: both;" />
      
                                      <rich:extendedDataTable value="#{moviePersonList.personList}" var="_moviePerson" id="personShuttle" sortMode="single" selectionMode="multi" selection="#{staffMemberHome.selection}" rowKeyVar="key">
                                          <rich:column filterBy="#{_moviePerson.name}"  filterEvent="onkeyup">
                                              #{_moviePerson.name}
                                          </rich:column>
                                          <a:support reRender="selectionTable" event="onselectionchange" action="#{staffMemberHome.takeSelection()}" ajaxSingle="true"/>
                                      </rich:extendedDataTable>
      
                                      <rich:dataTable id="selectionTable" value="#{staffMemberHome.getSelectedPersons()}" var="_selected">
                                          <rich:column>
                                              <f:facet name="header">Selected Person</f:facet>
                                              <h:outputLabel value="#{_selected.name}" />
                                          </rich:column>
      
                                      </rich:dataTable>
      
                          </rich:panel>        
      

      This is only a part of the whole .xhtml File if you need the whole file I will gave it to you.

       

      Maybe you have an idea why the selection ist always NULL.

      Thanks for your help.

       

      Greets

      Dominic

       

      PS: Please exuse me for my bad english but I don't use it so often.