12 Replies Latest reply on Apr 4, 2007 1:17 AM by mousstik

    rendering selectOneRadio

    mousstik

      Hi,

      I want to display a selectOneRadio by selecting yes in a previous selectOneRadio on the same JSF.
      If No is selected, the second selectOneRadio disappears.

      Here is my JSF code :

      <f:view>
       <h:form>
       <h:selectOneRadio value="#{bean.boolean1}" >
       <a4j:support event="onchange" reRender="rep" />
       <f:selectItem itemValue="true" value="Oui"/>
       <f:selectItem itemValue="false" value="Non"/>
       </h:selectOneRadio>
      
       <h:selectOneRadio value="#{bean.boolean2}" id="rep" rendered="#{bean.boolean1}">
       <f:selectItem itemValue="true" value="Oui"/>
       <f:selectItem itemValue="false" value="Non"/>
       </h:selectOneRadio>
       </h:form>
      </f:view>
      


      My bean Bean is a classic one with 2 boolean and their getter/setter.

      The scope is session but when I change it in request, it's the same.

      Could you please help me ?

        • 1. Re: rendering selectOneRadio
          mousstik

          Sorry I didn't explain what happened in my application.
          If my boolean1 is initialized with "true" in my bean, the second selectOneRadio is always displayed. If false, it's never displayed...

          • 2. Re: rendering selectOneRadio

            try:

            <f:view>
             <h:form>
             <h:selectOneRadio value="#{bean.boolean1}" >
             <a4j:support event="onchange" reRender="rep" />
             <f:selectItem itemValue="true" value="Oui"/>
             <f:selectItem itemValue="false" value="Non"/>
             </h:selectOneRadio>
             <a4j:outputPanel layout="none">
             <h:selectOneRadio value="#{bean.boolean2}" id="rep" rendered="#{bean.boolean1}">
             <f:selectItem itemValue="true" value="Oui"/>
             <f:selectItem itemValue="false" value="Non"/>
             </h:selectOneRadio>
             </a4j:outputPanel>
             </h:form>
            </f:view>


            Explanation: when the component is not rendered at the first time, there is no any node in the browser DOM that represent the non-rendered component. During the ajax request you put the rendered to true. However, when the new update comes to the browser, ajax4jsf has no idea where to insert it. If you put <a4j:log> on the page, you can see the message about it.
            So, do not point to component with rendered attribute. Point to one of the parent. The second approach is using <a4j:outputPanel layout="none"> as I show above. This insert the non-visible stub to the DOM, so ajax4jsf knows where is the place it can insert update into.

            do not point with reRender to component that has rendered attribute.

            • 3. Re: rendering selectOneRadio
              mousstik

              thank you Sergey I will try this tomorrow and give here the result.
              I've tried to put <a4j:region id="rep"> but without success...

              • 4. Re: rendering selectOneRadio

                I am sorry, but are you sure in the code I posted above you see the a4j:region, but not a4j:outputPanel.
                Never ever use a4j:region for the purpose, it is not designed for!

                • 5. Re: rendering selectOneRadio
                  mousstik

                  Sorry Sergey I think we misunderstood. I wanted to say that before posting my question here, I've tried to pu an <a4j:region> but without success :-(

                  thank you for your answer but I still have a little problem. When I select Yes, my second radio button appears but when I select No, it's still present. Is it normal or my bean is incorrect ?

                  thank you again for your help

                  • 6. Re: rendering selectOneRadio

                    post your current page code

                    • 7. Re: rendering selectOneRadio
                      mousstik

                      Thanks, I'll post my code tomorrow, I don't have my source code at home ;-) But my bean is very classic, two boolean and two method setboolean and isboolean.
                      I'll try again tomorrow by rewritting my bean correctly and if it dosen't work I'll repost. Your answer makes me think that my bean should be false.

                      • 8. Re: rendering selectOneRadio

                        If you look at the begging of this thread very carefully, you can see your post with your code and then my version of the code you should have.

                        The difference between your code and my version is a couple of lines.

                        <a4j:outputPanel layout="none">
                        .....
                        </a4j:outputPanel>


                        So, my question to you is : did you pay an attention to those two lines?



                        • 9. Re: rendering selectOneRadio
                          mousstik

                          Yes, of course.
                          I added this two lines in my JSF code, this has for consequence the displaying of my second selectOneRadio when I select Yes.
                          But when I select No then, I want this second selectOneRadio disapear.
                          I thought you wanted me to post my bean code.

                          • 10. Re: rendering selectOneRadio

                            Ok. So, we have some progress on it.

                            Just for the testing purpose, put add ajaxRendered="true" to outputPanel. I.e:

                            <a4j:outputPanel ajaxRendered="true">
                             <h:selectOneRadio value="#{bean.boolean2}" id="rep" rendered="#{bean.boolean1}">
                             <f:selectItem itemValue="true" value="Oui"/>
                             <f:selectItem itemValue="false" value="Non"/>
                             </h:selectOneRadio>
                            </a4j:outputPanel>


                            Is it is hided /shown correctly now? If not we need to check that #{bean.boolean1} becomes false when you say No



                            • 11. Re: rendering selectOneRadio
                              mousstik

                              I'll try this and tell you the result tomorrow.
                              The only thing I can say tonight is when I add an outputText with the value bean.boolean1, the value correctly changes on my page !

                              • 12. Re: rendering selectOneRadio
                                mousstik

                                it works very well.
                                Thank's a lot