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
Ken KoellnerKen Koellner 

What is view state? All data going to/from page or all data your controller owns?

I want to make sure I understand view state.  I have a controller that also uses other classes and those class read a lot of data, only some of which is displayed on the page at a time.

 

Is the view state all data going to/from the page?

 

Or is view state all data my controller is owning, including class instances it has references to that have data?

 

 

I have an application where there will be lots of data handled by the controller but the user will page through it.  I don't want to exceed view state size.  That's why I ask the question.  I did notice that static data is not part of the view state.  A follow up question is if I keep my large set of data in statics instead of instance variables will that help?

 

 

aballardaballard

If you have data you do not want included in viewstate, mark the variable as transient in the apex code.

 

(Then it is up to you to recreate the data on any action from the page.   any daya you exclude from viewstate won't be there when the action is processed.   That's what viewstate is for....)

soofsoof

Everything that you keep in non-transient instance variables, is a part of view-state.  As for keeping the data in static variables, I don't think it will work for you.  If you need data accross invocations/requests, then static variables would not hold the data accross requests.  If you DO NOT need data across requests, then you can keep it in local variables or transient variables (instead of instance variables), and it won't be a part of view-state.

 

I hope that helps!

 

Thanks.

Chamil MadusankaChamil Madusanka

Refer : http://wiki.developerforce.com/page/An_Introduction_to_Visualforce_View_State

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Ken KoellnerKen Koellner

Do effectively your entire controller and all its data do not exist between requests.

 

All data gets sent to the for form in the web browser and is sent back, correct?

 

I thought maybe the hidden field just contains a key to identify the view state and the actual data was saved on the server.  I suspect that is not the case and that all data is sent and retrieved from the server.

 

 

cwall_sfdccwall_sfdc

Visualforce does not store state on the server.  State is serialized to the client and the client push the state back to the server on form-based requests.  This is why it's very important to only store what is needed in viewstate and to design and develop your form-based pages efficiency, eg don't overload the page.

 

Also, in th dev mode footer, use View State Inspector to see what is in view state.

soofsoof

That's correct!  The state is NOT maintained at server-side, but on the client-side as a value of a hidden form-field, in an encrypted format.

 

Thanks.