+ Start a Discussion
lakshmi.sf9lakshmi.sf9 

How to pass controller value to copmonent

Hi,

In my controller i have one getter,setter variable.
public boolean test {get;set;}
public void next(){
test = true;
}
In page i have one button 
<apex:commandbutton value="Next" action = "{!Next()}" />
This will call component alse

In component 
<apex:attribute name="extrapoints" type="Boolean" description="extrapoints" assignTo="{!test}" />
<apex:outputText value ="{!test}"
If i debug the component i am getting false value.But i need here true.

Can any one help on this

Thanks,
ppoojary18@gmail.comppoojary18@gmail.com
Hi Lakhmi,

Please find below example

###### Component Controller ######
public class CompController {
    public boolean componentVariable{get;set;}
    public CompController(){
    }
}
###### Component ######
<apex:component controller = "CompController">
    <apex:attribute name="attributeName" description="This is color for the border." type="Boolean" required="true" assignTo="{!componentVariable}"/>
</apex:component>
###### Page controller######
public class PageController {
    public boolean pageVariable{get;set;}
    public PageController() {
        pageVariable = true;
    }
}
###### Page ######
<apex:page controller = "PageController">
    <c:sampleComponent attributeName="{!pageVariable}" />
</apex:page>
Note : pageVariable value will assigned to componentVariable after initialization of CompController class. if you try to debug componentVariable value inside CompController contructor then it will always null.

lakshmi.sf9lakshmi.sf9
Thanks ppoojary

Component and page is having same controller.Actually when I click on next button in the page ,it will call  next() in the controller.Here based on my requirement I am making boolean value as true.That I want to use in component.

Plese give solution
ppoojary18@gmail.comppoojary18@gmail.com
Hi

Even if same controller used in component and page you have pass values in above mentioned proceedure as there will be two separate instance of class exists