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()).
- Is %CSP.Page instantiated using %New() under the hood, or does it use a different initialization mechanism?
- Are there specific limitations or behaviors in CSP pages that prevent InitialExpression from working as expected?
Thank you!
Comments
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:
Initialization Mechanism:
%CSP.Pageclass is designed for web-based processing, with lifecycle methods likeOnPage(),OnPreHTTP(), andOnPostHTTP()controlling request and response handling rather than relying on object instantiation semantics from%New()[3][2].Property Initialization: For most applications, properties in
%CSP.Pageare 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].Alternative Callbacks for Initialization: Override lifecycle methods like
OnPreHTTP()orOnPage()within your subclass of%CSP.Pageto 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:
Simplified: %CSP.Page is a collection of methods and event handlers without any own properties.
Related data are kept outside in %CSP.Request and %CSP.response.
But you may mimic InitialExpressions by using PARAMETERS
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 --> JoeHello @Julius Kavay
Thanks for pointing that out — you're absolutely right. The generator method for property initialization is missing. However, we are able to create an instance of %CSP.Page
Oh yes, you are able to create an instance of
Class Your.Page Extends%CSP.Page
{
Property Name As%String [ InitialExpression = "Joe" ];
}class because the inheritance goes as follows:
Your.Page <-- %CSP.Page <-- %Library.Base <-- %Library.SystemBase
and the %Library.SystemBase donates you the %New() method.