2 Replies Latest reply on Jun 18, 2009 3:32 PM by thiagu.m

    Rendered option

      hi every one


      in my page i have two text box like x and y with one drop down menu.
      the drop down menu have the possible values are like 'Y Only' and 'X Only' and 'both X and Y'.
      based on the drop down selection i need to enable and disable the text fields on the screen.
      i don't want to hart code my view page.
      it is possible to do it dynamically.
      because my drop down menu value is dynamic one.
      is it possible to do with drools rule.


      by
      Thiagu.m


        • 1. Re: Rendered option
          niox.nikospara.yahoo.com

          Hi,


          One solution with RichFaces would be:


          <h:selectOneMenu value="#{bean.type}">
            <f:selectItem itemLabel="Y only" value="Y_ONLY" />
            <f:selectItem itemLabel="X only" value="X_ONLY" />
            <f:selectItem itemLabel="Both" value="BOTH" />
            <a:support event="onchange" reRender="xval,yval" />
          </h:selectOneMenu>
          
          <h:inputText id="xval" disabled="#{bean.type == 'Y_ONLY'}" ... />
          <h:inputText id="yval" disabled="#{bean.type == 'X_ONLY'}" ... />
          



          But this requires a roundtrip to the server. It can be done with JS:


          <h:selectOneMenu
            value="#{bean.type}"
            onchange="disableControl(this.value)"
          >
            <f:selectItem itemLabel="Y only" value="Y_ONLY" />
            <f:selectItem itemLabel="X only" value="X_ONLY" />
            <f:selectItem itemLabel="Both" value="BOTH" />
            <a:support event="onchange" reRender="xval,yval" />
          </h:selectOneMenu>
          
          <h:inputText id="xval" ... />
          <h:inputText id="yval" ... />
          



          And the JS function would be like (you have to complete various parts, like the input ids):


          <script>
          function disableControl(val) {
            var xControl = document.getElementById("....:xval");
            var yControl = document.getElementById("....:yval");
            if( val == "Y_ONLY" ) {
              xControl.disabled = true;
              yControl.disabled = false;
            }
            else if( val == "X_ONLY" ) {
              ...
            }
            else {
              ...
            }
          }
          </script>
          



          I am not aware of Drools support for what you ask. It can be done, but you would have to write the plumbing code.

          • 2. Re: Rendered option

            thank u for Ur reply


            i am going to try with try with script.