6 Replies Latest reply on Nov 18, 2005 8:17 AM by Marius Oancea

    Two way navigation in @DataModel

    Marius Oancea Novice

      I have a component containing a @DataModel and a @DataModelSelectionIndex. I need a interface where i display all entries (datatable) and in this datatable i can randomly select any entry (selectItem method <- one way of navigation).

      @DataModel
       List<TocEntry> itemsList;
      
       @DataModelSelectionIndex
       private int itemNdx;
      
       public String selectTocEntry() {
       currentItem = itemsList.get(itemNdx);
       ....
       }
       public String nextItem() {
       ++itemNdx;
       return selectTocEntry();
       }
      


      nextItem gets called when i press "next" button <- second way of navigation.

      Seems that seam initialize itemNdx to -1 when i have the datatable rendered. selection in the table works. If I delete datatable from the page, "next" button also works.

      Only when both ways of navigations are present the problem is existing.

      The problem seems to be from Component.java:

      private void injectDataModelSelection(Object bean)
       {
       final String name;
       if (dataModelGetter!=null)
       {
       name = toName( dataModelGetter.getAnnotation(DataModel.class).value(), dataModelGetter );
       }
       else if (dataModelField!=null)
       {
       name = toName( dataModelField.getAnnotation(DataModel.class).value(), dataModelField );
       }
       else {
       return;
       }
      
       javax.faces.model.DataModel dataModel = (javax.faces.model.DataModel) scope.getContext().get(name);
       if (dataModel!=null)
       {
       if (dataModelSelectionIndexSetter!=null)
       {
       setPropertyValue(bean, dataModelSelectionIndexSetter, name, dataModel.getRowIndex() );
       }
       if (dataModelSelectionSetter!=null)
       {
       Object rowData = (dataModel.getRowIndex() == -1) ? null : dataModel.getRowData();
       setPropertyValue(bean, dataModelSelectionSetter, name, rowData);
       }
       if (dataModelSelectionIndexField!=null)
       {
       setFieldValue(bean, dataModelSelectionIndexField, name, dataModel.getRowIndex() );
       }
       if (dataModelSelectionField!=null)
       {
       Object rowData = (dataModel.getRowIndex() == -1) ? null : dataModel.getRowData();
       setFieldValue(bean, dataModelSelectionField, name, rowData);
       }
       }
       }
      


      Seems that all the time selected value from table is taken even if i press next button.

      I can solve the problem somehow with a backup variable where I keep old selected index but I hate such solutions.

      Any other solution?

      IMHO the value of DataModelSelectionIndex has to be injected only when the selection was triggered from table (but how to make the distinction?).