2 Replies Latest reply on May 1, 2012 4:25 PM by rohit1183

    how to put lists in the session or application scope

    bking007

      I tried to use Session Scope on the component, on @Factory and also on @Out but nothing seems to work. I am populating a list from the database values and would like to have it available through out the application or session - to avoid multiple queries. But, every time I access this list in JSF page, a db call is made because list value is null.


      @Factory(value="list1",scope=ScopeType.SESSION)     
           public void getList1() {     
                list1 = return em.createQuery(queryStr).getResultList();           
           }



        • 1. Re: how to put lists in the session or application scope
          bking007

          Got it:



          @Out(scope=ScopeType.SESSION, required=false)
              List<SelectItem> list1;
          
          @Factory(value="list1")     
               public void getList1() {     
                    list1 = return em.createQuery(queryStr).getResultList();           
               }
          
          
                   
          <h:selectOneMenu value="#{val1}">
               <f:selectItem itemLabel="-- Select --" itemValue="#{null}"/>        
               <f:selectItems value="#{list1}"/>                     
          </h:selectOneMenu>
          
          





          • 2. Re: how to put lists in the session or application scope
            rohit1183

            I am facing an issue with any scope greater than EVENT.

            I had this

             

            @Factory(value="allDistinctDwellTypes", scope=ScopeType.EVENT)

            public List<DwellType> getDistinctDwellTypes(){

                      //code to get the list

            }

             

            On my UI I had this:

             

            <h:selectOneListbox id="dwellType" size="1" value="#{allDevelopmentsAction.developmentSearch.dwellType}" required="false">

                   <s:selectItems value="#{allDistinctDwellTypes}"

                        label="#{dwellType.description}" var="dwellType"  noSelectionLabel="Choose" />

                   <s:convertEntity />

            </h:selectOneListbox>

             

            With EVENT scope every thing works fine. However if I change the scope to say APPLICATION, then the list box is populated fine with the options but as and when I choose an option and submit the page, I get an error saying value is required. This does not occur with EVENT scope.

             

            I have also tried your suggestion by using @Factory method which returns void and then using @out and setting the scope of the variable as APPLICATION. But same thing happens.