4 Replies Latest reply on Sep 14, 2007 5:34 AM by fmarwede

    Activate poll right before submit

    rapthor

      Hello,

      I wonder how it is possible to activate the "a4j:poll"-element right before the submit action of a commandButton is triggered. I have implemented a progress counter which simply polls a bean's getPercentage-getter. The result is always 0 until the user clicks the a submit button, which changes the percentage value.

      What I want to achieve is to start the poll-element AFTER the user clicks the submit button to avoid senseless network traffic because the value is 0. (And if it is possible deactivate the poll again after finishing.)

      This is an excerpt from the code I am using:

      <a4j:form>

      ......... this poll continously triggers events even though getPercentage always returns 0 ..........

      <h:panelGroup id="percentagepanel">
      <h:outputText value="#{bean.getPercentage}% uploaded" />
      <a4j:poll id="poll" limitToList="true" interval="400"
      reRender="percentagepanel" ignoreDupResponses="true" />
      </h:panelGroup>

      ......... the following button updates the percentage value ..........

      <h:panelGroup>
      <h:commandButton action="#{controller.doSomething}" value="Submit">
      </h:commandButton>
      </h:panelGroup>
      </a4j:form>

      Does anybody have an idea?

        • 1. Re: Activate poll right before submit
          rapthor

          No idea anyone? I just want to enable the a4j:poll whenever the user clicks on the submit button. So this has to work like a chain reaction.

          • 2. Re: Activate poll right before submit

            Use the rendered attribute of the poll. Here you can set a boolean value with your bean. When the button is clicked, set the value to true and so on. Perhaps this causes the effect you want - or did I get something wrong?

            Another thing: I see a limitToList attribute in your code. I tried to use that too but in my context that attribute (set to true) causes that the poll tag do nothing every time. I put this problem in this forum a few weeks ago but nobody answered...so if something don't work and you don't know why, try to get by on it without this attribute.

            But I hope this will be commented by the experts of this forum too.

            • 3. Re: Activate poll right before submit
              rapthor

              Hi, there's everythin gokay with my poll-tag like this.

              The problem is, when I set the rendered-attribute within the submit-button-action-Method, the page IS rerendered AFTER the things that happen within the method. But I have to set the rendered attribute "true" then cause a rerender of the poll-tag and after that proceed with the submit-method.

              • 4. Re: Activate poll right before submit

                Hi,

                that means you want the following things happen in this order:

                1.) Button is clicked.
                2.) Activate the poll to rerender the text
                3.) Call the action method of the button.

                Next idea: Control the rendered attribute of the poll not with a java boolean from the bean but with a javascript boolean. Set this one with the onclick or onsubmit event of the button...but I don't know if this causes the effect you want. The question is: When exactly the poll "notices" that it has to be rerendered? And I didn't use javascript in the context of JSF this way so far.