4 Replies Latest reply on Feb 14, 2011 11:34 AM by sv kap

    ajax rerender + request scoped beans

    sv kap Newbie



      I have parts of my site which I would like to update using Ajax. However, using reRender property would not work every time because sometimes I have request scoped beans. Is there a way to create some kind of centralized registry (session bean) which calls some js function (?) which makes the JSF component to update itself?

        • 1. ajax rerender + request scoped beans
          Ilya Sorokoumov Master

          Try to use a4j:keepAlive it should save your bean's state until a user is viewing the page.

          • 2. ajax rerender + request scoped beans
            sv kap Newbie

            I can use ViewScoped beans. Unfortunatelly this does not seem ti affect other parts of the site (initialized by other beans). That is why I wanted to have some certralized mechanism of Ajax regions updates. I guess that this is a common problem so probably there are some examples.


            For example I have 2 beans. First one generates some content and passes HtmlPanelGroup to the second one. The second bean generates another content using the passed HtmlPanelGroup. However, the second bean refreshes only its generated content and not the whole HtmlPanelGroup.

            • 3. ajax rerender + request scoped beans
              Nick Belaevski Master



              Can you please post some code to additionaly clarify the issue?

              • 4. Re: ajax rerender + request scoped beans
                sv kap Newbie

                Of course. This is not the exact code but I think that these are the important parts.




                // bean1

                private HtmlPanelGroup panelRoot = new HtmlPanelGroup();




                public void init() {

                // panelRoot initialization with some controls







                Bean2 bean2 = new Bean2();


                // init jsf controls of bean2


                // custom helper class

                JSFHelper.setBean("bean2", bean2);



                // bean2

                public void init() {


                    HtmlAjaxCommandButton button = new HtmlAjaxCommandButton();

                    button.setId("button_id_" + getRandom());





                    MethodExpression btnActionExpression = expressionFactory


                                    "#{bean2.buttonAction}", null,

                                    new Class[] { ActionEvent.class });

                    MethodExpressionActionListener listenerBtn = new MethodExpressionActionListener(







                // jsf

                <a4j:form id="form_id" ajaxSubmit="true" reRender="panelRoot_id" >

                    <h:panelGroup layout="block" id="panelRoot_id" style="width:580px;"

                        binding="#{bean1.panelRoot}" />



                Probably the problem is in my code.


                public void setPanelRootHtmlPanelGroup panelRoot) { } is called when button is clicked. However, I need to reload the content of panelRoot (currently loaded by public void init() {} method of bean1)