7 Replies Latest reply on Apr 22, 2010 10:55 AM by Josef Eisele

    ExtendedDataTable - Select rowentry using Backingbean

    Josef Eisele Newbie

      Hi @ll,

       

      we use a Richfaces ExtendedDataTable and do some CRUDS Functionality on one JSF-Page.

       

      In case of the Insert-Case the following is done:

           1) User is pushing the Button "Insert" on the Page.

           2) Navigationrule navigates to Method in Backing Bean:    

                2.1 New Entry is added to the ExtendedTableDataModel (old Model removed, new added)

                2.2 Selection-Object is created as SingleSelection - Object and selected Key is the New Entry

                2.3 Method results with empty string, therefore same page is called

           3) Result in the Browser: Everything is fine, new Entry is in the UI-Table, BUT not selected

       

      -> How can I select an entry of the ExtendedDataTable in the Backing Bean ??

       

      Thanx in advance

       

      Josef

        • 1. Re: ExtendedDataTable - Select rowentry using Backingbean
          Ilya Shaikovsky Master
          if row keys - your custom objects - do not forget about rowKeyConverter.
          • 2. Re: ExtendedDataTable - Select rowentry using Backingbean
            Josef Eisele Newbie

            Hi Ilya,

             

            So far we don't use this attribute, we use:

             

                <rich:extendedDataTable id="table"
                        rows="0" columnClasses="col" height="250px" width="400px"
                        value="#{bean.dataModel}" styleClass="myStyle"
                        var="meld" sortMode="single"
                        selection="#{bean.selection}"
                        enableContextMenu="true"
                        tableState="#{bean.tableState}"
                        selectionMode="single">

             

            Do you have an example ?

             

            cu Josef

            • 4. Re: ExtendedDataTable - Select rowentry using Backingbean
              Josef Eisele Newbie

              BackingBean:

               

              ...

                  private ExtendedTableDataModel<HeVmgDvnTO> dataModel;
                  private HeVmgDvnTO selectedMeldung = new HeVmgDvnTO();
                  private String tableState;
                  private String order;
                  private Selection selection;

              ...

               

                  public String navNeu(){
                      // erzeugt einen neuen Eintrag im Model der dann spaeter gespeichert werden kann
                      HeVmgDvnTO neuerEintrag = new HeVmgDvnTO();
                      // Foreign Key setzen
                      neuerEintrag.setHevmgId(vmgId);
                      neuerEintrag.setChanged(true);
                      neuerEintrag.setId(0);
                     
                      // an das Modell einen Eintrag hinzufuegen geht nicht daher wegwerfen und neu
                      HeVmgDvnProvider dataProvider = (HeVmgDvnProvider) dataModel.getDataProvider();
                      List<HeVmgDvnTO> dvnListe = dataProvider.getItems();
                     
                      // jetzt hinzufuegen und Modell neu setzen
                      dvnListe.add(neuerEintrag);
                      dataModel = new ExtendedTableDataModel<HeVmgDvnTO>(
                              new HeVmgDvnProvider(dvnListe));
                     
                      // Diesen neuen Eintrag selektieren
                      SimpleSelection simpleselect = new SimpleSelection();
                      simpleselect.addKey(0);
                      selection = simpleselect;
                     
                      dataModel.setRowKey(0);
                     
                      selectedMeldung = neuerEintrag;
                     
                      return "";
                  }


              ...

               

              DataProvider-Klasse:

               

              ...

              public class HeVmgDvnProvider implements DataProvider<HeVmgDvnTO> {

              ...

              • 6. Re: ExtendedDataTable - Select rowentry using Backingbean
                Josef Eisele Newbie

                public class HeVmgDvnProvider implements DataProvider<HeVmgDvnTO> {

                 

                    private static final long serialVersionUID = 5241196402571534077L;

                 

                    /**
                     * Datencontainer
                     */
                    private List<HeVmgDvnTO> items;
                   
                    public HeVmgDvnProvider(List<HeVmgDvnTO> items) {
                        super();
                        this.items = items;
                    }
                   
                    public List<HeVmgDvnTO> getItems() {
                        return items;
                    }

                 

                    public void setItems(List<HeVmgDvnTO> items) {
                        this.items = items;
                    }

                 

                   
                    /* (non-Javadoc)
                     * @see org.richfaces.model.DataProvider#getItemByKey(java.lang.Object)
                     */
                    public HeVmgDvnTO getItemByKey(Object key) {
                        if (key == null)
                            return null;
                        for (HeVmgDvnTO entity : getItems()){
                            if (Long.valueOf(entity.getId()).equals(key))
                                return entity;
                        }
                        return null;
                    }

                 

                    /* (non-Javadoc)
                     * @see org.richfaces.model.DataProvider#getItemsByRange(int, int)
                     */
                    public List<HeVmgDvnTO> getItemsByRange(int firstRow, int lastRow) {
                         return getItems().subList(firstRow, lastRow);
                    }

                 

                    /* (non-Javadoc)
                     * @see org.richfaces.model.DataProvider#getKey(java.lang.Object)
                     */
                    public Object getKey(HeVmgDvnTO item) {
                        return item.getId();
                    }

                 

                    /* (non-Javadoc)
                     * @see org.richfaces.model.DataProvider#getRowCount()
                     */
                    public int getRowCount() {
                         return getItems().size();
                    }

                 

                   
                }

                • 7. Re: ExtendedDataTable - Select rowentry using Backingbean
                  Josef Eisele Newbie

                  I think I found the solution under:

                   

                  https://jira.jboss.org/jira/secure/ReleaseNote.jspa?projectId=12310341&styleName=Html&version=12312242

                  ...

                  [RF-8229] - ExtendedDataTable: programmatic changes in table state are not applied to the table (https://jira.jboss.org/jira/browse/RF-8229)

                  ...


                  The Future will fix it...