5 Replies Latest reply on Jan 25, 2010 6:15 AM by Cvetelin Andreev

    aj4:region and immediate

    Cvetelin Andreev Newbie

      Hello and thanks for the help

       

      I'm using richfaces 3.3.2, spring (with webflow), facelets, etc,

       

      I have a page with 2 comboboxes. I need to perform action when the second one is changed. I need the value of the second one in an acton listener, then I need the value of the first one in the model. I have the following code:

       

                  <a4j:region>
                      <h:selectOneMenu id="insurer" required="true" value="#{protocol.insurerId}">
                          <f:selectItems value="#{insurers.items}"/>
                      </h:selectOneMenu>

       

                      <h:selectOneMenu id="insurer_agency" required="true" value="#{protocol.insurerAgencyId}">
                          <f:selectItems value="#{agencies.items}"/>
                          <f:selectItem itemLabel="#{msg.global_new_entry}" itemValue="-1"  />
                          <a4j:support event="onchange"
                              action="#{agencies.newAction}" reRender="#{flowRenderFragments}"
                              actionListener="#{agencies.newActionListener}" />
                      </h:selectOneMenu>
                   </a4j:region>

       

      I know that if I need the value if the second selectOneMenu in the action listener #{agencies.newActionListener} I need to put immediate="true" on the a4j:support tag, but if I do this, I'll not get the value of the first combo in the model (I'm using this value in the webflow xml). If I put immediate="true" on the second selectOneMenu the model is updated and I don't get its value in the action listener. I tried to remove the region and to put process="insurer,insurer_agency" on the a4j:support tag, but then the validaton of the other fields in the form occures and I cannot submit.

        • 1. Re: aj4:region and immediate
          Ilya Shaikovsky Master
          sorry, but seems case not fully clear. Your current code looks fine and both selects should be processed just as you need with it.. Whats wrong with it that you want to use immediate?
          • 2. Re: aj4:region and immediate
            Cvetelin Andreev Newbie

            this is my implementation of the action listener

             

                public void newActionListener(ActionEvent event) {
                    HtmlSelectOneMenu parent = (HtmlSelectOneMenu) event.getComponent().getParent();
                    this.value = (String) parent.getSubmittedValue();
                    if (null == value || false == value.equals(NEW_ENTITY_ITEM_VALUE)) {
                        throw new AbortProcessingException();
                    }
                }

             

            the problem is that there is no value in the HtmlSelectOneMenu component. If I put immediate="true" on the a4j:status then I get the value in the HtmlSelectOneMenu component.

             

            I need to have the value in the action listener, because it is related to my architecture. I'm trying to make a "New Entity" option in the combo box which opens a modal dialog to create new option on demand. It works fine but now I need the value of another component to create the new option in the select.

            • 3. Re: aj4:region and immediate
              Ilya Shaikovsky Master

              B.t.w. How about to move this logic to select valueChangeListener? It will looks more accurate + you will just get values from event.

              • 4. Re: aj4:region and immediate
                Nick Belaevski Master
                There's a problem in your code. "submittedValue" attribute is erased after successful conversion, refer to UIInput documentation and code.
                • 5. Re: aj4:region and immediate
                  Cvetelin Andreev Newbie

                  Works fine with the value change listener. It is invoked before the action of the a4j:support tag, which is what I need.

                   

                  Thanks.

                   

                  The reason why I don't get the submited value in my action listener without specifying immediate="true" is that the immediate attribute causes the value to be populated in the component model before the action listener is invoked.