1 Reply Latest reply on Jul 16, 2009 4:50 PM by sl0005

    DataModel, inheritance, NoRowAvailableException

    sl0005

      I have a number of beans with similar functions. I want to use one abstract parent class to unite these functions.
      To implement DataModel I add in parent class following (copy from org.jboss.seam.framework.Query ) :


         @Transactional
          public DataModel getDataModel(){
                 if (dataModel==null){
                    dataModel = new ListDataModel();
                    dataModel.setWrappedData(getResultList());
                 }
                 return dataModel;
          }
              
          @SuppressWarnings("unchecked")
          public E getDataModelSelection(){
                 return (E) getDataModel().getRowData();
          }
              
          public int getDataModelSelectionIndex(){
                 return getDataModel().getRowIndex();
          }
      
          public void edit(){
                setItem(getDataModelSelection());
          }
      



      than I use DataModel in xhtml :


      <h:form id="list">
          <rich:dataTable id="aList" var="item" value="#{bean.dataModel}">
              <h:column>
                  <f:facet name="header">
                   ......
                  </f:facet>
               <s:link id="editItem" view="/editItem.xhtml" value="#{item.id}" action="#{bean.edit}"/>
              </h:column>
                   ......
      



      when I click on the link in table I get NoRowAvailableException.


      Whan is wrong here?



        • 1. Re: DataModel, inheritance, NoRowAvailableException
          sl0005

          The solution is found!
          Must be :


             @Transactional
              public DataModel getDataModel(){
                     if (dataModel==null){
                        dataModel = new ListDataModel();
                        dataModel.setWrappedData(getResultList());
                           Contexts.getSessionContext().set("DataModelOne", dataModel);
                     }
                     return dataModel;
              }
                  
              @SuppressWarnings("unchecked")
              public E getDataModelSelection(){
                     return (E) getDataModel().getRowData();
              }
                  
              public int getDataModelSelectionIndex(){
                     return getDataModel().getRowIndex();
              }
          
              public void edit(){
                    setItem(getDataModelSelection());
              }
          



          than I use DataModel in xhtml :


          <h:form id="list">
              <rich:dataTable id="aList" var="item" value="#{DataModelOne}">
                  <h:column>
                      <f:facet name="header">
                       ......
                      </f:facet>
                   <s:link id="editItem" view="/editItem.xhtml" value="#{item.id}" action="#{bean.edit}"/>
                  </h:column>
                       ......
          



          This way it is possible to use DataModel when you need been inheritance (because annotation @DataModel cannot be inherited, so here is a way around)