Friday, 3 August 2012

Hide/show a pageBlock depending upon the button selection


VF:
' rendered' is used to hide or display visualforce elements
<apex:page controller="Wizard_3a_Controller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Rate Information">
Are there proposed non-standard electronic rates—<br/>
<apex:commandButton action="{!showSection1}" value="Yes" styleClass="btn" rerender="details"></apex:commandButton>
<apex:commandButton action="{!showSection2}" value="No" styleClass="btn"></apex:commandButton>
</apex:pageBlockSection>
<apex:outputPanel id="details">
<apex:pageBlockSection id="newData" title="Discount Rates" rendered="{!hideshow}">
Enter Proposal range
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>

APEX:
By default the page block is in hide mode due to datamember value i.e False
public class Wizard_3a_Controller
{

Boolean testval = false;
public pagereference showSection1() {
setHideshow(true);
return null; }

public pagereference ShowSection2()
{
setHideshow(false);
return null;
}

public Boolean getHideshow()
{
return this.testval;
}
public void setHideshow(boolean s)
{
this.testval = s;
}
}

No comments:

Post a Comment

Labels