function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SidharthSidharth 

Component rerender by button/link

Hi

 

I have two components A and B, which i am showing in my Client portal.

Right now i am showing both, but now i have to show only one. 

Can i have two buttons/links naming A and B, so by clicking on any one, that component with open.

 

Here is Component A code, (B is just similar with different google chart partameters).

 

<apex:component controller="TestChartController2a"> 
   <div>              

<img src="https://fdrclient.com/proxy-1.0/proxyproxiedUrl=http%3A%2F%2Fchart.apis.google.com}"/>           

</div> 
</apex:component>

 

Here is Visualforce page where i am caaling the components.

 

<apex:page showHeader="false" sidebar="false" standardController="Account">   

<apex:stylesheet value="{!$Resource.CustomerPortalCSS}"/>       

<div>       

<table>           

<tr>               

<td><c:Component_A /></td>               

<td><c:Component_B /></td>              

          </tr>       

</table>   

</div>

</apex:page>

 

Please provide a sample code to achieve that, if possible.

 

Thanks a lot

Sid

Best Answer chosen by Admin (Salesforce Developers) 
SantoshiSantoshi

You can modify the vf page as given below so that when a link is clicked the corresponding component will be rendered. You need to add extensions to your page and then set the value of rendered variables as true in class on the basis of links clicked.

 

 

<apex:page showHeader="false" sidebar="false" standardController="Account" extensions="Class1">   

<apex:stylesheet value="{!$Resource.CustomerPortalCSS}"/>       

<apex:commandlink  value="A" action="{!rendersA}" rerender="renderComponents"/> <!- Set the rendered variable renderA of the corresponding section as true in the action>

 

<apex:commandlink value="B" action="{!rendersB}" rerender="renderComponents"/> <!- Set the rendered variable renderB of the corresponding section as true in the action>

<div>       

<table>           

<tr>               

<apex:outputpanel id="renderComponents" >

<apex:outputpanel rendered="{!renderA}"> <!-- Initialize the value of this varaiable as false so that when page is loaded this section is not rendered-->

<td><c:Component_A /></td>   

</apex:outputpanel>

 

<apex:outputpanel rendered="{!renderB}"> <!-- Initialize the value of this varaiable as false so that when page is loaded this section is not rendered-->

<td><c:Component_B /></td>      

 

</apex:outputpanel>   

</apex:outputpanel>               

          </tr>       

</table>   

</div>

</apex:page>



 

class code

 

pulic class class1

{

public boolean renderA{get;set;}

public boolean renderB{get;set;}

 

  Construtor for the class()

{

 // set the value for above varibales as false.

renderA=false;

renderB=false;

}

 

public void rendersA() // action for link A to set the render variable true for the section related to link A.

{
renderA=true;

}

 

public void rendersA() // action for link B to set the render variable true for the section related to link B.

{
renderB=true;

}

}

 

Thanks,

Santoshi.

All Answers

SidharthSidharth

Actually i have many other division in my customer portal, so i want to rerender only that componet division, based on selected button/link (component A or B)

SantoshiSantoshi

You can modify the vf page as given below so that when a link is clicked the corresponding component will be rendered. You need to add extensions to your page and then set the value of rendered variables as true in class on the basis of links clicked.

 

 

<apex:page showHeader="false" sidebar="false" standardController="Account" extensions="Class1">   

<apex:stylesheet value="{!$Resource.CustomerPortalCSS}"/>       

<apex:commandlink  value="A" action="{!rendersA}" rerender="renderComponents"/> <!- Set the rendered variable renderA of the corresponding section as true in the action>

 

<apex:commandlink value="B" action="{!rendersB}" rerender="renderComponents"/> <!- Set the rendered variable renderB of the corresponding section as true in the action>

<div>       

<table>           

<tr>               

<apex:outputpanel id="renderComponents" >

<apex:outputpanel rendered="{!renderA}"> <!-- Initialize the value of this varaiable as false so that when page is loaded this section is not rendered-->

<td><c:Component_A /></td>   

</apex:outputpanel>

 

<apex:outputpanel rendered="{!renderB}"> <!-- Initialize the value of this varaiable as false so that when page is loaded this section is not rendered-->

<td><c:Component_B /></td>      

 

</apex:outputpanel>   

</apex:outputpanel>               

          </tr>       

</table>   

</div>

</apex:page>



 

class code

 

pulic class class1

{

public boolean renderA{get;set;}

public boolean renderB{get;set;}

 

  Construtor for the class()

{

 // set the value for above varibales as false.

renderA=false;

renderB=false;

}

 

public void rendersA() // action for link A to set the render variable true for the section related to link A.

{
renderA=true;

}

 

public void rendersA() // action for link B to set the render variable true for the section related to link B.

{
renderB=true;

}

}

 

Thanks,

Santoshi.

This was selected as the best answer
SidharthSidharth

Thanks Santoshi, this is what i was looking for.