0

I have a problem like when i select the check box it will rendered the particular part and after i deselect it is not rendering that part which i want to hide.

<apex:page sidebar="false" standardController="DetailLog__c" extensions="checkboxctrl">

 apex:form>

     <apex:pageBlock id="dir">

         <apex:pageBlockSection title="Perosnal Detail">
             <apex:outputField value="{!DetailLog__c.First_Name__c}"/>
             <apex:outputField value="{!DetailLog__c.Last_Name__c}"/>
             <apex:outputField value="{!DetailLog__c.Email_ID__c}"/>
              <apex:outputField value="{!DetailLog__c.Date_of_Birth__c}"/>

         </apex:pageBlockSection>

         <apex:inputCheckbox value="{!recheck}" label="Working">
            <apex:actionSupport action="{!reMethod}" event="onclick" reRender="dir"/> 
     </apex:inputCheckbox>

     <apex:outputPanel id="exp">

      <apex:pageBlockSection id="wed" title="Work Experience Detail" rendered="{!if(re==true,true,false)}">

             <apex:outputField value="{!DetailLog__c.Company_Name__c}"/>
             <apex:outputField value="{!DetailLog__c.Company_Address__c}"/>
             <apex:outputField value="{!DetailLog__c.Joining_Date__c}"/>
              <apex:outputField value="{!DetailLog__c.Notice_Period_Month__c}"/>
              <apex:outputField value="{!DetailLog__c.Desgination__c}"/>
              <apex:outputField value="{!DetailLog__c.Department__c}"/>
         </apex:pageBlockSection>
         </apex:outputpanel>
 apex:pageBlockSection title="Additional Information" >

             <apex:outputField value="{!DetailLog__c.Graduation__c}"/>
             <apex:outputField value="{!DetailLog__c.Post_Graduation__c}"/>
             <apex:outputField value="{!DetailLog__c.University__c}"/>
             <apex:outputField value="{!DetailLog__c.College_Name__c}"/>
              <apex:outputField value="{!DetailLog__c.Known_Programming_Languages__c}"/>  
         </apex:pageBlockSection>
     </apex:pageBlock>
/apex:form>
/apex:page>  

//-------------- Controller

public class checkboxctrl {

   public String recheck{get;set;}
   public Boolean re{get;set;}

    public checkboxctrl(ApexPages.StandardController controller) {



    }

    public PageReference reMethod()
    {


        re=true;
        System.debug('--Re--'+re);
        return null;
    }

    public PageReference reFalseMethod()
    {


        re=false;
        System.debug('--Re--'+re);
        return null;
    }


}

3 Answers 3

0

You don't have to create another variable in your controller re. Also your method reMethod is the one that always fire so your value of re will always evaluate to true.

Instead you can use the recheck value which is the true value of the checkbox.

Just change your reRender attribute and things should be good:

rendered="{!if(re==true,true,false)}

to

rendered="{!recheck}
0

Use `

<apex:inputCheckbox value="{!recheck}" label="Working" onclick="reMethod()" reRender="dir"/>`
<apex:actionFunction name="reMethod" action={!remethod}/>

at the place of

<apex:inputCheckbox value="{!recheck}" label="Working">
            <apex:actionSupport action="{!reMethod}" event="onclick" reRender="dir"/> 
     </apex:inputCheckbox>

//-- when you click on checkbox you are calling remethod in which you always set re variable True that's why its showing....

You can do like

public PageReference reMethod()
    {

        if(re==true){
             re=false;
        }else{
             re=true;
        } 

    }
0

You do not need the reCheck variable; you can directly use the re variable. This is because re is boolean and directly be used with inputcheckbox. That way, you would also not need the 2 methods you have. See below:

Controller Code:

public class checkboxctrl {

   public Boolean re{get;set;}

   public checkboxctrl(ApexPages.StandardController controller) {
       // Set your Default value here
       re = false;
   }
}

Visualforce Code:

<apex:page sidebar="false" standardController="DetailLog__c" extensions="checkboxctrl">

 <apex:form>

     <apex:pageBlock id="dir">

         <apex:pageBlockSection title="Perosnal Detail">
             <apex:outputField value="{!DetailLog__c.First_Name__c}"/>
             <apex:outputField value="{!DetailLog__c.Last_Name__c}"/>
             <apex:outputField value="{!DetailLog__c.Email_ID__c}"/>
              <apex:outputField value="{!DetailLog__c.Date_of_Birth__c}"/>

         </apex:pageBlockSection>

         <apex:inputCheckbox value="{!re}" label="Working">
            <apex:actionSupport event="onclick" reRender="dir"/> 
         </apex:inputCheckbox>

     <apex:outputPanel id="exp">

      <apex:pageBlockSection id="wed" title="Work Experience Detail" rendered="{!re}">

             <apex:outputField value="{!DetailLog__c.Company_Name__c}"/>
             <apex:outputField value="{!DetailLog__c.Company_Address__c}"/>
             <apex:outputField value="{!DetailLog__c.Joining_Date__c}"/>
              <apex:outputField value="{!DetailLog__c.Notice_Period_Month__c}"/>
              <apex:outputField value="{!DetailLog__c.Desgination__c}"/>
              <apex:outputField value="{!DetailLog__c.Department__c}"/>
         </apex:pageBlockSection>
         </apex:outputpanel>
 <apex:pageBlockSection title="Additional Information" >

             <apex:outputField value="{!DetailLog__c.Graduation__c}"/>
             <apex:outputField value="{!DetailLog__c.Post_Graduation__c}"/>
             <apex:outputField value="{!DetailLog__c.University__c}"/>
             <apex:outputField value="{!DetailLog__c.College_Name__c}"/>
              <apex:outputField value="{!DetailLog__c.Known_Programming_Languages__c}"/>  
         </apex:pageBlockSection>
     </apex:pageBlock>
</apex:form>
</apex:page>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .