You need to sign in to do that
Don't have an account?
NeelimaG
accessing values between vf page,component and controller
I have a VF page with MyController and MyComponent.
MyController is used both in VF page and Component.
I have two variables in MyController and these will be set to some value from the Component.
But when I try to access them from VFPage, the variables are returning null.
Below is the simplified code for the three items.
Any ideas?
public with sharing class MyController {
public String var1 {get; set;}
public String var2 {get;set;}
//method called from component
public void setVariables() {
var1='test';
var2='test2';
}
} //end of MyController
Component code:
<apex:component controller="MyController" access="global"> <apex:attribute name="VarId1" description="The type of record we are viewing." type="String" assignTo="{!var1}" />
<apex:attribute name="VarId2" description="The type of record we are viewing." type="String" assignTo="{!var2}" />
<apex:form>
<apex:commandButton value="Verify Code" onclick="veify();return false;" >
<apex:actionFunction name="verify" action="{!setVariables()}" rerender="" status="counterStatus2">
</apex:actionFunction>
</apex:commandButton> </apex:form>
</apex:Component>
My VF page
<apex:page docType="html-5.0" controller="MyController" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false"> <html lang="en">
<apex:outputPanel id="verifiedBlockId" rendered="{!verified}"> <div class="col-sm-12 padding-left-0"> <h1><apex:outputText id="VarId" value="{!var1}"></apex:outputText></h1> <apex:outputText id="VarId2" value="{!var2}" style="visibility:hidden" ></apex:outputText> </apex:outputPanel>
<c:TG_MyComponent VarId1="" VarId2=""></c:MyComponent> </body> </html> </apex:page>
MyController is used both in VF page and Component.
I have two variables in MyController and these will be set to some value from the Component.
But when I try to access them from VFPage, the variables are returning null.
Below is the simplified code for the three items.
Any ideas?
public with sharing class MyController {
public String var1 {get; set;}
public String var2 {get;set;}
//method called from component
public void setVariables() {
var1='test';
var2='test2';
}
} //end of MyController
Component code:
<apex:component controller="MyController" access="global"> <apex:attribute name="VarId1" description="The type of record we are viewing." type="String" assignTo="{!var1}" />
<apex:attribute name="VarId2" description="The type of record we are viewing." type="String" assignTo="{!var2}" />
<apex:form>
<apex:commandButton value="Verify Code" onclick="veify();return false;" >
<apex:actionFunction name="verify" action="{!setVariables()}" rerender="" status="counterStatus2">
</apex:actionFunction>
</apex:commandButton> </apex:form>
</apex:Component>
My VF page
<apex:page docType="html-5.0" controller="MyController" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false"> <html lang="en">
<apex:outputPanel id="verifiedBlockId" rendered="{!verified}"> <div class="col-sm-12 padding-left-0"> <h1><apex:outputText id="VarId" value="{!var1}"></apex:outputText></h1> <apex:outputText id="VarId2" value="{!var2}" style="visibility:hidden" ></apex:outputText> </apex:outputPanel>
<c:TG_MyComponent VarId1="" VarId2=""></c:MyComponent> </body> </html> </apex:page>
make sure your rerender some item in componet rather than putting rerrender as ="" . and your action should be action="{!setVariables}".