1

I have a VF page with output text that I want to show based on the boolean blShowIt in the controller. I have 2 buttons on the form, one to show the text the other to hide it. And I set blShowIt to true, but it displays as false..

I tried a panel, but not luck. So why do the buttons not change the value?

Thanks in advance!

public class clsTestRender {
    public boolean blShow{get;set;}
    public boolean blShowIt; 

    public clsTestRender(){
        blShowIt = true;
    }    
    public void show(){
        blShowIt = true;  
    }
    public void hide(){
        blShowIt = false;
    }
    public boolean getblShow(){
        return blShowIt;
    }
}

VF Page:

<apex:page  controller="clsTestRender"  >
    <apex:form>
     <apex:commandButton value="Show" action="{!show}" reRender="t1,p1,t0"/>
     <apex:commandButton value="Hide" action="{!hide}" reRender="t1,p1,t0"/>
        <BR/>
     <apex:outputText value="Show Value = {!blshow}" id="t0" /> <BR/>  

     <apex:outputPanel rendered = "{!blshow}" id="p1">
         <apex:outputText value="Show this when true "  /> 
     </apex:outputPanel>
        <BR/>
     <apex:outputText value="Show this when false "  rendered = "{!(!blshow)}" id = "t1"/>
     </apex:form>
</apex:page>
1

You don't need the getblShow() method or the blShowIt member in your code as they are just confusing matters. Just use the blShow member directly. Your controller class would look like this:

public class clsTestRender {
    public boolean blShow {get;set;}

    public clsTestRender(){
        blShow = true;
    }    
    public void show(){
        blShow = true;  
    }
    public void hide(){
        blShow = false;
    }
}
| improve this answer | |
  • Should probably be private set. – Adrian Larson Jun 23 '15 at 17:24
  • This, used with tandonprateek's VF cleanup worked. Thank you! – Apx42 Jun 23 '15 at 17:58
-1

Can u plz try below code.

    <apex:page  controller="clsTestRender"  >
    <apex:form>
     <apex:commandButton value="Show" action="{!show}" reRender="t1,p1,t0"/>
     <apex:commandButton value="Hide" action="{!hide}" reRender="t1,p1,t0"/>
        <BR/>
<apex:outputPanel id="t0">
     <apex:outputText value="Show Value = {!blshow}" />   
</apex:outputPanel> <BR/>
     <apex:outputPanel id="p1">
         <apex:outputText rendered = "{!blshow}" value="Show this when true "  /> 
     </apex:outputPanel>
        <BR/>
<apex:outputPanel id = "t1">
     <apex:outputText value="Show this when false "  rendered = "{!(!blshow)}" />
</apex:outputPanel>
     </apex:form>
</apex:page>
| improve this answer | |
  • This, used with Mark Ponds controller cleanup worked. Thank you! – Apx42 Jun 23 '15 at 17:58
  • @tandonprateek - Just like simply posting code for a question is frowned upon so it simply posting code for an answer. In order for others to easily see what the issue is and for the OP to get the most out of the effort you put into crafting the answer, please explain a little bit about what it is you see as the issue and how your solution solves that. – Eric Jun 24 '15 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.