You need to sign in to do that
Don't have an account?
Aditya Rayavarapu 5
Pass variable in Controller
Hello,
Please take a look at my controller (Public string acc4). In the else statement, I have hardcoded the value 'xxxx', but I want it to take the value of the string acc3 (which is an input field in the VF page). I've tried a few different ways for this, but can't seem to figure it out. Any suggestions?
Thanks
Part of VF Page:
<apex:inputField value="{!c.Lastname}" />
<apex:inputField value="{!c.Master__c}" />
<apex:inputField value="{!cont.Lastname}" />
<apex:commandButton action="{!save}" value="Save"/>
Part of CONTROLLER:
public Contact c {get; set;}
Public Contact cont{get;set;}
Public String accId{get;set;}
Public String acc2{get;set;}
Public String acc3{get;set;}
Public String acc4{get;set;}
public controller(){
accId = ApexPages.currentPage().getParameters().get('LastName');
if(accId != null)
{
this.c= [ SELECT LastName
FROM Contact
WHERE LastName = : accId ];
}
else
{this.c= new Contact ();}
acc3 = ApexPages.currentPage().getParameters().get('Master__c');
if(acc3 != null)
{
this.c= [ SELECT Master__c
FROM Contact
WHERE Master__c = : acc3 ];
}
else
{this.c= new Contact ();}
acc2 = ApexPages.currentPage().getParameters().get('LastName');
if(acc2 != null)
{
this.cont= [ SELECT LastName
FROM Contact
WHERE LastName = : acc2 ];
}
else
{this.cont= new Contact(); }
acc4 = ApexPages.currentPage().getParameters().get('Master__c');
if(acc4 != null)
{
this.cont= [ SELECT Master__c
FROM Contact
WHERE Master__c = : acc3 ];
}
else
{this.cont= new Contact(ReportsTo=new Contact(Master__c='xxxx'); }
}
public PageReference save() {
insert c;
insert cont;
Please take a look at my controller (Public string acc4). In the else statement, I have hardcoded the value 'xxxx', but I want it to take the value of the string acc3 (which is an input field in the VF page). I've tried a few different ways for this, but can't seem to figure it out. Any suggestions?
Thanks
Part of VF Page:
<apex:inputField value="{!c.Lastname}" />
<apex:inputField value="{!c.Master__c}" />
<apex:inputField value="{!cont.Lastname}" />
<apex:commandButton action="{!save}" value="Save"/>
Part of CONTROLLER:
public Contact c {get; set;}
Public Contact cont{get;set;}
Public String accId{get;set;}
Public String acc2{get;set;}
Public String acc3{get;set;}
Public String acc4{get;set;}
public controller(){
accId = ApexPages.currentPage().getParameters().get('LastName');
if(accId != null)
{
this.c= [ SELECT LastName
FROM Contact
WHERE LastName = : accId ];
}
else
{this.c= new Contact ();}
acc3 = ApexPages.currentPage().getParameters().get('Master__c');
if(acc3 != null)
{
this.c= [ SELECT Master__c
FROM Contact
WHERE Master__c = : acc3 ];
}
else
{this.c= new Contact ();}
acc2 = ApexPages.currentPage().getParameters().get('LastName');
if(acc2 != null)
{
this.cont= [ SELECT LastName
FROM Contact
WHERE LastName = : acc2 ];
}
else
{this.cont= new Contact(); }
acc4 = ApexPages.currentPage().getParameters().get('Master__c');
if(acc4 != null)
{
this.cont= [ SELECT Master__c
FROM Contact
WHERE Master__c = : acc3 ];
}
else
{this.cont= new Contact(ReportsTo=new Contact(Master__c='xxxx'); }
}
public PageReference save() {
insert c;
insert cont;
See the difference between the "Inputfield" and "inputtext". I you want to bind the varibale to the controller use that in the vf page.
to bind it to a controller variable use inputtext.
Regards,
MCS
<apex:inputtext value="{!acc3}" />