Posted: 8 May 2015 8:38 EDT Last activity: 17 Jul 2017 16:28 EDT
PDN or Pega Help sought re: Pages & Classes
I have taken SAE I & II and have really not gotten a grasp of what is going on in the "Pages & Classes" tab. I have tried searching PDN and Mesh, as well as the online help, but really am not quite getting it. Is there a better overall guide to understanding this tab and the concepts it is trying to present?
I'm quite comfortable with inheritance/polymorphism, instantiation of objects, etc, but I just don't know what is being done here. When I ask people it's a bit like 5 blind guys describing an elephant - I get a different answer each time.
Where I am stumped is:
- are we declaring "new" variables / objects / whatever that are to be of the specified class?
- if not, if we are just stating a reference to something (which implies it already exists), where does that come from - is it assumed to be on the Clipboard?
- is it something altogether different than either of these?
***Updated by moderator: Marissa to close post***
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
Pages-and-classes merely describes some pages, it doesn’t create them, and it doesn’t define them.
One example would be if you were defining an activity and you were typing in the fields of a property-set step, and you typed
Note the dot at the end. Often when you type that dot, the system presents a list of possible properties so you can conveniently choose one.
But if “Mypage” isn’t mentioned in the pages-and-classes tab, then the system makes some assumptions about what the class of page Mypage is, which might be wrong (it tends to err on the side of too-generalized) .
If you specified in pages-and-classes, for example, that Mypage is of class “Code-Pega-List”, then when you press that dot during your property-set step, the system will know to present a list of properties from class Code-Pega-List. /Eric
Thanks much, and your answer brings up more questions (of course!). Is "MyPage" a new name that you can just make up, or is it the actual name of a property that is assumed to exist on the clipboard. And if we're just referencing clipboard properties, how does one test something like this? (In other words, to test it, i may not be in step 50 of the 30th stage or whatever of my overall process - how do I just set up data to run using this "MyPage" clipboard value?
I think "MyPage” can be made up if you want to create it. Like in Java you write
Where MyClass is the class and mypage is the name of the variable of type MyClass.
As I said, you can use Page-New to instantiate it or if it is already instantiated in the Clipboard, then you could just use it.
Usually you would probably want to write a pre-activity to create this page or load this page using an Obj-Open from the database or populate it via a connector from an external source etc. so that the data is in the clipboard before it is used.
So, Rajiv, this is where the Pega terminology confuses me. When you say
"I think "MyPage” can be made up if you want to create iI think "MyPage” can be made up if you want to create it."
that's the opposite of the answer you earlier gave, where you said
"The values in pages and classes are like defining variables of a certain class. They are not doing a "new”."
So either we are or we are not creating a new variable here, or we're just referencing pre-existing clipboard properties. This is why I am confused. Does the Pages & Classes tab exist just to define references, data types, etc, to existing clipboard values, or to define new variables to use? Or both? And if both, how do you tell whether something is assumed to be on the clipboard at run time or not?
Does the Pages & Classes tab exist just to define references, data types, etc, to existing clipboard values, or to define new variables to use? Or both? And if both, how do you tell whether something is assumed to be on the clipboard at run time or not?
It is both. Like in the OO world, defining the variable is not enough. How do you know in a method of the class whether the variable has been instantiated? You will check for "null" (mostly) or you will assume the constructor or some other method has done the initialization for you so that the method in the class can safely use that variable. When those assumptions break, in Java you end up with NullPointerException.
Coming the Pega platform world, it is the same. Mentioning something in the Pages and Classes means that the variable has been defined. You could explicitly instantiate it or you could assume that something else has populated it. You can check if this has already been instantiated using pageExists Rule-Utility-Function before actually referring to properties within it.
So the clipboard is like space (with the pega thread context) where all pages are available for use by different rules executing in that context. That is where it is different from standard OO.
Thanks Phani! Well, this is more of the "ask different people, get different answers". Your answer sounds like a "new" variable is being instantiated, others have said it's just referencing something already existing on the clipboard. Color me confused
as said earlier in the posts by Rajiv/Eric - declaring a page under Pages & Classes tab is used as reference to get the context and access to properties.
example: A page 'temp_NewCustomer' is of class (MyCo-Data-Customer)
Activity: CreateNewCustomer is created in class MyCo-Work
Step #1 Page-New temp_NewCustomer [declare the page 'temp_NewCustomer' under Pages & Classes tab]
Step #2 Property-Set temp_NewCustomer (step page) we would get access to all the properties & inherited properties in class 'MyCo-Data-Customer --> Data-Party --> Data- --> @baseclass' though we create the activity in work class.
so it will be .pyCity (MA)
Output: property 'pyCity' will have MA on clipboard page 'temp_NewCustomer'
please note ...
the declaration would help to get reference to properties during design time
from Pega 7 - if a step page is not declared under Pages & Classes tab & referred in a step would throw design time error on saving the activity rule
As a page without an absolute class would result in unknown errors.
"Mentioning something in the Pages and Classes means that the variable has been defined. You could explicitly instantiate it or you could assume that something else has populated it."
If it's already populated, why do I need to mention it again in the Pages and Classes tab? I can understand if i am truly creating something new, why that is necessary. But if i am just referencing an existing Clipboard value, why do I need to go define it again in Pages & Classes?
You might want to refer back to Eric's comment of putting a dot after the name of the page in the rule to get a list of properties.
To clarify further, when you are creating / updating a rule, you are at design time. While crafting the rule, you are referring to to variables (clipboard pages) which you believe will exist when you actually execute the rule (runtime). Since these pages may not exist at design time in the clipboard, but you do need to refer to properties under that page, you define the type (PRPC class) for it in Pages and Classes tab so that within the rule you can refer to properties under it using the dot notation as Eric pointed out. If you don't associate a type, you are essentially saying I don't know the type of this page so default it to any type which means when you put a dot after the page name, you will not be able to get the list of properties because we can't resolve it to the correct type.
Citing an example from the Java world where you are using an IDE (like eclipse) to write a Java class.
When you create a class and define variables in that class, you use the "ctrl + space” to get the list of methods or variables for that class while writing the code within your method. At the time of writing the code, those objects don't exist in memory. But when you execute the code, you assume (either by instantiation or by passing via reference / value) that the variable is initialized for use.
Just when I thought I understood that Pages & Classes refer to an already-existing value on the clipboard, per Rajiv Nistala and Eric Osman, I come across this article which shows creating something called "Operator" in the Pages & Classes tab, and acting on it as if it were a new variable/value/whatever:
"on the Pages & Classes tab, enter the name of a page that can hold the contents of the Operator ID record returned by the Obj-Open method."
By "can hold", what is meant here is "will hold". That's what's done in step 1 of the demonstrated activity.
To update Rajiv's answer above, you can also use methods like Obj-Open or Page-Copy to set the name of page, declared on the Pages & Classes tab. This is in keeping with the use of P&C similar to declarations in a traditional programming.
As Jon said, what you define in Pages and Classes are declarations which may have already been initialized previously or can be initialized using Rule-Method like Page-New, Obj-Open, Page-Copy etc. The clipboard unlike standard OO is not enclosed within the "class" but is a more global (restricted to current PRThread) space on which data has already been put by a previous rule or can be initialized by the current executing rule.
So - coming from a "traditional" programming background - can you give me an example or equivalent? I have never seen something where, when you look at it, you don't know if it is referring to an already-existing variable, or if it is declaring a new instance. Pretty much any language I've seen has a very clear distinction between these two.
>>> you don't know if it is referring to an already-existing variable, or if it is declaring a new instance
A specification in java saying “double average(double a, double b);” neither refers to already-existing method “average” nor declares method “average”. That specification says “if you call method average, give it two doubles as parameters, and it will return a double”. /Eric
That's what I'd call a reference - an interface definition is just a reference to a method, not the actual method itself. What it sounds like we're saying in pages & classes is both references and instantiations, hence my confusion
>>> What it sounds like we're saying in pages & classes is both references and instantiations, hence my confusion
I’ve never seen the pages-and-classes tab do “instantiation”. Here are some situations in which I’ve used it:
1) I mentioned my operator-record in the pages-and-classes tab of my activity, and then did some read operations from my operator-record in the steps tab of the activity. In this situation, there’s no instantiation at all. The operator page already exists as a requestor-wide-available page, and is shown in the clipboard viewer.
2) I mentioned a page called “mypage” in the pages-and-classes tab of my activity, specifying that its class is one of my data classes. I then instantiate page “mypage” on one of my activity steps either by doing page-new if I am making a new data object, or by using obj-open if I am opening an existing data object into page “mypage”.
Uh oh. If I said already-existing-value, I apologize. (Where did I say that ?) The pages-and-classes declares what class such-and-such a page will be, when and if such-and-such page gets created. The pages-and-classes tab makes no inference of whether the page exists, and makes no inference whether the page will be created or not. /Eric
Pages-and-classes merely describes some pages, it doesn’t create them, and it doesn’t define them.
I took "doesn't create" to mean, "this is not creating a new instance, but merely referencing existing" when I posed the "which does this do - reference or instantiate?" question. Sorry if I mis-characterized your answer...thanks again
My experience with pages-and-classes is that first, as I partially mentioned, it often assists with showing property name choices when you type either a page name or a non-scalar property name (i.e. an embedded page or page list), and then type a dot.
Secondly, there are times that I've gotten validation errors when I tried to save my activity and only by adding some of the embedded property names to pages-and-classes, was I allowed to successfully save the activity.
I suspect, although I've never proved, that the contents of the pages-and-classes tab would affect both of the above, but would not actually affect the generated java for the activity. Is this true ? One way to test examples is, on the activity rule form, click the coffee cup icon (or the java choice in the action dropdown for later Pega versions, which are you on again ?), and do that twice once with and once without pages-and-classes entries, to see whether the java is any different. /Eric
Regarding reports that have a class name but no page name in the pages-and-classes tab. I’m guessing that the lack of page name means “the primary page”. However, if it does, that needs to be documented ! (maybe it is already ?)
re: "Initially It's clear that "Pages & Classe"s help Pega limits what data to retrieve from memory AKA the clipboard."
It's clear? to whom? What are you basing this on? The Pages & Classes are not represented in the generated Java -- unless you're creating a page with Page-New, and you didn't specify the classname in the method parameters, so it's pulled from P&C.