Why do we need to extend a component??
Consider a situation, when there is a OOTB component. By layering configuration files we can only change the existing property values of the component. But what if we need to add some new properties to the same component? Or there could be situation when we need to add some methods to an existing component Or override the method of existing component. These tasks cannot be done alone by configuration files, addition of new properties/methods requires class-level modifications. To accomplish this we extend the component.
The answer is even simpler..
For example, if we need to extend OOTB ProfileFormHandler component, we should know that its nucleus path is :
/atg/userprofiling/ProfileFormHandler.
Now, let us assume, that our component "Person" existing at location "/atg/commerce/Person" and is out of the box. So, our assumed "Person" component is same as we discussed in ART#104 - ATG Components. Now our assumed out-of-the-box "Person" component's properties file looks like (this can be seen in dyn/admin):-
$class=com.mypackage.Person name=Stephen age=20
Now that we know where our component exists, and what are its properties, we need to follow the below steps:-
- Extend the class: Since addition of properties/methods has to be done at class level, we need to extend the class this component is referring to. Next, we have to extend it and add our custom code. Our OOTB component "Person" refers to com.mypackage.Person class. Therefore, we will now extend Person class and add our custom code. In the below example, we are adding an additional property "gender" to our extended class.
- Now that we have extended the person class, we need to do two things:-
- Layer our configuration file at the same location as OOTB component. i.e. /atg/commerce/Person (in our module's config-path).
- Override the $class nucleus property to use our custom (extended) class, to tell the component to use extended class instead of the original class; so that the new property "gender" is accommodated. (New methods can also be written in this class OR existing methods of "Person" class can be overridden if needed)
- Next, we provide the value to our very own newborn variable "gender".
Now, our OOTB atg component uses our custom class, with newly set-properties. Similarly, other components can be easily extended.
Let us move on.. and understand a new topic of ATG, known as droplets or dynamo servlet beans...
I am able to View the components created in eclipse ATG browser,But I am not able to view the ATG module i have created in Dynamo admin.Could you please help me out
ReplyDelete1. Firstly, dyn/admin would not show any components which are not initialized.
Delete2. You can initialize a component in two ways:-
a. Mentioning the component in initialServices [Click HERE]
b. Hitting the component directly in dyn/admin instead of searching.
For example, you created a component /com/myfolder/MyComponent.properties, you can hit the URL:-
http://[hostname]:[port]/dyn/admin/nucleus/com/myfolder/MyComponent
3. If you can see your component, then you're good. If not, then you have not assembled your application correctly.
Please let me know if it solves the problem.
Hi Monis,
ReplyDeleteI have a question. If we have 2 components lets say ExtendedPerson1 and ExtendedPerson2. Both are extending Person component. I have "gender" propery in ExtendedPerson1 and "region" property in ExtendedPerson2. I want both properties added to the OOTB (Person) component. Then how can i declare the class property of Person component?I mean how can we add both components (EP1 and EP2 ) to Person component through class variable?
Hi,
DeleteYou cannot do that. There is no way to add to classes to a component.
For a component to set a property, you need to have a property at class level.
In your example, you have a class "Person", two subclasses viz.:
1. ExtendedPerson1 : Having "gender" property
2. ExtendedPerson2 : Having "region" property
Now, you are creating a component named "MyPersonComponent".
For this component, you would have to specify a class.
If you choose ExtendedPerson1, you'll be able to set "gender" property and NOT "region" property.
If you choose ExtendedPerson2, you'll be able to set "region" property and NOT "gender" property.
To have access to both the properties, you'll have to create both "gender" and "region" properties into a single subclass e.g.
ExtendedPerson -> which has both properties.
Now, when you create a component, you can set the class as "ExtendedPerson" and have both properties.
I am not sure why you'd want a single component to use multiple classes. If you could tell me your functional requirement, i'll be able to help you better with the design pattern.
ofcourse i can use both variables (gender and region)in same class (ExtendedPerson1). Can i do it with 2 components?Just like extending a class by two different classes..
ReplyDeleteYes, you can use the same class for different components.
DeleteBut, these will be exact copies of each other. Therefore, this does not seem a good design pattern.
Let me know your functional requirement, so i'll be able to help you better.
I am not clear about your comments "Layer our configuration file at the same location as OOTB component. i.e. /atg/commerce/Person (in our module's config-path).". There is one OOB property file Person.properties at location : /atg/commerce/Person. Our customized property is to be copied at /atg/commerce/Person location then it will not override the file present OOB.
ReplyDeleteHi,
DeleteMe statement means that the component path should be same as the out of the box path, but it should be present in your config path.
Once you have a file there, you can easily override properties.
Hello Monis
DeleteI bumoed into this article while looking for a solution where i have overriden a OOTB component but its properties are not loaded in 1 env , however with same config it is loaded in another env Can you please have a look
https://community.oracle.com/thread/3886793
Thanks
PC
Hi,
DeleteCan you open this component in dyn/admin, click on "View Service Configuration" and send me the full screenshot.
Do this for both the environments and send across the screens.
Hi Monis,
ReplyDeleteCould you please tell the steps that i need to follow to customize the OOTB CRS module. I installed CRS. But i am not able to customize it by creating my own module. Could you please help in creating my own module using CRS.
Thanks,
Yousuf.
For that, you'll have to create a new ATG module on top of existing CRS installation.
DeleteI will hash out the details in upcoming articles.
Thanks Monis for the details. Could you please list out the steps so that i can start with my custom module.
ReplyDeleteYou can refer the details here: http://learnoracleatg.blogspot.in/p/setup.html
DeleteThis comment has been removed by a blog administrator.
ReplyDeleteWhy is the config file named "Person.properties" instead of "ExtendedPerson.properties"? Where are the Person properties' values defined if the config file is completely overridden?
ReplyDeleteThis is because we are layering the existing component (Person.properties).
DeleteWe have assumed that Person.properties exists out of the box. We are just overriding its class and properties.
SEVERE: javax.servlet.ServletException: Error encountered while initializing Nucleus servlet: R
ReplyDeletejavax.servlet.ServletException: Error encountered while initializing Nucleus servlet: Required
at atg.nucleus.servlet.NucleusServlet.initializeAppLauncher(NucleusServlet.java:2201)
at atg.nucleus.servlet.NucleusServlet.initBigEarNucleus(NucleusServlet.java:938)
at atg.nucleus.servlet.NucleusServlet.init(NucleusServlet.java:465)
at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelpe
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:3
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:6
at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.
at weblogic.servlet.internal.StubLifecycleHelper.(StubLifecycleHelper.java:48)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:539)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.j
at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletCo
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3153)
Can someone Please help me rsolving the above error please. :(
This is not the complete error. I assume you have modified Intial.properties file and added a new component, which is not being initialized. Send across the copy of your Initial.properties, you might not have written the component path correctly.
DeleteHi,
ReplyDeleteIn ATG 10,the pluggin is sucsfully installed while coming to the ATG module is not created