Question

I'm new to ATG, and I've only been able to install ATG v10.2 successfully with JBoss.
However, since creating components and modules in ATG can be done in different ways, so I would like to know if there's any "Hello World" example for both module and component.

I have already searched in Google, but the different articles present in Internet don't mention point-wise in details, in a sequential manner.
So it will be great, if people can detail out the steps for a newbie, as I at least need to get started with one example, which I can later use as a base for other complex ones.

Thanks a lot to every one out there!

Note:-
I also know J2EE and MVC to some extent, where I can submit forms and save the user-input data to DB, without any significant issues.
I'm also going through the ATG Page Developer Guide at this moment.

Was it helpful?

Solution

There are so many concepts in ATG, that makes coming up with Hello World program little difficult. Do you mean to create one JSP page and deploy it like commerce reference store? Do you want to create a component just to see in Dyn/Admin? Do you want to create a hello world repository? Depending on what you want to do, the approach to take will be different.

To work with ATG, you don't have to know about saving values in database. If you approach ATG programming with J2EE & MVC experience, you may find it little difficult to cope with it unless you start with a fresh mind, because things are very different in ATG.

As @radimpe covered creating a hello world droplet, I will show how to create a simple component so that it can be viewed in Dyn/Admin.

Creating a HelloWorld component: That just appears in DynAdmin Create an Eclipse project with following structure.

Elipse project structure

Following is the content of each of the file shown in the above screenshot

HelloWorldComponent.java

package com.buddha.components;

import atg.nucleus.GenericService;
import atg.nucleus.ServiceException;

public class HelloWorldComponent extends GenericService {

    public String firstStr = "Dummy Value"; /* This value will be overwritten */

    public String getFirstStr() {
        return firstStr;
    }

    public void setFirstStr(String firstStr) {
        this.firstStr = firstStr;
    }

    @Override
    public void doStartService() throws ServiceException {
        super.doStartService();
        System.out.println("Hello ATG Component!");
    }

    @Override
    public void doStopService() throws ServiceException {
        super.doStopService();
        System.out.println("Hello ATG Component! Stops now!");
    }
}

Manifest.MF

Manifest-Version: 1.0
ATG-Required: DafEar.Admin 
ATG-Config-Path: config/
ATG-Class-Path: ./bin/ 

HelloWorldComponent.properties

$class=com.buddha.components.HelloWorldComponent
firstStr=HelloWorld

Build the project and copy the project folder into ${DYNAMO_ROOT} and run the following command to generate an ear file of your project and deploy it in your jboss server.

runAssembler.bat -jboss HelloWorld.ear -m EXP_HelloATGComponentWorld

Navigate to Dyn/Admin and search for the component HelloWorldComponent and click on the component listed in the search results.

SearchResults of the component we have just created

Click on it to go to the component page to see the property we have created and its value given in properties file. Component Property we have created

You can observe the log as something like this 21:53:00,485 INFO [stdout] (http-/0.0.0.0:8080-1:ipaddr=127.0.0.1;path=/dyn/admin/nucleus//com/buddha/components/HelloWorldComponent;sessionid=gT4bmHj5WKs1Rf85GN0Z+9Qu) Hello ATG Component! This line is generated because of the sysout in our doStartService(); You can also give other methods that can be called through dyn/admin or interact with other components. Best of Luck.

Source: Creating a component in Oracle Commerce Platform

OTHER TIPS

This is quite a broad topic and, in general, the Hello World example will only get you started with getting some text rendered on the screen. Most of your front-end interaction would happen with FormHandlers and Droplets of which the Droplet will get you the Hello World text on the screen. So lets start with that.

<%-- JSTL --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%-- DSP --%>
<%-- This tag library represents the ATG tags --%>
<%@ taglib prefix="dsp" uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0" %>

<%-- All, non-static includes will have a wrapping page tag --%>
<dsp:page>
  <%-- A droplet is almost like a servlet, and here you include the name of the droplet you want to call --%>
    <dsp:droplet name="/com/acme/droplet/HelloWorldDroplet">
    <%-- An 'output parameter' matches the name of the 'service parameter' in your droplet. You can have multiple of these --%>
     <dsp:oparam name="output">
       <%-- The 'param' matches the name of the 'setParameter' in your droplet and can also be assigned to a jstl variable below --%>
       Hello <dsp:valueof param="toWhom" />
     </dsp:oparam>
  </dsp:droplet>
</dsp:page>

Now create a 'component'. This is the property file that will map between the JSP page and the CLASS file (ie. you reference this in the droplet name)

File: /com/acme/droplet/HelloWorldDroplet.properties

$class=com.acme.droplet.HelloWorldDroplet
$scope=global

And now create your Java file: (/com/acme/droplet/HelloWorldDroplet.java)

public class HelloWorldDroplet extends DynamoServlet {

    public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws ServletException, IOException {
            //This will allow you to pass a parameter to the droplet eg: hello.jsp?who=Peter
        String who = pRequest.getParameter("who");

        //Do a check on whether to display the default value or the one passed in
        if (StringUtils.isEmpty(who)) {
            //'toWhom' is the name of the param on the JSP page
            pRequest.setParameter("toWhom", "World");
        } else {
            pRequest.setParameter("toWhom", who);
        }
        //'output' is the name of the 'oparam' on the JSP page.
        pRequest.serviceParameter("output", pRequest, pResponse);
        }
}

Hopefully that will be enough to get you started.

You can also have a look at below page.. it well explains the concept of What Actualy is a component and how can we use it.. http://learnoracleatg.blogspot.in/2014/10/art108-extending-out-of-box-components.html

You can also start right from the basics by pressing the "The Basics" button on the navigation bar.. it explains the concepts really well..

Check http://www.asknsay.com/creating-new-atg-project-in-eclipse.html for creating new application in atg from scratch using eclipse. It also covers how to deploy it in JBOSS 6.1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top