You need to sign in to do that
Don't have an account?
heuye
variable can't be changed after asignTo?
below is all my code.when i click the commandButton,the pageBlockName doesn't change,why?
use the component in a page:
<c:test_updateAttribute blockName="set in page" />
component:
<apex:component controller="test_sample" access="global"> <apex:attribute name="blockName" type="String" required="true" access="global" assignTo="{!pageBlockName}" description="The blockName." /> <apex:pageBlock title="{!pageBlockName}" id="resultTable"> <apex:commandButton value="change blockName" action="{!changeName}" reRender="resultTable"/> </apex:pageBlock> </apex:component>
component controller:
global with sharing class test_sample{ public String pageBlockName {get; set;} public void changeName(){ pageBlockName = '456'; } }
This is because primitive values (e.g. Strings) are passed by value to components not by reference, so effectively the component takes a copy of the String.
Oddly enough I wrote a blog post about this very subject over the weekend and have just published it:
http://bobbuzzard.blogspot.com/2011/05/updating-attributes-in-component.html