9 Replies Latest reply on Aug 20, 2007 5:43 PM by pmuir

    Ajax4JSF and s:selectItems

    pdhaigh

      I'm having some difficulty getting an a4j action trigger a re-evaluation of the value in a h:selectOneMenu using s:selectItems.

      Is there anything wrong with the following?

      <h:form id="mainForm">
       <f:facet name="afterInvalidField">
       <h:panelGroup><br/><s:message/></h:panelGroup>
       </f:facet>
       <f:facet name="aroundInvalidField">
       <s:span styleClass="error"/>
       </f:facet>
       <s:validateAll>
       <h:panelGrid columns="2" columnClasses="object,value">
       <h:outputText value="Destination: "/>
       <h:panelGroup>
       <h:selectOneMenu value="#{pressArticle.destination}" >
       <s:selectItems value="#{destinations.resultList}"
       var="destination"
       label="#{destination.name}"
       noSelectionLabel="Please select"/>
       <s:convertEntity/>
       <a4j:support ajaxSingle="true" event="onchange" reRender="mainForm,mainForm:dothis" actionListener="#{pressArticleManager.setDestination}"/>
       </h:selectOneMenu>
       <h:commandButton styleClass="button" style="margin:0px 0px 0px 5px; padding: 0px" actionListener="#{pressArticleManager.setDestination}" value="Set destination"/>
       </h:panelGroup>
       <h:outputText value="Region: "/>
       <h:panelGroup>
       <s:decorate id="dothis">
       <h:selectOneMenu value="#{pressArticle.region}" >
       <s:selectItems value="#{regions.resultList}"
       var="region"
       label="#{region.name}"
       noSelectionLabel="Please select"/>
       <s:convertEntity/>
       </h:selectOneMenu>
       </s:decorate>
       <h:outputText value="Region: #{pressArticle.region.name}" rendered="#{pressArticle.region!=null}"/>
       </h:panelGroup>
       </h:panelGrid>
       </s:validateAll>
      </h:form>


      The a4j tag does correctly call my backing mething, which logs the change to pressArticle.region, but the drop down value does not change. Subsequently calling a standard JSF action back to the same view-id does change the drop down value..

      cheers

      p

        • 1. Re: Ajax4JSF and s:selectItems
          damianharvey

          reRender="dothis" should be all that is required.

          Cheers,

          Damian.

          • 2. Re: Ajax4JSF and s:selectItems
            pdhaigh

            no joy...

            it is re-rendering this part correctly:

            <h:outputText value="Region: #{pressArticle.region.name}" rendered="#{pressArticle.region!=null}"/>


            so the problem isn't that it's not rerendered the section, but that it's not re-evaluating the value set in the drop down

            • 3. Re: Ajax4JSF and s:selectItems

              agreed, all you should be rerendering is "dothis"

              Here is an example that I know works from my app

              <h:selectOneMenu id="departmentCode_select" value="#{departmentCode}">
               <s:selectItems label="#{deptCode.department.departmentNumber} - #{deptCode.department.departmentName}"
               value="#{departmentCodeList}"
               noSelectionLabel="(None)" var="deptCode"/>
               <s:convertEntity/>
               <a4j:support event="onchange"
               actionListener="#{serviceRequestManager.fillDepartmentSectionList}"
               ajaxSingle="true" reRender="departmentSection_select"/>
               </h:selectOneMenu>
               <h:outputLabel for="departmentSection_select" value="#{messages['AssignmentList.departmentSection']}"/>
               <h:selectOneMenu id="departmentSection_select" value="#{departmentSection}">
               <s:selectItems label="#{deptSection.departmentSectionName}"
               value="#{departmentSectionList}"
               noSelectionLabel="(None)" var="deptSection"/>
               <s:convertEntity/>
               </h:selectOneMenu>
              


              • 4. Re: Ajax4JSF and s:selectItems
                pdhaigh

                Hi guys,

                yes, i had tried that too. Here's a stripped down example:

                <h:form>
                 <f:facet name="afterInvalidField">
                 <h:panelGroup><br/><s:message/></h:panelGroup>
                 </f:facet>
                 <f:facet name="aroundInvalidField">
                 <s:span styleClass="error"/>
                 </f:facet>
                <s:validateAll>
                 <h:panelGrid columns="2" columnClasses="object,value">
                 <h:outputText value="Destination: "/>
                 <s:decorate>
                 <h:selectOneMenu value="#{feedback.destination}" required="true" >
                 <s:selectItems value="#{destinations.resultList}"
                 var="destination"
                 label="#{destination.name}"
                 noSelectionLabel="Please select"/>
                 <s:convertEntity/>
                 <a4j:support ajaxSingle="true" event="onchange"
                 actionListener="#{feedbackManager.setDestination}" reRender="regionmenu"/>
                 </h:selectOneMenu>
                 </s:decorate>
                 <s:decorate>
                 <h:selectOneMenu id="regionmenu" value="#{feedback.region}" required="true"
                 disabled="#{feedback.destination!=null}" >
                 <s:selectItems value="#{regions.resultList}"
                 var="region"
                 label="#{region.name}"
                 noSelectionLabel="Please select"/>
                 <s:convertEntity/>
                 </h:selectOneMenu>
                 </s:decorate>
                 </h:panelGrid>
                 </s:validateAll>
                </h:form>
                


                does not work. However, changing the disabled parameter to

                disabled="#{feedback.destination==null}"


                makes it work (although of course this isn't much help)

                Removing the disabled statement completely does not work.

                cheers

                p

                • 5. Re: Ajax4JSF and s:selectItems
                  damianharvey

                  How does the regions bean get the value of feedback.destination? Do you inject feedbackManager?

                  • 6. Re: Ajax4JSF and s:selectItems
                    pdhaigh

                    not sure I understand your question...? regions is an entityquery defined in components.xml

                    <fwk:entity-query name="regions">
                     <fwk:ejbql>from Region</fwk:ejbql>
                     <fwk:order>name</fwk:order>
                     </fwk:entity-query>
                    


                    Feedback is a model class that has references to a region (instance of Region model class) and destination (instance of Destination model class).

                    • 7. Re: Ajax4JSF and s:selectItems
                      damianharvey

                      I misunderstood what you were trying to do. You aren't trying to re-query regions you are only trying to enable the regions drop-down and (stating the obvious) your problem is that destination in the feedback bean is always null.

                      Is the feedBack bean scoped so that it is maintained over the request? Try scoping it to a conversation and adding a begin-conversation to the page.xml. Also ensure that if you are setting the value of destination in feedbackManager that you are outjecting it.

                      Cheers,

                      Damian.

                      • 8. Re: Ajax4JSF and s:selectItems
                        pdhaigh

                        hi,

                        actually, the destination on the feedback bean is being correctly set, as indeed is the region (if I add in some outputText fields and get them to be re-rendered it shows the correct values).

                        The problem is just that the selected value in the drop down is not being updated on re-render. I have used this functionality before with no problem, (although that was with textual value in the drop down, rather than seam converted entities) so I'm not sure what exactly is going wrong.

                        cheers


                        phil

                        • 9. Re: Ajax4JSF and s:selectItems
                          pmuir

                          You should post on the ajax4jsf forum as well, as I don't *think* this is related to Seam.