Contact

Technology

May 25, 2012

Most Common ATG Beginner Mistakes

Rachel Walzl

Rachel Walzl

Default image background

There are three mistakes ATG beginners frequently make:

  • Using a parameter that is out of scope

  • Forgetting to import a Droplet or Form Handler

  • Not including a set method when injecting parameters into Droplets and Form Handlers

If you are new to ATG, becoming familiar with these pitfalls can save you hours of trouble shooting.  Alternatively if you are an ATG pro, you may want to send these to newbies who join your team.

Common Mistake 1: Attempting to use a parameter that is out of scope

By default a parameter set by a Droplet can only be used within the Droplet’s oparams.  In the example below let’s assume that the MyDroplet sets the parameter x to ‘Hello’.  When the code is executed only the first ‘valueof’ instance will display the ‘Hello’ text.  The second ‘valueof’ instance will display nothing.  Since the second time x is referenced is outside of the oparam its value would be null.

<dsp:droplet name=“/project /droplet/MyDroplet”>

<dsp:param name=“value” param=“value”/>

<dsp:oparam name=“output”>

<dsp:valueof param=“x”/>

</dsp:oparam>

</dsp:droplet>

<dsp:valueof param=“x”/>

There are many instances where you will want to reference a parameter set by a Droplet outside of the Droplet’s oparam.  When these occasions occur you can set a JSTL parameter as shown here:

<dsp:droplet name=“/project /droplet/MyDroplet”>

<dsp:param name=“value” param=“value”/>

<dsp:oparam name=“output”>

<dsp:getvalueof param=“x” var=”xValue”/>

</dsp:oparam>

</dsp:droplet>

${xValue}

__

Common Mistake 2: Importing Droplets__

It is easy to forget to include an import Droplet statement at the top of the jsp especially if you are cutting and pasting snippets of code from one JSP to another.  Here is an example of a jsp which will not compile:

<dsp:droplet name=“Switch”>

<dsp:param name=“value” param=“loggedIn”/>

<dsp:oparam name=“true”>

<jsp:include page=“/personalizedWelcome.jsp”/>

</dsp:oparam>

<dsp:oparam name=“default”>

Welcome Guest

</dsp:oparam>

</dsp:droplet>

The error can be resolved by either importing the Droplet at the top of the page like this:

<dsp:importbean bean=“/atg/dynamo/droplet/Switch”/>

<dsp:droplet name=“Switch”>

<dsp:param name=“value” param=“loggedIn”/>

<dsp:oparam name=“true”>

<jsp:include page=“/personalizedWelcome.jsp”/>

</dsp:oparam>

<dsp:oparam name=“default”>

Welcome Guest

</dsp:oparam>

</dsp:droplet>

The issue can also be resolved by referencing the Droplet path when using the Droplet as so:

<dsp:droplet name=“/atg/dynamo/droplet/Switch”>

<dsp:param name=“value” param=“loggedIn”/>

<dsp:oparam name=“true”>

<jsp:include page=“/personalizedWelcome.jsp”/>

</dsp:oparam>

<dsp:oparam name=“default”>

Welcome Guest

</dsp:oparam>

</dsp:droplet>

__

Common Mistake 3: Including a Set when Injecting a Property__

Injection in ATG is simple.  First create the parameter you would like to inject in your Droplet or FormHandler:

public class MyDroplet extends DynamoServlet {

private Repository productCatalog;

public void service( DynamoHttpServletRequest req, DynamoHttpServletResponse res ) throws ServletException, IOException{

}

}

Then update the class’s properties file with the injected parameter:

$class=com.project.droplet.MyDroplet

$scope=request

productCatalog=/atg/commerce/catalog/ProductCatalog

The pitfall new developers run into most frequently is forgetting the get and set method.  In this scenario, your tipoff is running into a Null Pointer exception when attempting to access the injected parameter.  Keep in mind that spelling counts.  If the set method doesn’t match the parameter name exactly you will run into the same issue.   Here is what the code should look like:

public class MyDroplet extends DynamoServlet {

private Repository productCatalog;

public void service( DynamoHttpServletRequest req, DynamoHttpServletResponse res ) throws ServletException, IOException {

}

public Repository getProductCatalog() {

           return productCatalog;

}

public void setProductCatalog(Repository productCatalog) {

this.productCatalog = productCatalog;

}

}

Hopefully being aware of these pitfalls will save you time and frustration. As always, don’t hesitate to contact me or Credera if you need help with your next ATG implementation. Best of luck to you on your ATG journey!

Conversation Icon

Contact Us

Ready to achieve your vision? We're here to help.

We'd love to start a conversation. Fill out the form and we'll connect you with the right person.

Searching for a new career?

View job openings