5 Replies Latest reply on Jun 3, 2008 6:05 AM by sambolino

    a4j support and dynamically generated component

    sambolino

      greetings!

      i have h:selectOneMenu, and h:panelGrid. onchange on the menu should trigger grid reRender.

      The grid is created dynamically, so actually menu should set its new entity value to a bean1, then ask for grid rerender, and grid's bean2 knows how to access bean1, and according to the chosen entity generate the grid (the middle-tier part's accuracy shouldn't be doubted because when i add a commandbutton, and attach an action which rerenders whole page everything works fine).

      so here's the code that doesn't work

      <h:form>
       <rich:panel>
       <f:facet name="header">
       <h:outputText value="Add new address" />
       </f:facet>
      
       <h:selectOneMenu id="addressTypesSelectOne"
       styleClass="selectOneMenu"
       value="${addressService.spatialAddressType}" onchange="submit()">
      
       <s:selectItems value="#{addressBinder.allSpatialAddressTypes}"
       var="result" label="#{result.name}"
       noSelectionLabel="#{messages['select']}" />
      
       <s:convertEntity />
       <a4j:support event="onchange" reRender="pnlGrid" ajaxSingle="true" action="#{addressService.resetAllUnits}" />
       </h:selectOneMenu>
       <br />
      
       <h:panelGrid id="pnlGrid" columns="1"
       binding="#{addressLinker.generatedPanel}"></h:panelGrid>
       <div style="clear: both" />
       </rich:panel>
       </h:form>


      thanks!

        • 1. Re: a4j support and dynamically generated component

          you have an onchange="submit()" for selectOneMenu that produces non-Ajax request. At the same time, you attach a4j:support on the same event. This will cause double (ajax and non-ajax) requests with unpredictable result.

          • 2. Re: a4j support and dynamically generated component
            sambolino

            i've changed code a bit according to richfaces demo

            <a4j:outputPanel layout="block">
             <a4j:outputPanel ajaxRendered="true">
             <h:messages globalOnly="true" styleClass="message" />
             </a4j:outputPanel>
            
             <a4j:outputPanel layout="block">
             <h:form>
             <f:facet name="header">
             <h:outputText value="Add new address" />
             </f:facet>
             <h:selectOneMenu id="addressTypesSelectOne"
             styleClass="selectOneMenu"
             value="${addressService.spatialAddressType}">
             <s:selectItems value="#{addressBinder.allSpatialAddressTypes}"
             var="result" label="#{result.name}"
             noSelectionLabel="#{messages['select']}" />
             <s:convertEntity />
             <a4j:support event="onchange" reRender="out1"
             action="#{addressService.resetAllUnits}"></a4j:support>
             </h:selectOneMenu>
             <h:commandButton action="selectAddressType"
             value="Select address type" />
             </h:form>
             </a4j:outputPanel>
            
             <a4j:outputPanel id="out1" >
             <h:panelGrid columns="1" binding="#{addressLinker.generatedPanel}" ></h:panelGrid>
             </a4j:outputPanel>
            
             </a4j:outputPanel>


            now, rerender happens, selectOneMenu sets value to the bean and a4j:support action is called. still, binding on the panelGrid is only called when i manually hit the button or refresh the page. i couldn't find an attribute which would tell "bind on every request" or so.

            thanks

            • 3. Re: a4j support and dynamically generated component
              ilya_shaikovsky

              addressLinker - should be request scoped.

              • 4. Re: a4j support and dynamically generated component
                sambolino

                i'm using seam:

                @Stateless
                @Scope(ScopeType.STATELESS)
                @Name("addressLinker")

                i've also tried to put it as a managed bean (but still keeping seam annotations in the code)

                <managed-bean-name>addressLinker</managed-bean-name>
                <managed-bean-class>com.advsofttech.registeroffice.logic.AddressLinkerBean</managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>


                doesn't work this way either

                • 5. Re: a4j support and dynamically generated component
                  sambolino

                  if i put static content inside "out1" a4j:outputpanel it works. seems like ajax doesn't work with component which is dynamically bound. is there a workaround more elegant than refreshing the UIViewRoot (because defining navigation rule that rerenders the whole page results in unexpected behavior).