You need to sign in to do that
Don't have an account?
Variable value being lost despite controller "set" being called correctly.
Hello,
I am trying to set a string vaue in my controller class but I'm finding th following unusual scenario resulting:
- Note I've tried to set my value using an actionFunction and subsequently I'm not trying via a hidden field.
- I click on the following button
<apex:commandLink styleClass="btn" value="Save Image Order" action="{!changeImageOrder}"/>
<apex:inputHidden value="{!currentImageOrder}" id="theHiddenInput"/>
In my controller, for String currentImageOrder the setter is called and prints out the value ok in my debug as follows.
public String currentImageOrder{get;set{
system.debug('in image order set ' + value);
}
}
In funciton "changeImageOrder" String currentImageOrder is null.
public PageReference changeImageOrder(){
system.debug('in chngorder111 ' + currentImageOrder);
system.debug('in chngorder222 ' + this.currentImageOrder);
return null;
}
As the setter is called first should the value not be set when I debug in changeImageOrder?
Thanks in advance for any help.
Hi,
Controller
public String currentImageOrder{get;set;} //Declare globally
public PageReference changeImageOrder(){
system.debug('in chngorder111 ' + currentImageOrder);
system.debug('in chngorder222 ' + this.currentImageOrder);
return null;
}
Page
<apex:commandLink styleClass="btn" value="Save Image Order" action="{!changeImageOrder}"/>
<apex:inputHidden value="{!currentImageOrder}" id="theHiddenInput"/>
Declare the get;set; like that and see what happens.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
Hi,
Controller
public String currentImageOrder{get;set;} //Declare globally
public PageReference changeImageOrder(){
system.debug('in chngorder111 ' + currentImageOrder);
system.debug('in chngorder222 ' + this.currentImageOrder);
return null;
}
Page
<apex:commandLink styleClass="btn" value="Save Image Order" action="{!changeImageOrder}"/>
<apex:inputHidden value="{!currentImageOrder}" id="theHiddenInput"/>
Declare the get;set; like that and see what happens.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
What is the initially value for "currentImageOrder" ?
Are you setting anything to "<apex:input:Hidden/>" ?
If you havent initialised the value of "currentImageOrder" it will be always be null. To pass a value to the controller probably you have to set a value to your inputHidden using js may be ?