2 Replies Latest reply on Nov 21, 2011 10:28 AM by Milo van der Zee

    a4j:ajax does not fire oncomplete (rf4.1.0M4)

    Milo van der Zee Newbie

      In this snipped the oncomplete is called:

       

      <a4j:ajax event="change" render="#{cc.attrs.render}"

        onbegin="console.log('begin');"

        oncomplete="console.log('complete');"

        listener="#{cc.attrs.onChangeActionListener}"

        execute="@this"

      />

       

      But in the following it is not. Also the 'render' is not handled.

       

      <a4j:ajax event="change" render="#{cc.attrs.render}"

        onbegin="console.log('begin');"

        oncomplete="console.log('complete');"

        execute="@this"

      />

       


      I had to fix this by using aj4:jsFunction called by onbegin like:

       

      <a4j:ajax event="change" render="#{cc.attrs.render}"

        onbegin="#{cc.attrs.id}Render();"

        execute="@this"

      />

       

      Why is oncomplete not being fired? Looks a bit like that the oncomplete is only called when there is a listener defined. That makes some sense but the render should still be handled.

       

      Thanks,

      Milo

        • 1. Re: a4j:ajax does not fire oncomplete (rf4.1.0M4)
          Milo van der Zee Newbie

          After some more searching I found that a4j:ajax does not always like h: components like h:datatable and h:selectOneMenu. So it might have to be related to the fact that my more complete snipped looks like this:

           

          <h:selectOneMenu id="${cc.attrs.id}" rendered="${!cc.attrs.compact or !cc.attrs.disabled}" value="#{selectBoxValueManager.value[selectBoxValue]}"

            class="#{cc.attrs.styleClass}" style="${cc.attrs.style}" disabled="#{cc.attrs.disabled}" title="#{cc.attrs.title}"

          >

            <a4j:ajax event="change" render="#{cc.attrs.render}"

              onbegin="console.log('begin');"

              oncomplete="console.log('complete'); restoreFocus(); #{cc.attrs.oncomplete};"

              listener="#{cc.attrs.onChangeActionListener}"

              rendered="#{! empty cc.attrs.onChangeActionListener}"

              execute="@this"

            />

           

            <a4j:ajax event="change" render="#{cc.attrs.render}"

              rendered="#{empty cc.attrs.onChangeActionListener or ! empty cc.attrs.oncomplete}"

              onbegin="#{cc.attrs.id}Render();"

              execute="@this"

            />

            <f:selectItems value="#{selectBoxDataManager.getSelectBoxData(cc.attrs.selectClass,'id',cc.attrs.selectProperty,cc.attrs.ordering,cc.attrs.filter,cc.attrs.addNull,cc.attrs.canCache)}"/>

          </h:selectOneMenu>

           

          <a4j:jsFunction name="#{cc.attrs.id}Render"

            render="#{cc.attrs.render}"

            execute="@this"

            immediate="true"

            onbegin="console.log('begin');"

            oncomplete="console.log('complete'); restoreFocus(); #{cc.attrs.oncomplete};"

          />

          • 2. Re: a4j:ajax does not fire oncomplete (rf4.1.0M4)
            Milo van der Zee Newbie

            Sorry for the spam but I found the solution. I used 'rendered=...' to choose between the two versions of the onchange event. That does not work. Now I use c:if and all is fine.

             

            <h:selectOneMenu id="${cc.attrs.id}" rendered="${!cc.attrs.compact or !cc.attrs.disabled}" value="#{selectBoxValueManager.value[selectBoxValue]}"

              styleClass="#{cc.attrs.styleClass}" style="${cc.attrs.style}" disabled="#{cc.attrs.disabled}" title="#{cc.attrs.title}"

            >

              <c:if test="#{!empty cc.attrs.onChangeActionListener}">

                <a4j:ajax event="change" render="#{cc.attrs.render}"

                  onbegin="console.log('begin');"

                  oncomplete="console.log('complete'); restoreFocus(); #{cc.attrs.oncomplete};"

                  listener="#{cc.attrs.onChangeActionListener}"

                  execute="@this"

                />

              </c:if>

              <c:if test="#{empty cc.attrs.onChangeActionListener and (!empty cc.attrs.oncomplete or !empty cc.attrs.render)}">

                <a4j:ajax event="change" render="#{cc.attrs.render}"

                  onbegin="console.log('begin');"

                  oncomplete="console.log('complete'); restoreFocus(); #{cc.attrs.oncomplete};"

                  execute="@this"

                />

              </c:if>

              <f:selectItems value="#{selectBoxDataManager.getSelectBoxData(cc.attrs.selectClass,'id',cc.attrs.selectProperty,cc.attrs.ordering,cc.attrs.filter,cc.attrs.addNull,cc.attrs.canCache)}"/>

            </h:selectOneMenu>

             

             

            Hope this helps anybody.

             

            Thanks,

            Milo