function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesRedSalesRed 

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.

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

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

souvik9086souvik9086

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

 

This was selected as the best answer
Avidev9Avidev9

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 ?