8 Replies Latest reply on Apr 27, 2009 7:31 AM by shantanu.u

    Proper use of keepAlive

    mglowacki

      Hi

      I was wondering how to use keepAlive in proper way, because I think I do this wrong. Let's say I am at the page where I can manage my account. I have a "account bean", which holds values like id, owner etc. On this page I have few ajax buttons to change those values. Every time I change something I read from this bean, which is request one with keepAlive. Works ok when I am at the page, but I thought my bean will loose values when I leave the page - it is not this way. When I go back to this page, the bean is already set with those old values.

      Could anyone explain me how to use properly then?

      Michal

        • 1. Re: Proper use of keepAlive

          The bean saved with keepAlive is stored in the state. So, if you return back with back button and then click and button, the state from this page is restored and the value of the bean should be restored as well.

          • 2. Re: Proper use of keepAlive
            balteo

            What is the difference between a "kept alive" bean and a session-scoped bean?

            Julien.

            • 3. Re: Proper use of keepAlive
              mglowacki

              keepAlive behaves like session bean, but exists only when you are at the page where this tag is defined. Session bean exists during all the session, so you can get data from it on many pages.

              • 4. Re: Proper use of keepAlive
                ilya_shaikovsky

                Also you may tell to keepAlive to store your beans only for Ajax requests.

                • 5. Re: Proper use of keepAlive
                  simoncigoj

                  I was wandering if the extensive use of keepAlive for ajax requests only could result in vast memory use on server and mybe memory space related problems...like out of memory etc... ?

                  And I would also like more about how keep alive works, how it stores data between requests?

                  • 6. Re: Proper use of keepAlive
                    dryan63

                    Is there away to get the current instance of a bean that has been marked with a4j:keepalive? I need to refresh a property on the marked bean from another bean.

                    • 7. Re: Proper use of keepAlive
                      ilya_shaikovsky

                      no difference between standard getting an instance of the bean and bean marked with keep alive.

                      it done with next code in our Song converter at richaces demo

                       ValueExpression beanExpression = expressionFactory
                       .createValueExpression(facesContext.getELContext(),
                       "#{library}", Library.class);
                      
                       Library library = (Library)beanExpression.getValue(facesContext.getELContext());
                       for (Song song : library.getSongsList()) {
                       if (song.getId() == id){
                       return song;
                       }
                      
                       }
                      
                      


                      • 8. Re: Proper use of keepAlive
                        shantanu.u

                        Sounds like keepAlive is the quivalent of t:saveState provided by tomahawk but synchronizes the state of the bean with ajax requests. Is this true ?