2 Replies Latest reply on Jul 22, 2008 8:33 PM by luxspes

    DataModel outjecting the very first value instead of selected one

    ali1983

      I am using two action classes both with Event Scope. I am sending you the code of the classes please take a look at it and see if u can save the problem


      LocationFactory.java


      This is the class in which I have DataModelSelection


      @Name("locationFactory")
      @Scope(ScopeType.EVENT)
      public class LocationFactory {
      
           @In(create = true) SalesPersonActionBean salesPersonAction;
           @In(create = true) LocationService locationService;
           @In(create = true, required = false) CustomerActionFactory customerActionFactory;
           
           @DataModel
           private List<Locations> lstLocations;
           @DataModelSelection("lstLocations")
           @Out(required = false, scope=ScopeType.SESSION)
           Locations location;
           
           UIDatascroller locationDatascroller;
           
           @SuppressWarnings("unchecked")
           @Factory(value = "lstLocations")
           public void listLocations() {
                int locationsPageFirstIndex;
                List listLocationSubSetRecords;          
                Long locationCount;
                java.util.Vector locationsVector = new Vector();
      
                locationCount = locationService
                          .getLocationRowCount(customerActionFactory.getCustomerWrapper()
                                    .getCustomers().getCustomerNumber());
      
                locationsVector.setSize(locationCount.intValue());
                
                // This statement fetches the current pages first row index
                
                locationsPageFirstIndex = (this.getLocationDatascroller().getPage() * 
                          this.getLocationDatascroller().getDataTable().getRows()) - 
                          this.getLocationDatascroller().getDataTable().getRows();
                
                
                listLocationSubSetRecords = locationService.getLocations(
                          salesPersonAction.getLocationOrderField(), salesPersonAction
                                    .isAscendingOrder(), locationsPageFirstIndex,
                          customerActionFactory.getCustomerWrapper().getCustomers()
                                    .getCustomerNumber());
      
                for (int index = 0; index < listLocationSubSetRecords.size(); index++) {
                     locationsVector.set(locationsPageFirstIndex + index,
                               listLocationSubSetRecords.get(index));
                }
      
                lstLocations = locationsVector;
           }
           
           public void nullLocationList(){
                this.lstLocations = null;
           }
      
           public List<Locations> getLstLocations() {
                return lstLocations;
           }
      
           public void setLstLocations(List<Locations> lstLocations) {
                this.lstLocations = lstLocations;
           }
      
           public UIDatascroller getLocationDatascroller() {
                return locationDatascroller;
           }
      
           public void setLocationDatascroller(UIDatascroller locationDatascroller) {
                this.locationDatascroller = locationDatascroller;
           }
      
           public Locations getLocation() {
                return location;
           }
      
           public void setLocation(Locations location) {
                this.location = location;
           }
      }



      LocationPrinterFactory.java



      @Name("locationPrinterFactory")
      @Scope(ScopeType.EVENT)
      
      public class LocationPrinterFactory {
           
           @In(create = true)LocationPrinterService locationPrinterService;
           @In(create = true, required = false)LocationFactory locationFactory;
           @DataModel private List<Locationprinters> lstLocationPrinters;
           
           UIDatascroller locationPrinterDatascroller;
           
           @SuppressWarnings("unchecked")
           @Factory("lstLocationPrinters")
           public void listLocationPrinters() {
                Long locationPrinterCount;
                Vector locationPrintersVector = new Vector();
                
                int locationPrinterCurrentPageIndex;
                int locationPrintersPageFirstIndex;
                List listLocationPrintersSubSetRecords;
      
                
      *System.out.println("this.this.locationFactory.getLocation().getLocationName(): " + this.locationFactory.getLocation().getLocationName());
      System.out.println("this.locationFactory.getLocation.getLocationNumber: " + this.locationFactory.getLocation().getLocationNumber());*
      
                
                locationPrinterCount = locationPrinterService
                          .getlocationPrinterRowCount(this.locationFactory.getLocation().getLocationNumber());
      
                locationPrintersVector.setSize(locationPrinterCount.intValue());
      
                
                // This statement fetches the current pages first row index
                locationPrintersPageFirstIndex = (this.locationPrinterDatascroller.getPage() *
                          this.locationPrinterDatascroller.getDataTable().getRows()) - 
                          this.locationPrinterDatascroller.getDataTable().getRows();
                
                listLocationPrintersSubSetRecords = locationPrinterService
                          .getLocationPrinter(locationPrintersPageFirstIndex,
                                    this.locationFactory.getLocation().getLocationNumber());
      
                for (int index = 0; index < listLocationPrintersSubSetRecords.size(); index++) {
                     locationPrintersVector.set(locationPrintersPageFirstIndex + index,
                               listLocationPrintersSubSetRecords.get(index));
                }
      
                lstLocationPrinters = locationPrintersVector;
           }
      
           public List<Locationprinters> getLstLocationPrinters() {
                return lstLocationPrinters;
           }
      
           public void setLstLocationPrinters(List<Locationprinters> lstLocationPrinters) {
                this.lstLocationPrinters = lstLocationPrinters;
           }
      
           public UIDatascroller getLocationPrinterDatascroller() {
                return locationPrinterDatascroller;
           }
       
           public void setLocationPrinterDatascroller(
                     UIDatascroller locationPrinterDatascroller) {
                this.locationPrinterDatascroller = locationPrinterDatascroller;
           }
                
           public void nullLocationPrinter(){
                this.lstLocationPrinters = null;
           }     
      }



      I am trying to access the DataModelSelection in LocationPrinterFactory class but it always print me the very first value.


      Someone from this forum said that his/her problem was solved by updating jsf jar files. But I am still having that problem. So Please answer A.S.A.P

        • 1. Re: DataModel outjecting the very first value instead of selected one
          dan.j.allen

          I can tell you first of all that a @DataModel must be in PAGE, SESSION, or CONVERSATION (with a long-running conversation) scope. Otherwise, it will be refetched before the row is selected.

          • 2. Re: DataModel outjecting the very first value instead of selected one

            Hi!



            Dan Allen wrote on Jul 10, 2008 19:07:


            I can tell you first of all that a @DataModel must be in PAGE, SESSION, or CONVERSATION (with a long-running conversation) scope. Otherwise, it will be refetched before the row is selected.


            If I try to use (@DataModel(scope=SESSION) I get the exception: @DataModel scope must be ScopeType.UNSPECIFIED or ScopeType.PAGE (I am using Seam 2.0.2SP1), the cause is some code in org.jboss.seam.Component:


             private void checkDataModelScope(DataModel dataModel) {
                  ScopeType dataModelScope = dataModel.scope();
                  if ( dataModelScope!=PAGE && dataModelScope!=UNSPECIFIED )
                  {
                     throw new IllegalArgumentException("@DataModel scope must be ScopeType.UNSPECIFIED or ScopeType.PAGE: " + name);
                  }
               }
            



            Any hints on why SESSION and @DataModel no longer mix?