View state does not appear on pages using Standard controllers?

I am looking into ‘View State Limit exceeded’ error and want to display the View state information using the development mode footer. For my user, I have enabled both Development Mode and Show View State in Development Mode.

At the moment, I cannot get the View State to appear. The page does contain <apex:form> tags but is using a standardController.

By using a Standard Controller, does this mean I cannot get the View State information I need?

Since the view state is linked to form data, the View State tab only appears if your page contains an <apex:form> tag. In addition, the View State tab displays only on pages using custom controllers or controller extensions. Link

Does anyone know any other way around this?

Answer

What the message states is that you need some custom Apex code for the page to bother serializing the View State and sending it to the server. There are two ways to do so.

  1. Use a standard controller with a controller extension.
  2. Use a custom controller.

If you are using a StandardController already, you would write an Extension. The Visualforce Developer Guide has a great article on Building a Controller Extension. In essence, you need to write a class that accepts the StandardController as a parameter in its constructor, then add it to the extensions property of your <apex:page> tag.

Extension

public with sharing class MyExtension
{
    public MyExtension(ApexPages.StandardController controller)
    {
        // constructor logic if necessary
    }
}

Page

<apex:page standardController="..." extensions="MyExtension">
    <!-- additional markup -->
</apex:page>

Note that the property is plural. You can add more than one extension to a page.

I also highly recommend you read Difference between controller and extensions. It’s one of the better answers anywhere on this forum.

Attribution
Source : Link , Question Author : TSmith , Answer Author : Community

Leave a Comment