2 Replies Latest reply: Apr 14, 2009 11:41 AM by 807575 RSS

    problem with set rendered a component to false or true

    807575
      Hi,

      my problem is that ,in one case i set rendered a component to false ,so in another case i want to set rendered that component to true to displayed ,but it dosn't work .

      example:

      if(...){
      button1.setRendered(false);
      }
      else{
      button1.setRendered(true);
      }

      this code must execute when a page loaded so i put it in prerendered().
      but it dosen't work and dosen't display.

      thanks.
        • 1. Re: problem with set rendered a component to false or true
          807575
          Hi,

          Following are the steps I followed:

          1. Drag and drop a dropdown list and two buttons on the page
          2. In the Application outline click on dropdown1DefaultItems
          3. In the Properties sheet click on ... button next to Items property and a new Items dialog opens
          4. Remove the default item1, item2 and item3 and add True and False
          5. In the Project navigator expand the java sources node till you see Session Bean
          6. Right click on SessionBean and choose Add --> Property
          7. Enter val as the name of the property and click ok
          8. Expand the SessionBean node till you see the property val under the Fields node and click on it
          9. In the properties sheet enter "True" for the property initial value
          10. Return to the design view and double click on button1
          11. In the button1_action method add the following line of code
          getSessionBean1().setVal((String)dropdown1.getValue());
          12. In Page1.jave itself enter the following block of code after the afterRenderResponse method
          protected void beforeRenderResponse(){
                   if(getSessionBean1().getVal().equals("true")){
                      button2.setRendered(true);            
                  } else {
                      button2.setRendered(false);            
                  }
              }
          13. Save and run the application
          14. Depending on the value chosen in the dropdown list the button2 is rendered / not rendered everytime the button1 is clicked

          Hope this helps

          Cheers
          Giri
          • 2. Re: problem with set rendered a component to false or true
            807575
            Hi Friend,

            I was getting the same problem and want to share my exp with you also.

            Initially, I was using the bean scope as session but due to some reasons I modified it to request scope. Please check your bean's scope, I hope it would be request scope.

            For resolving it, I create one boolean field inside the backen bean like this: -

            private boolean renderedFlag = true;

            public boolean isRenderedFlag() {
            return renderedFlag;
            }

            public void setRenderedFlag(boolean renderedFlag) {
            this.renderedFlag = renderedFlag;
            }

            and inside the jsp, I binded it with rendered property of that component, like this: -

            rendered="#{AccountBean.renderedFlag}"

            I HOPE IT WOULD BE WORK FOR ALL;

            Thanks
            :)