New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Saturday, 4 August 2012

We have three country buttons, if we click any button that country information should only display

VF
<apex:page controller="coun">
<apex:form >

<apex:commandButton value="India" action="{!india}" reRender="India,Us,Uk"/>
<apex:commandButton value="Us" action="{!us}" reRender="India,Us,Uk"/>
<apex:commandButton value="Uk" action="{!uk}" reRender="India,Us,Uk"/>

<apex:pageBlock >

<apex:outputPanel id="India">
<apex:pageBlockSection title="India" rendered="{!mhide}">
</apex:pageBlockSection>
</apex:outputPanel>

<apex:outputpanel id="Us">
<apex:pageBlockSection title="US" rendered="{!m1hide}">
</apex:pageBlockSection>
</apex:outputpanel>

<apex:outputpanel id="Uk">
<apex:pageBlockSection title="UK" rendered="{!m2hide}">
</apex:pageBlockSection>
</apex:outputpanel>

</apex:pageBlock>

</apex:form>
</apex:page>

APEX

public class coun {

    public Boolean hide = false;
    public Boolean hide1 = false;
    public Boolean hide2 = false;
   
    public void setMhide(Boolean b) {
    this.hide = b;
    }
   
    public Boolean getMhide() {
    return this.hide;
    }//Passing input dynamically through another method
   
   
    public Boolean getM1hide() {
        return this.hide2;
    }
   
    public void setM1hide(Boolean b) {
      this.hide2 = b; 
    }
   
   
    public Boolean getM2hide() {
        return this.hide1;
    }
   
    public void setM2hide(Boolean b) {
        this.hide1 = b;
    }
   
   
    public PageReference india() {
        setMhide(true);
        setM2hide(false);
        setM1hide(false);       
        return null;
    }
//displaying only india information and hiding other information
   
     public PageReference us() {
        setM1hide(true);
        setM2hide(false);
        setMhide(false);
        return null;
    }
   
    public PageReference uk() {
        setM2hide(true);
        setM1hide(false);
        setMhide(false);
        return null;
    }  
   
}

Explanation:
* For displaying or hiding we should use rendered, It contains either True or False.
* Instead of giving True or False, I would like to pass T/F dynmically using {!name}
* For {!name}, I would like to construct set and get method seperately.
* For set method, I would like to pass a boolean value through boolean datatype.
* For this I would like to pass the value through another method.
* Using, setmethodname(T/F) as a statement in another method.
* Through get method again I am returning the boolean value to rerenderd.
* By default, to put false I am taking a boolean type varibale.
* action, rerender, renderd should mainly use in VF page.

No comments:

Post a Comment

Labels