Question
· Sep 28

InitialExpression Not Working in %CSP.Page Subclass

Hello Community

The InitialExpression keyword values does not to set default values for properties in classes that extend %CSP.Page, unlike in other class types such as %Persistent or %RegisteredObject, where it works as expected during object instantiation (typically via %New()).

  1. Is %CSP.Page instantiated using %New() under the hood, or does it use a different initialization mechanism?
  2. Are there specific limitations or behaviors in CSP pages that prevent InitialExpression from working as expected?

Thank you!

Product version: IRIS 2025.1
$ZV: IRIS for Windows (x86-64) 2025.1 (Build 223U) Tue Mar 11 2025 18:18:59 EDT
Discussion (5)3
Log in or sign up to continue

The InitialExpression keyword works for setting initial values during object instantiation via %New() in certain types of classes, such as %Persistent, %RegisteredObject, etc., but this behavior does not apply consistently to %CSP.Page or its subclasses. %CSP.Page utilizes specific mechanisms for customization and instantiation, which differ from standard object creation through %New() [1][2][3].

Key points to consider:
1. Initialization Mechanism: %CSP.Page class is designed for web-based processing, with lifecycle methods like OnPage(), OnPreHTTP(), and OnPostHTTP() controlling request and response handling rather than relying on object instantiation semantics from %New() [3][2].

  1. Property Initialization: For most applications, properties in %CSP.Page are set during request handling or by explicitly overriding lifecycle methods. Using parameters or configuration settings might be more effective to achieve default values during response construction [3][5].

  2. Alternative Callbacks for Initialization: Override lifecycle methods like OnPreHTTP() or OnPage() within your subclass of %CSP.Page to implement default value assignments or initialization logic explicitly [2].

For further details regarding limitations or behaviors specific to %CSP.Page, you can consult its related documentation on callbacks, lifecycle management, and property interactions [2][5][6].

Sources:

My guess is, because abstract classes (%CSP.Page is an abstract class) can't be instantiated, your subclass lacks the generator methos for property initialisation.

But there is a simple solution:

Class Your.Page Extends (%RegisteredObject, %CSP.Page)
{
Property Name As %String [ InitialExpression = "Joe" ];
}

Well, the world is right again

set page=##class(Your.Page).%New()
write page.Name --> Joe