6 Replies Latest reply on Jun 25, 2008 9:26 AM by ali1983

    factory method with defined scope outjected a value

    nasir.imtiaz

      hi guys.


      I have this SFSB:


      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("SalesPersonContacts")
      public class SalesPersonContactsBean implements SalesPersonContacts {
      
              @DataModel
              private List<Contacts> lstContacts;
      
              @DataModelSelection("lstContacts")
              @Out(required=false)
              Contacts contact;
      
              @Factory("lstContacts")
              public void getContacts() {
                      lstContacts = some query thru database...
              }
      
              ...
      



      The above code works fine, but the problem i have is that the 'lstContacts' list only fills up the first time.
      After going thru a number of resources i found that @Factory only calls up once when the given list is null. But what if i want to call it on each request.
      Cause im retrieving paginated data thru db and for that i've bound a datascroller which would tell me the current page clicked, so i could retrieve my data accordingly on each request.


      And, if i try to set a scope for the factory as follows:



             @Factory(value="lstContacts", scope=ScopeType.EVENT)
              public void getContacts() {
                      lstContacts = some query thru database...
              }
      



      it starts throwing java.lang.IllegalArgumentException: factory method with defined scope outjected a value: lstContacts


      This poor guy had the same problem:
      http://lists.jboss.org/pipermail/jboss-user/2007-February/038874.html


      Gavin, if ur out there and reading this, help us out PLEASE!


      B.T.W. Following is my work enviorment:



      1. JDK 1.6.0 02,


      2. JBoss 4.2.2.GA,


      3. JBoss Seam 2.0.1.GA,


      4. RichFaces 3.2.1.GA

        • 1. Re: factory method with defined scope outjected a value
          hasan_muhstaq

          Don't annotate ur Factory method, annotate the varriable thats used for outjection



           
          // annotate with event / Page
          @DataModel(scope = ScopeType.EVENT)
          private List<Contacts> lstContacts;
          
          @Factory(value="lstContacts")
          public void getContacts() {
             lstContacts = some query thru database...
          }
          



          • 2. Re: factory method with defined scope outjected a value
            nasir.imtiaz

            Thanks hasan for your reply. But i tried your suggestions and unfortunately they didnt work.


            When i tried to set scope of @DataModel to EVENT it threw

            Caused by: java.lang.IllegalArgumentException: @DataModel scope must be ScopeType.UNSPECIFIED or ScopeType.PAGE: SalesPersonContacts


            and when i set the scope to PAGE it shows me the first page of datascroller but when i click the 2nd page it throws exception
            java.lang.IllegalStateException: No page context active


            Any help would be great.

            • 3. Re: factory method with defined scope outjected a value
              gjeudy

              Can you explain why you try to use EVENT scope ? I  didnt have to use it in my Seam app. It seems like many people don't know that using CONVERSATION scope may do just as well even if you don't promote your conversation to a long-running one.


              So why declare SalesPersonContact bean in SESSION scope ? If you declare it in CONVERSATION scope your @DataModel will implicitely be in CONVERSATION scope. Then all that you have left is control your conversation boundaries. If you dont the implicit CONVERSATION lasts for one full request cycle.

              • 4. Re: factory method with defined scope outjected a value
                newion

                If you want factory method to refresh your data (lstContacts in your case) set the data null


                lstContacts = null


                • 5. Re: factory method with defined scope outjected a value
                  dan.j.allen

                  Well said. The problem here is that you are putting your SFSB in session. If you are using Seam, then you really don't need to be using session scope. If you want to use session and have the factory method called again, what you want to do is nullify the list in an action method and on the next view it will be fetched again.


                  Setting the @DataModel scope to PAGE should work too. I'm not sure I understand why you are getting page context is not active.

                  • 6. Re: factory method with defined scope outjected a value
                    ali1983

                    hasan mushtaq wrote on Jun 13, 2008 12:37:


                    Don't annotate ur Factory method, annotate the varriable thats used for outjection


                     
                    // annotate with event / Page
                    @DataModel(scope = ScopeType.EVENT)
                    private List<Contacts> lstContacts;
                    
                    @Factory(value="lstContacts")
                    public void getContacts() {
                       lstContacts = some query thru database...
                    }
                    






                    Hello mr Hassan Mushtaq.


                      I am having the problem in binding the UIDatascroller with UI. everything is working fine. But the problem is I am unable to set the page of datascroller through my backing bean.


                    I have two classes one with Event scope and other with Session scope


                    FactoryClass with Event scope


                    @Name("factoryClass")
                    @Scope(ScopeType.EVENT)
                    public class FactoryClass {
                            
                            
                            
                            @In(create = true) PrinterScansService printerScansService;
                            @In(create = true) GroupService groupService;
                            @In(create = true) PCUserSession pcUserSession;
                            @In(create = true) UserService userService;
                            @In(create = true) SalesPersonDashboardBean SalesPersonDashboard; 
                            
                            @SuppressWarnings("unused")
                            @DataModel
                            private List<Printerscans> lstPrinterscans;
                            
                            @SuppressWarnings("unchecked")
                            @Factory(value = "lstPrinterscans")
                            public void listPrinterscans() {
                                            
                                    System.out.println("----- OrderField ----- "+ SalesPersonDashboard.getOrderField());
                                    List listSubSetRecords;
                                    List lstGroups;
                                    Set setSPsOfGroups;
                                    int pageFirstIndex;
                                    Long count;
                                    
                                    
                                    
                                    lstGroups = groupService.getGroupsForSP(pcUserSession.getUserNumber());
                    
                                    setSPsOfGroups = userService.getSPsFromSalesGroups(lstGroups);
                    
                                    count = printerScansService.getPrinterscanRowCount(userService
                                                    .getCSVUserNumber(setSPsOfGroups));
                    
                                    Vector vector = new Vector();
                    
                                    vector.setSize(count.intValue());
                    
                                    pageFirstIndex = (SalesPersonDashboard.getDashboardDataScroller().getPage() * SalesPersonDashboard.getDashboardDataScroller()
                                                    .getDataTable().getRows())
                                                    - SalesPersonDashboard.getDashboardDataScroller().getDataTable().getRows();
                    
                                    listSubSetRecords = printerScansService.getPrinterscansOfSPs(
                                                    userService.getCSVUserNumber(setSPsOfGroups), SalesPersonDashboard.getOrderField(),
                                                    SalesPersonDashboard.isAscendingOrder(), pageFirstIndex);
                                    
                                    
                                    for (int index = 0; index < listSubSetRecords.size(); index++) {
                                            vector.set(pageFirstIndex + index, listSubSetRecords.get(index));
                                    }
                    
                                    lstPrinterscans = vector;
                            }
                            
                            public void nullList(){
                                    this.lstPrinterscans = null;
                            }




                    SalesPersonDashboardBean with SESSION scope


                    @Scope(ScopeType.SESSION)
                    @Name("SalesPersonDashboard")
                    
                    public class SalesPersonDashboardBean {
                            
                            @In(create = true,required=false) FactoryClass factoryClass;
                            public boolean ascendingOrder;  
                            public String orderField;
                            @Out(value="dashboardDataScroller")
                            UIDatascroller dashboardDataScroller;
                            
                    
                            public void sortAction(String field) {
                                    
                                    this.ascendingOrder = !this.ascendingOrder;
                                    this.orderField = field;
                                    
                    //              this.dashboardDataScroller.setPage(1);
                    //              System.out.println("DataScroller Page: " + factoryClass.dashboardDataScroller.getPage());
                                    factoryClass.listPrinterscans();
                            }
                            
                            public boolean isAscendingOrder() {
                                    return ascendingOrder;
                            }
                    
                            public void setAscendingOrder(boolean ascendingOrder) {
                                    this.ascendingOrder = ascendingOrder;
                            }
                    
                            public String getOrderField() {
                                    return orderField;
                            }
                    
                            public void setOrderField(String orderField) {
                                    this.orderField = orderField;
                            }
                    
                            public UIDatascroller getDashboardDataScroller() {
                                    return dashboardDataScroller;
                            }
                    
                            public void setDashboardDataScroller(UIDatascroller dashboardDataScroller) {
                                    this.dashboardDataScroller = dashboardDataScroller;
                            }



                    UI in which I am doing the binding


                    <rich:datascroller id="printerScanScroller" align="center"
                                   selectedStyleClass="activeLinksScroller"
                                   tableStyleClass="tablefooter"
                                   inactiveStyleClass="inActiveLinksScroller" for="sp-printerscans"
                                   maxPages="15" style="tablefooter" boundaryControls="hide"
                                   action="#{factoryClass.nullList}"
                                   binding="#{SalesPersonDashboard.dashboardDataScroller}"
                                   fastControls="hide"
                                   renderIfSinglePage="false">
                                   <f:facet name="previous">
                                        <h:graphicImage value="../common/image/arrow-left.gif" height="14"></h:graphicImage>
                                   </f:facet>
                                   <f:facet name="next">
                                        <h:graphicImage value="../common/image/arrow-right.gif"></h:graphicImage>
                                   </f:facet>
                                   <f:facet name="previous_disabled">
                                        <h:graphicImage value="../common/image/arrow-left.gif"></h:graphicImage>
                                   </f:facet>
                                   <f:facet name="next_disabled">
                                        <h:graphicImage value="../common/image/arrow-right.gif"></h:graphicImage>
                                   </f:facet>
                    
                              </rich:datascroller>




                    In this scenario CONVERSATION scope is not working. The thing is that I want to reset my datascroller to page 1. And I am trying to do this in  SalesPersonDashboard.sortAction() method. But it is not working. Other binding properties are working fine of UIdatascroller.


                    One more thing If u don't mind can I have your personal email address and phone number for help in further problems regarding seam.


                    Bye
                    Muhammad Ali