5 Replies Latest reply on Nov 5, 2008 2:14 PM by Val Sw

    urgent help required, a4j onchange event

    Val Sw Expert

      As soon as I change 1st dropdown Item, particular value is immediately updated in database before even clicking update button.

      example if existing value in Item dropdown is A abd I select B, immediatedly it is updated in database...

      xhtml file:-

      xmlns:a="http://richfaces.org/a4j"
      ...
      <a:region renderRegionOnly="false">
      <s:decorate id="quantationDec" template="layout/edit.xhtml">
      <ui:define name="label">Item : </ui:define>
      <h:selectOneMenu value="#{itemList.instance.item}" required="true"
      styleClass="message">
      <f:selectItem itemValue="A" itemLabel="A"/>
      <f:selectItem itemValue="B" itemLabel="B"/>
      <f:selectItem itemValue="C" itemLabel="C"/>
      <a:support event="onchange" reRender="panel"/>
      </h:selectOneMenu>
      </s:decorate>
      </a:region>

      <rich:panel id="panel">
      <h:selectOneMenu name="itemvalue1" id="itemvalue1" value="#{bean.value}"
      rendered="#{empty itemList.instance.item}"
      styleClass="message">
      <f:selectItem itemValue="A1" itemLabel="A1"/>
      <f:selectItem itemValue="A2" itemLabel="A2"/>
      <f:selectItem itemValue="A3" itemLabel="A3"/>
      <f:selectItem itemValue="A4" itemLabel="A3"/>
      </h:selectOneMenu>

      <h:selectOneMenu name="itemvalue2" id="itemvalue2" value="#{bean.value}"
      rendered="#{itemList.instance.item=='A'}"
      styleClass="message">
      <f:selectItem itemValue="A1" itemLabel="A1"/>
      <f:selectItem itemValue="A2" itemLabel="A2"/>
      <f:selectItem itemValue="A3" itemLabel="A3"/>
      <f:selectItem itemValue="A4" itemLabel="A3"/>
      </h:selectOneMenu>

      <h:selectOneMenu name="itemvalue3" id="itemvalue3" value="#{bean.value}"
      rendered="#{itemList.instance.item=='B'}"
      styleClass="message">
      <f:selectItem itemValue="B1" itemLabel="B2"/>
      <f:selectItem itemValue="B1" itemLabel="B2"/>
      </h:selectOneMenu>
      .........
      </rich:panel>

      <h:commandButton id="update"
      value="Update"
      action="#{abcHome.update}"
      rendered="#{abcHome.managed}"
      onclick="if (!confirm('Are you sure you want to update?')) return false;">

        • 1. Re: urgent help required, a4j onchange event
          Ilya Shaikovsky Master

          the code seems looks ok.. sorry, but could not understand the problem with your description.

          • 2. Re: urgent help required, a4j onchange event
            Nick Belaevski Master

            Hi,

            Try to add

            <a4j:support bypassUpdates= "true" ...>


            • 3. Re: urgent help required, a4j onchange event
              Val Sw Expert

              Edit screen: I tried adding bypassUpdates="true" in "a:support" tag but still it updates the database as soon as I select any other value from dropdown.

              Create Screen : Using bypassUpdates="true" does not change the other dropdowns in "panel"

              Ilya : Issue is, as soon as I change 1st dropdown value, this value is immediately updated in database before even clicking update button.

              <a:region renderRegionOnly="false">
              <s:decorate id="quantationDec" template="layout/edit.xhtml">
              <ui:define name="label">Item : </ui:define>
              <h:selectOneMenu value="#{itemList.instance.item}" required="true"
              styleClass="message">
              <f:selectItem itemValue="A" itemLabel="A"/>
              <f:selectItem itemValue="B" itemLabel="B"/>
              <f:selectItem itemValue="C" itemLabel="C"/>
              <a:support event="onchange" reRender="panel" bypassUpdates="true"/>
              </h:selectOneMenu>
              </s:decorate>
              </a:region>

              • 4. Re: urgent help required, a4j onchange event
                Ilya Shaikovsky Master

                Look.. a4j:support works fully the same as h:command except that it uses xmlHttpRequest to rise submit on some event and updates only parts of page. So if your db entities updates after simple h:command* submit - the same will be done during ajax request. So just create some buffer bean which fields will be populated to db only after some action.

                • 5. Re: urgent help required, a4j onchange event
                  Val Sw Expert

                  Thanks for the replying Ilya...

                  We will only have 1 main 1st. dropdown and 3 other child dropdowns, it is very trival...

                  Is there no other way instead of writing buffer bean.

                  I have tried a lot using other simple JSF and Ajax using bean but our child drop-downs will be in UI repeat which will be added dynamically...