13 Replies Latest reply on Mar 18, 2009 4:59 AM by darmstadter

    when destroy the keepalived backing bean?

      I have some questions about the backing bean, when will the beans initialization and when will be destroy? e.g. i have a wizard, which implemented with modelpanel, after finished, the modalpanel is hidden, the bean is keep alived or destroy?

        • 1. Re: when destroy the keepalived backing bean?

          Another question. i have a wizard implemented with modelpanel, You can click the "next" button and go to next step, click "canel" hide the modalpanel. But aperiodic the getter method can not be called by click "next" button, but thenceforth click "canel" button, the getter method is called. This meas, that the keepalived bean is alive still. The reasons is that the ajax request is not be sent or ???

          
          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:rich="http://richfaces.org/rich"
           xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:dim="http://dimetis.de/jsf">
          
           <rich:panel styleClass="backgroundNet" style="height:275px">
           <a4j:outputPanel id="createTaskType">
           <h:panelGrid style="margin-left:60px; margin-top:10px;">
           <h:selectOneMenu style="width : 360px;" ajaxSingle="true"
           value="#{createTaskDialogBean.taskType}">
           <f:selectItems value="#{createTaskDialogBean.taskTypes}" />
           <a4j:support event="onchange"/>
           </h:selectOneMenu>
           <rich:separator height="1px" style="margin-top:7px;"/>
           </h:panelGrid>
           </a4j:outputPanel>
           </rich:panel>
          
           <h:panelGrid columns="3" style="margin-top:8px;vertical-align:bottom">
           <rich:spacer width="190px" />
          
           <a4j:commandButton action="#{createTaskDialogBean.refreshBean}" reRender="createTaskType"
           onclick="Richfaces.hideModalPanel('taskWizard');"
           value="Cancel" style="float:right; width:110px; height:30px;"/>
           <a4j:commandButton value="Next >>" ajaxSingle="true"
           style="float:right; width : 110px; height:30px;"
           styleClass="createTaskStep1Object"
           action="#{createTaskDialogBean.getTaskType}"
           onclick="startWait();"
           oncomplete="stopWait();"/>
           </h:panelGrid>
          </ui:composition>
          


          java code:
          
          /**
           * select item list for play type combbox
           */
           private List<SelectItem> t_list = null;
           public List<SelectItem> getTaskTypes()
           {
           if(t_list != null){
           return t_list;
           }
           t_list = new ArrayList<SelectItem>();
           SelectItem item = new SelectItem(Constants.IN, "Recording");
           SelectItem item2 = new SelectItem(Constants.OUT, "Playout");
          
           t_list.add(item);
           t_list.add(item2);
           setTaskType(Constants.IN);
           return t_list;
           }
          /**
           this getter method aperiodic can not be called by click next button, but called by click "canel " button
          **/
           public String getTaskType()
           {
           return taskType;
           }
          
           public void setTaskType(String taskType)
           {
           this.taskType = taskType;
           }
          


          • 2. Re: when destroy the keepalived backing bean?
            nbelaevski

            Hello,

            Just remove bean from request scope (e.g. in action method) and saved state will be cleared.

            • 3. Re: when destroy the keepalived backing bean?

              thank you very much for your reply. In my application i get aperiodic the problem, that the discontinuity of the richfaces component and backing bean. i.e i click the components, but don't get the reaction, the backing bean's methods are not called. The keepalived bean is already removed or die? If login again(new session is created), it works again. i have no ideas any more, can your gieve me any suggestions? Thanks again.

              • 4. Re: when destroy the keepalived backing bean?
                ilya_shaikovsky

                Your next button probably not works in modal because there is no form in your panel accorgin to the snippet you listed above. And cancel works just because you hide the panel before submit (in onclick) so your modal returned from the top of the DOM to its actual place. Check about form and modal panel limitations in our guide.

                • 5. Re: when destroy the keepalived backing bean?

                  Ilya, you are right. Perhaps i have done wrong.

                  i use customize facelets component
                  dialog.xhtml

                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                   xmlns:f="http://java.sun.com/jsf/core"
                   xmlns:h="http://java.sun.com/jsf/html"
                   xmlns:rich="http://richfaces.org/rich"
                   xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                   xmlns:ui="http://java.sun.com/jsf/facelets"
                   xmlns:c="http://java.sun.com/jstl/core">
                   <rich:modalPanel id="#{dialogId}" moveable ="true" >
                   <h:form>
                   <ui:insert/>
                   </h:from>
                  </rich:modalPanel>
                  </ui:composition>
                  


                  wizard.xhtml
                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                   xmlns:f="http://java.sun.com/jsf/core"
                   xmlns:h="http://java.sun.com/jsf/html"
                   xmlns:rich="http://richfaces.org/rich"
                   xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                   xmlns:ui="http://java.sun.com/jsf/facelets"
                   xmlns:dim="http://dimetis.de/jsf">
                   <dim:dialog dialogId="taskWizard" height="355" width="520"
                   dialogTitle="Create Task">
                   <a4j:keepAlive beanName="createTaskDialogBean" ajaxOnly="true"/>
                   <a4j:include viewId="/restricted/modal/createTaskWizard/createTaskStep1.xhtml" />
                   </dim:dialog>
                   </ui:composition>
                  


                  createTaskStep1.xhtml
                  
                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                   xmlns:f="http://java.sun.com/jsf/core"
                   xmlns:h="http://java.sun.com/jsf/html"
                   xmlns:rich="http://richfaces.org/rich"
                   xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                   xmlns:ui="http://java.sun.com/jsf/facelets"
                   xmlns:dim="http://dimetis.de/jsf">
                  
                   <rich:panel styleClass="backgroundNet" style="height:275px">
                   <a4j:outputPanel id="createTaskType">
                   <h:panelGrid style="margin-left:60px; margin-top:10px;">
                   <h:selectOneMenu style="width : 360px;" ajaxSingle="true"
                   value="#{createTaskDialogBean.taskType}">
                   <f:selectItems value="#{createTaskDialogBean.taskTypes}" />
                   <a4j:support event="onchange"/>
                   </h:selectOneMenu>
                   <rich:separator height="1px" style="margin-top:7px;"/>
                   </h:panelGrid>
                   </a4j:outputPanel>
                   </rich:panel>
                  
                   <h:panelGrid columns="3" style="margin-top:8px;vertical-align:bottom">
                   <rich:spacer width="190px" />
                  
                   <a4j:commandButton action="#{createTaskDialogBean.refreshBean}" reRender="createTaskType"
                   onclick="Richfaces.hideModalPanel('taskWizard');"
                   value="Cancel" style="float:right; width:110px; height:30px;"/>
                   <a4j:commandButton value="Next >>" ajaxSingle="true"
                   style="float:right; width : 110px; height:30px;"
                   styleClass="createTaskStep1Object"
                   action="#{createTaskDialogBean.getTaskType}"
                   onclick="startWait();"
                   oncomplete="stopWait();"/>
                   </h:panelGrid>
                  </ui:composition>
                  


                  I think that the createTaskStep1.xhtml is wrapped by h:form by the ui:insert, but the a4j:include is not equals the ui:insert, perhaps that is the reasons.

                  • 6. Re: when destroy the keepalived backing bean?

                    forgot, i should add h:from into wizard.xhtml?

                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:rich="http://richfaces.org/rich"
                     xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:dim="http://dimetis.de/jsf">
                     <dim:dialog
                     dialogId="taskWizard" height="355" width="520"
                     dialogTitle="Create Task">
                     <a4j:keepAlive beanName="createTaskDialogBean" ajaxOnly="true"/>
                     <h:form>
                     <a4j:include viewId="/restricted/modal/createTaskWizard/createTaskStep1.xhtml" />
                     </h:form>
                     </dim:dialog>
                     </ui:composition>
                    
                    
                    


                    • 7. Re: when destroy the keepalived backing bean?
                      ilya_shaikovsky

                      lets stop our discussion in one of the threads you opened ("Wizard problem" or there ):) because it's to hard to read them one by one. In general it could be really easier if you share you complete sample somewhere and provide the link. So we could investigate it on our side and post the answer there.

                      • 8. Re: when destroy the keepalived backing bean?

                        Sorry, i stop the topic of "Wizard problem". I have done after your suggest, that the commandButton wrapped with form, but the problem that the backing bean is broken down. i.e, click the button, no method is called. If the wizard is single, i think it works fine. But in my appliction there are others. e.g after confirm an error message dialog (modelpanel with output text and ok button), the wizard(modelpanel too) doesn't work any more, only The modelpanel of step1 is shown. There are conflicts between the beides? I don't konw that what is the cause, i want to konwing that when or who can cause the keepalived bean break down, or the commandButton don't send the ajax request ?

                        • 9. Re: when destroy the keepalived backing bean?
                          ilya_shaikovsky

                          Please create complete sample for us. Sorry but seems I can't get an answer using this simplified snippets and all the changes you trying descriptions..

                          The sample which works fine for me:
                          main page

                          <rich:modalPanel styleClass="wizard" showWhenRendered="true">
                           <f:facet name="header">
                           <h:outputText value="Using a4j:include for Wizard-like behaviour" />
                           </f:facet>
                           <h:form>
                           <a4j:include viewId="/richfaces/include/examples/wstep1.xhtml" />
                           </h:form>
                           </rich:modalPanel>

                          first
                          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                           xmlns:ui="http://java.sun.com/jsf/facelets"
                           xmlns:h="http://java.sun.com/jsf/html"
                           xmlns:f="http://java.sun.com/jsf/core"
                           xmlns:a4j="http://richfaces.org/a4j"
                           xmlns:rich="http://richfaces.org/rich">
                          
                           <div style="position:relative;height:140px">
                           <h:panelGrid rowClasses="s1row" columns="3" columnClasses="wfcol1,wfcol2,wfcol3">
                           <h:outputText value="First Name:" />
                           <h:inputText id="fn" value="#{profile.firstName}" label="First Name" required="true" />
                           <rich:message for="fn" />
                          
                           <h:outputText value="Last Name:" />
                           <h:inputText id="ln" value="#{profile.lastName}" label="Last Name" required="true" />
                           <rich:message for="ln" />
                          
                           <h:outputText value="Company:" />
                           <h:inputText id="comp" value="#{profile.company}" label="Company" required="true" />
                           <rich:message for="comp"/>
                           </h:panelGrid>
                           <div class="navPanel">
                           <a4j:commandButton style="float:right" action="next" value="Next &gt;&gt;"/>
                           </div>
                           </div>
                          </ui:composition>

                          second
                          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                           xmlns:ui="http://java.sun.com/jsf/facelets"
                           xmlns:h="http://java.sun.com/jsf/html"
                           xmlns:f="http://java.sun.com/jsf/core"
                           xmlns:a4j="http://richfaces.org/a4j"
                           xmlns:rich="http://richfaces.org/rich">
                          
                           <div style="position:relative;height:140px">
                           <h:panelGrid rowClasses="s1row" columns="3" columnClasses="wfcol1,wfcol2,wfcol3">
                           <h:outputText value="First Name:" />
                           <h:inputText id="fn" value="#{profile.firstName}" label="First Name" required="true" />
                           <rich:message for="fn" />
                          
                           <h:outputText value="Last Name:" />
                           <h:inputText id="ln" value="#{profile.lastName}" label="Last Name" required="true" />
                           <rich:message for="ln" />
                          
                           <h:outputText value="Company:" />
                           <h:inputText id="comp" value="#{profile.company}" label="Company" required="true" />
                           <rich:message for="comp"/>
                           </h:panelGrid>
                           <div class="navPanel">
                           <a4j:commandButton style="float:right" action="next" value="Next &gt;&gt;"/>
                           </div>
                           </div>
                          </ui:composition>


                          and so one. taken from demo and include wrapped to modal.

                          • 10. Re: when destroy the keepalived backing bean?
                            ilya_shaikovsky

                            and

                             <a4j:keepAlive beanName="profile" />
                            


                            at main page.

                            • 11. Re: when destroy the keepalived backing bean?

                              Sorry, i must continue the topic. I have tried to implement the wizard after the demo. But i got always the problem, that the wizard is die,
                              i.e the navigation' button doesn't react. No backing bean method will be called. I used the push and poll in my application.
                              I thinks, that there are 2 possibilities:
                              1. the keep alived backing bean is die.
                              2. the navigation's button can not sent the request from modelPanel.
                              My question is that the aboved possibilities can be recaused by push or poll? i.e push or poll can destroy the wizard(implemented with modalPanel)?
                              Without the poll and push, the problem occurs infrequently( I can't say, there is not any more).
                              The problem is very difficult to reproduce, it occurs unexpectly.
                              customize tag wizard: wizard.xhtml

                              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                               xmlns:f="http://java.sun.com/jsf/core"
                               xmlns:h="http://java.sun.com/jsf/html"
                               xmlns:rich="http://richfaces.org/rich"
                               xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                               xmlns:ui="http://java.sun.com/jsf/facelets"
                               xmlns:c="http://java.sun.com/jstl/core">
                               <rich:modalPanel id="#{wizardId}" moveable ="true" resizeable="false"
                               height="#{height}" width="#{width}" zindex="2000" onshow="#{onshow};initDialog('#{dialogId}');">
                               <f:facet name="header">
                               <h:outputText value="#{dialogTitle}" />
                               </f:facet>
                               <script>
                              
                              
                               </script>
                               <!-- The closeable attribute is optional. Set it to true if it is missing. -->
                               <c:if test="${empty closeable}">
                               <c:set var="closeable" value="${true}" />
                               </c:if>
                              
                               <c:if test="${closeable}">
                               <f:facet name="controls">
                               <h:commandButton image="/images/close.png" style="cursor:pointer" disabled="#{disable}"
                               oncomplete="document.onkeydown = null;"
                               onclick="closeDlg#{wizardId}();"/>
                               </f:facet>
                               </c:if>
                               <h:form>
                               <a4j:include viewId="#{includeViewId}"/>
                               </h:form>
                               </rich:modalPanel>
                               </ui:composition>
                              


                              createTaskWizard.xhtml
                              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                               xmlns:f="http://java.sun.com/jsf/core"
                               xmlns:h="http://java.sun.com/jsf/html"
                               xmlns:rich="http://richfaces.org/rich"
                               xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                               xmlns:ui="http://java.sun.com/jsf/facelets"
                               xmlns:dim="http://dimetis.de/jsf">
                               <a4j:keepAlive beanName="createTaskDialogBean" />
                               <dim:wizard wizardId="taskWizard" height="355" width="520" dialogTitle="Create Task"
                               includeViewId="/restricted/modal/createTaskWizard/createTaskStep1.xhtml">
                               </dim:wizard>
                               </ui:composition>
                              


                              step1.xhtml
                              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                               xmlns:f="http://java.sun.com/jsf/core"
                               xmlns:h="http://java.sun.com/jsf/html"
                               xmlns:rich="http://richfaces.org/rich"
                               xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                               xmlns:ui="http://java.sun.com/jsf/facelets"
                               xmlns:dim="http://dimetis.de/jsf">
                              
                               <rich:panel styleClass="backgroundNet" style="height:275px">
                               <h:panelGrid style="margin-left:60px; margin-top:10px;">
                               <h:selectOneMenu style="width : 360px;" ajaxSingle="true"
                               value="#{createTaskDialogBean.taskType}">
                               <f:selectItems value="#{createTaskDialogBean.taskTypes}" />
                               </h:selectOneMenu>
                               <rich:separator height="1px" style="margin-top:7px;"/>
                               </h:panelGrid>
                               </rich:panel>
                              
                               <h:panelGrid columns="3" style="margin-top:8px;vertical-align:bottom">
                               <rich:spacer width="190px" />
                              
                               <a4j:commandButton action="#{createTaskDialogBean.refreshBean}" reRender="createTaskType"
                               onclick="Richfaces.hideModalPanel('taskWizard');"
                               value="Cancel" style="float:right; width:110px; height:30px;"/>
                               <a4j:commandButton value="Next &gt;&gt;"
                               style="float:right; width : 110px; height:30px;"
                               styleClass="createTaskStep1Object"
                               action="#{createTaskDialogBean.getTaskType}"
                               onclick="startWait();"
                               oncomplete="stopWait();"/>
                               </h:panelGrid>
                               <script>
                               initCreateTaskStep1Object();
                               </script>
                              
                               <a4j:jsFunction name="closeDlgtaskWizard"
                               action="#{createTaskDialogBean.refreshBean}"
                               reRender="createTaskType"
                               oncomplete="Richfaces.hideModalPanel('taskWizard');" />
                              </ui:composition>
                              


                              click the next button, navigation to step2 etc. Click the Cancel button, the backing bean will be refreshed, it used to clear the inputText in wizard.

                              refreshbean method
                              
                               public String refreshBean()
                               {
                               Field fields[] = CreateTaskDialogBean.class.getDeclaredFields();
                               try
                               {
                               for(Field field: fields)
                               {
                               Class<?> type = field.getType();
                               if(type.getName().equalsIgnoreCase("boolean"))
                               {
                               field.set(this, false);
                              
                               }else
                               {
                               field.set(this, null);
                               }
                               }
                               } catch (IllegalArgumentException e)
                               {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                               } catch (IllegalAccessException e)
                               {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                               }
                               setTaskType(Constants.IN);
                              // recordingBean = new RecordingTaskBean();
                              // playoutBean = new PlayoutTaskBean();
                               return Constants.RESET;
                               }
                              


                              the end of wizard, hide the modalpanel and refresh bean again, maybe this is a stupid method, but i dont know how to create the backing bean again.

                              • 12. Re: when destroy the keepalived backing bean?

                                if login again, new session is created, the wizard woks again, i.e. the Application on the server is ok, the problem is occurs only on the client site.
                                the dom tree goes wrong?

                                • 13. Re: when destroy the keepalived backing bean?

                                  i have anothers wizard, they can work, only the wizard got always problem.

                                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                                   xmlns:f="http://java.sun.com/jsf/core"
                                   xmlns:h="http://java.sun.com/jsf/html"
                                   xmlns:rich="http://richfaces.org/rich"
                                   xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                                   xmlns:ui="http://java.sun.com/jsf/facelets">
                                   <!-- disabled="#{layoutBean.disabledCreateTask}" -->
                                   <rich:toolBar width="1024px" id="mainToolBarId"
                                   style="margin-left:auto; margin-right:auto;"
                                   itemSeparator="line">
                                   <rich:toolBarGroup>
                                   <a4j:commandButton title="Create Task" image="#{layoutBean.createTaskIcon}" ajaxSingle="true"
                                   onclick="Richfaces.showModalPanel('taskWizard');initCreateTaskStep1Object();"/>
                                   </rich:toolBarGroup>
                                  </ui:composition>
                                  


                                  click the button, then start the wizard. the toolbar is wired in a4j:region.