5 Replies Latest reply on Apr 28, 2010 5:23 AM by amcghie

    issue with modalPanel and selectOneRadio

      Hello everyone,

       

      I'm hoping someone can help me.  I have having trouble getting the value of a selectOneRadio component to update with a modalPanel.  I have created the following trivial example to demostrate my problem, can anyone see what I'm doing wrong?

       

      I have the following XHTML page:

       

      {code:xml}
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:a4j="http://richfaces.org/a4j">
        <a4j:form>
          <a4j:commandLink id="showModalPanelLink"
                           value="Show Modal Panel">
            <rich:componentControl for="modalPanel" attachTo="showModalPanelLink" operation="show" event="onclick"/>
          </a4j:commandLink>
          <br/>
          <a4j:outputPanel id="status">
            <h:outputText value="#{backingBean.mandatory}" />
          </a4j:outputPanel>
        </a4j:form>

       

        <a4j:form id="modalForm">
            <rich:modalPanel id="modalPanel" width="350" height="150">
              <f:facet name="header">
                  <h:panelGroup>
                      <h:outputText value="Set Mandatory" />
                  </h:panelGroup>
              </f:facet>
              <h:panelGrid columns="2">
            
                <h:panelGroup />
                <h:selectOneRadio id="mandatoryRadio"
                                  value="#{backingBean.mandatory}">
                  <f:selectItem itemValue="true" itemLabel="Mandatory" />
                  <f:selectItem itemValue="false" itemLabel="Optional" />
                </h:selectOneRadio>
              
                <h:panelGroup />

       

                <a4j:commandButton id="addButton"
                                   action="#{backingBean.logMandatoryValue}"
                                   value="Hide"
                                   reRender="status"
                                   oncomplete="#{rich:component('modalPanel')}.hide()" />                           
              </h:panelGrid>
            </rich:modalPanel>
      </a4j:form>
      </html>
      {code}

       

      and the following in my backing bean (which is declared with session scope):

       

      {code:java}
      public class BackingBean {

       

        private boolean mandatory = false;

       

        public backingBean() {}

       

        public String logMandatoryValue() {
          System.out.println("Mandatory=" + mandatory);
          return null;
        }

       

        public boolean getMandatory() {
          return isMandatory();
        }

       

        public boolean isMandatory() {
          return mandatory;
        }

       

        public void setMandatory(boolean mandatory) {
          this.mandatory = mandatory;
        }
      }
      {code}

       

      No matter which value I select in the modalPanel the value shown is false (in both the browser and log).

       

      Any help would be greatly appreciated

       

      Kind Regards

       

      Andy

        • 1. Re: issue with modalPanel and selectOneRadio
          faustodelatog

          1) if you want select boolean values why don't you try with h:selectBooleanCheckBox.

          2) try to map to a integer property in the controller <h:selectOneRadio id="mandatoryRadio"
                                      value="#{backingBean.mandatory}">
                      <f:selectItem itemValue="1" itemLabel="Mandatory" />
                      <f:selectItem itemValue="0" itemLabel="Optional" />
                    </h:selectOneRadio>

          3) try with EL like this<h:selectOneRadio id="mandatoryRadio"
                                      value="#{backingBean.mandatory}">
                      <f:selectItem itemValue="#{true}" itemLabel="Mandatory" />
                      <f:selectItem itemValue="#{false}" itemLabel="Optional" />
                    </h:selectOneRadio>

          1 of 1 people found this helpful
          • 2. Re: issue with modalPanel and selectOneRadio

            Hi Fausto,

             

            Thanks for the suggestion, but this doesn't work either.  What is strange is that if I embed the same JSF components from the panelGrid within the first a4j:form like so:

             

              <a4j:form>
                <a4j:commandLink id="showModalPanelLink"
                                 value="Show Modal Panel">
                  <rich:componentControl for="modalPanel" attachTo="showModalPanelLink" operation="show" event="onclick"/>
                </a4j:commandLink>
                <br/>
                <a4j:outputPanel id="status">
                  <h:outputText value="#{backingBean.mandatory}" />
                </a4j:outputPanel>

             

                <h:panelGrid columns="2">
                   
                      <h:panelGroup />
                      <h:selectOneRadio id="mandatoryRadio2"
                                        value="#{backingBean.mandatory}">
                        <f:selectItem itemValue="true" itemLabel="Mandatory" />
                        <f:selectItem itemValue="false" itemLabel="Optional" />
                      </h:selectOneRadio>
                     
                      <h:panelGroup />
                      <a4j:commandButton id="addButton2"
                                         value="Change"
                                         reRender="status" />                            
                </h:panelGrid>
              </a4j:form>
             
            Then when I click on the "Change" button (id=addButton2), then the value of the outputText in the status outputPanel changes as expected.  Do you think it could be anything to do with having the modalPanel in a seperate form?  According to the doco this is required.

             

            Many Thanks

             

            Andy

            • 3. Re: issue with modalPanel and selectOneRadio
              ilya_shaikovsky

              1)read about modal panel and its form elements limitation in developer ddocumentation. (also check domElementAttachment)

              2) not really related to problem but just optimization hint - why did you defined component control at a4j:command - you really need ajax request when showing the panel? Or its just client side operation? If so add disableDefault=true to cc in order the a4j:control not send ajax on showing panel.

              • 4. Re: issue with modalPanel and selectOneRadio

                Hi Ilya,

                 

                Thanks for the tip about the a4j:command, In my actual page I'm submitting a request via AJAX, but removed the action for simplicity of the example above.

                 

                I can't find any information in the developer documentation about modal panel form element limitations.  Are you refering to the following page?

                 

                http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_modalPanel.html

                 

                The only limitation I can see is inserting the modalPanel inside it's own form (which I have done).  Am I missing something?

                 

                Kind Regards

                 

                Andy

                • 5. Re: issue with modalPanel and selectOneRadio

                  After a little tinkering, I understand what the documentation is saying.  The form element must appear inside modalPanel e.g.:

                   

                  <rich:modalPanel id="modalPanel" width="350" height="150">

                    <h:form>

                      ...

                    </h:form>

                  </rich:modalPanel>

                   

                  Whereas in my origingal posting I had the form element outside the modalPanel.

                   

                  Many Thanks for your help.

                   

                  Andy