3 Replies Latest reply on Apr 21, 2007 10:17 AM by Sergey Smirnov

    a4j:region inside a4j:repeat

    Ovidiu Balas Newbie

      Hello all,

      I have the following code:

      <a4j:outputPanel id="test">
       <a4j:form>
       <a4j:repeat value="#{SearchBoxBean.resultSomeItems}" var="resultItem">
       <a4j:region selfRendered="true">
       <h:selectBooleanCheckbox value="#{SearchBoxBean.onlyWithStock}">
       <a4j:support actionListener="#{SearchBoxBean.toggleOnlyWithStockOnOff}" reRender="test" event="onclick" />
       </h:selectBooleanCheckbox>
       </a4j:region>
       </a4j:repeat>
       </a4j:form>
       </a4j:outputPanel>
      


      The problem is when i click on one of the several checkboxes, Firefox only displays
      <html lang="de"><body>
      and IE7 displays an "Internal Server error" message.

      However, if i move the region outside the repeat, it all works well, but all controls are sent to the server. My purpose here is to limit the traffic to the server as much as possible...

      Can someone give me a hint on how to accomplish this?

      Thank you in advance,
      Ovi

        • 1. Re: a4j:region inside a4j:repeat
          Sergey Smirnov Master

          region does not limit the traffic to the server anyhow. ajaxSingle does.

          P.S. I wonder why selfRendered="true" ?

          • 2. Re: a4j:region inside a4j:repeat
            Ovidiu Balas Newbie

            Hello, Sergey, thank you for your quick response.

            My scope is to have a list of checkboxes in a form, and, when clicking on one of them, only that one to be submitted, like this:


            <a4j:form>
             <a4j:repeat value="#{SomeBean.someItems}" var="item">
             <a4j:region>
             <h:selectBooleanCheckbox value="#{SomeBean.someVar}">
             <a4j:support actionListener="#{SomeBean.someMethod}" event="onclick" />
             </h:selectBooleanCheckbox>
             </a4j:region>
             </a4j:repeat>
            </a4j:form>


            This code is not working, unfortunatelly, the problem is the existence of a4j:region inside a4j:repeat, as explained in my first post :(

            Then I tried a different approach, giving up the ideea of having a region and having instead a form for each checkbox, like this:

            <a4j:repeat value="#{SomeBean.someItems}" var="item">
             <a4j:form ajaxSingle="true">
             <h:selectBooleanCheckbox value="#{SomeBean.someVar}">
             <a4j:support actionListener="#{SomeBean.someMethod}" event="onclick" />
             </h:selectBooleanCheckbox>
             </a4j:form>
            </a4j:repeat>


            The problem here is when i click on a checkbox, all forms are submitted (e.g. the setters methods in the backing bean, are called for every checkbox, not only the ones in the current submitted form). AjaxSingle does not help very much here, maybe I put it in a wrong place?

            Any ideea on how to prevent this?

            Thank you in advance,
            Ovi

            • 3. Re: a4j:region inside a4j:repeat
              Sergey Smirnov Master

              Ovi, you put all eggs in one basket.
              Getters and setters of the backing beans are invoked several times during the JSF lifecycle. This is like JSF works. You cannot prevent it. Does not matter it is Ajax or not.

              you need to add ajaxSingle=true to the a4j:support, but not to a4j:form.
              I.e. <a4j:support ajaxSingle="true"..... />

              Having ajaxSingle=true on the a4j:form without ajaxSubmit just does not make sense. DO NOT add so many forms

              a4j:region is not allowed inside a4j:repeat (or any other iteration component kind )

              This is an example of table where rows are updated.
              http://localhost/richfaces-art-datatable/pages/example10.jsf
              Only the second table uses <a4j:support ajaxSingle="true" ..../>
              If you have FireFox with FireBug extension, you can see that in the first table all four number are submitted. In the second case, only that just edited.