Specifying the Calculator per Promotion

calculator on Flickr

(Photo: calculator by ansik)

ATG’s documentation, as far as I can tell, does not document how to specify the calculator for a promotion.  Promotion’s have a repository property called pricingCalculatorService.  In the ACC you won’t see it by default but you will see it if you show expert-level information.  Also you can see it configured in the Promotion repository (/atg/commerce/pricing/Promotions).

Having a repository property for each promotion allows you to specify different calculators for different promotions.  But typically you will probably specify the same one for the same class of promotion, e.g. /betweengo/commerce/pricing/calculators/ItemDiscountCalculator.

ATG Confirm Password Bug in ProfileFormHandler

Long-billed Curlew (Numenius americanus) birds on Morro Strand State Beach during a golden sunset. Also characteristic of Montana de Oro area to the south. | Flickr

Long-billed Curlew birds by mikebaird

Hi ATG Support,

I noticed a bug in how ATG’s ProfileFormHandler (ATG Java API) handles confirm passwords when creating a new profile.  Note that this bug happens only if you persist anonymous profiles.

During registration when you call handleCreate it calls createProfileItem and then updateProfileAttributes. In updateProfileAttributes it checks if the password matches the confirm password. If they don’t match it adds a form exception.

However at this point it has updated the profile attributes including the login. Therefore after the user sees the error about the passwords not matching, corrects it and resubmits the form she will see an error that the login is already taken.

The work around is to set creatNewUser to true but since the default value is false most developers will see this bug.

Update 12-22-2010: ATG confirmed this is a bug.

Hi Frank,

Thanks for the information and details. I’m glad that using ProfileFormHandler.createNewUser=true works for you. You might want to periodically check the size of the dps_user table and purge the anonymous profiles, if needed.

For your reference, I have created PR#DPS-167714 “ProfileFormHandler Confirm Password” to track the issue.

Kind Regards,
Kristi Coleman

Load ATG Order

Crystal Ball | FlickrCrystal Ball by David Reece

You can always look up an order in the repository using it’s ID.  But then you want to use the properties of this order object you will always be calling getPropertyValue and casting it to the type you expect.

A better and much simpler way is to look up the order using the OrderManager.  Then you get a strongly typed Order object and don’t have have to deal with the repository.  Life has become a little easier. 🙂

OrderManager orderManager = getOrderManager;
Order order = orderManager.loadOrder(orderId);


Now that you have the order you can also get the profile for that order.

RepositoryItem profile = getProfileTools().getProfileForOrder(order);

Turning on Secure for ATG Applications

Closed for business | FlickrClosed for business by maistora’s Photostream | Flickr

Almost all web applications have some parts of their site they want to be secure such as login and profile pages.

To enable security ATG has a ProtocolSwitchServlet, located at /atg/dynamo/servlet/dafpipeline/ProtocolSwitchServlet. Set the enable property to true and configure the other properties appropriately.

The only other properties that you will need to configure are the secureList property and the ignoreList property.  Examples of how these properties would be configured follow.

secureList=/myapp/account,/myapp/checkout
ignoreList=/myapp/css,/myapp/javascript

Optionally you might want to change the secureHostName and the httpsPort but typically it would be better to change siteHttpServerName and httpsPort respectively in /atg/dynamo/Configuration.

The default values for the other properties should be fine.

ATG Log Error from JSP Page

"The page cannot be displayed" | Flickr

"The page cannot be displayed" by Peter Kaminski

Unlike this IKEA sign, you usually don’t want to display errors on your web pages.  ATG allows you to log errors to the server log from a JSP page.  Below is an example of how to do this.  In this case if we find the price is null we log an error to the server log.

<dsp:getvalueof id="price" idtype="java.lang.Double" param="currentItem.priceInfo.amount">
<%
if (price == null) {
atg.servlet.DynamoHttpServletRequest dreq = atg.servlet.ServletUtil.getDynamoRequest(request);
dreq.logError("price is null!”);
}
%>
</dsp:getvalueof>

Set ATG Repository Item Date or Timestamp Properties to the Current Time

*Time* Ticking away... on Flickr *Time* Ticking away… by Michel Filion

This is a neat trick for automatically setting a date or timestamp property to the current time.  I learned it while perusing the ATG Repository Guide.

Date and Timestamp Properties

A repository item can use properties whose values are dates or timestamps, with the value set to the current date or time, using the java.util.Date, java.sql.Date, or java.sql.Timestamp classes. You can have a property whose value is set to the current time or date at the moment a repository item is created. You can do this by setting the feature descriptor attribute useNowForDefault. For example:
[xml]<property name="creationDate" data-type="timestamp">
<attribute name="useNowForDefault" value="true"/>
</property>[/xml]
For more information about this technique, see the Assigning FeatureDescriptorValues with the <attribute> Tag section in this chapter.

Set ATG Property And Popup Window After Clicking on Link

la cuarta ventana on Flickrla cuarta ventana by bachmont 

Sometimes when you click on a link in an ATG JSP/DSP page you want a property of an ATG component to be set as well.  For example:

[xml]<dsp:a href="foo.jsp">Foo
<dsp:property bean="BarFormHandler.baz" paramvalue="index"/>
</dsp:a>[/xml]

What gets tricky is if you also want a popup window to display the contents of this link.

The Wrong Way

I tried adapting the instructions from the tutorial Popup Windows | open new customised windows with JavaScript.

[xml]<dsp:a href="javascript:poptastic(‘foo.jsp’);">Foo
<dsp:property bean="BarFormHandler.baz" paramvalue="index"/>
</dsp:a>[/xml]

This does not work, i.e. the setter for baz in BarFormHandler is never called.

The Brute Force Way

I then reverted to the original DSP and looked at the outputted HTML.  Based on that I updated the DSP like this.

[xml]<% atg.servlet.DynamoHttpServletRequest dreq = atg.servlet.ServletUtil.getCurrentRequest(); %>
<a href="javascript:poptastic(‘foo.jsp?_DARGS=/betweengo/test.jsp_AF&_dynSessConf=<%= dreq.getSessionConfirmationNumber() %>&_D%3A/betweengo/BarFormHandler.baz=+&/betweengo/BarFormHandler.baz=<dsp:valueof param="index" />’);">Foo</a>[/xml]

This works but is grotesque.

The Good Idea That Did Not Work

Then I realized I could just set a parameter in the URL and have the form handler use the value to set the property.

[xml]<a href="javascript:poptastic(‘foo.jsp?index=<dsp:valueof param="index" />’);">Foo</a>[/xml]

And in BarFormHandler

public boolean beforeSet(DynamoHttpServletRequest req,
            DynamoHttpServletResponse res) throws DropletFormException {

  String indexParam = request.getParameter("index");
  setIndex(Integer.parseInt(indexParam));

  return super.beforeSet(request, response);
}

This did not work plus I did not really like it because now I have a beforeSet method that is called for every single request.

The Winner

I then realized I did not read the tutorial Popup Windows | open new customised windows with JavaScript carefully.  There is a more elegant way to call the JavaScript which degrades gracefully for browsers that don’t support JavaScript.

[xml]<dsp:a href="foo.jsp" onclick="poptastic(this.href);return false;">Foo
<dsp:property bean="BarFormHandler.baz" paramvalue="index"/>
</dsp:a>[/xml]

This works, is elegant and requires just adding the onclick attribute to the original DSP.

Enabling non-XA Resources in JBoss 4.2 with ATG

a dog and it's boss on Flickr
(Photo: a dog and it’s boss by Pixel Addict)

ATG documents how to enable non-XA resources in JBoss 4.2 for SOLID.  We ended up following the same instructions to work with Oracle.

JBoss Note: JBoss 4.2 by default assumes XA drivers, which some ATG applications use; however, there are no XA drivers for SOLID. To enable multiple non-XA resources in JBoss 4.2, add the property to the jbossjta-properties.xml file, under the “arjuna” property tag:

[xml]<property depends="arjuna" name="jta">
<property name="com.arjuna.ats.jta.allowMultipleLastResources" value="true"/>[/xml]

You may still see warnings in your log file, but ATG applications will run correctly. To suppress these warnings, add the following to your jboss-log4j.xml file:

[xml]<category name="com.arjuna.atg.jta.logging">
<priority value="ERROR"></priority>
</category>[/xml]

For further reading please see Starting the SOLID SQL Database document in the Running Nucleus-Based Applications section of the ATG Installation and Configuration Guide.

Configuring ATG to Send Email via Comcast SMTP

When you are developing at home you will probably need to configure your ATG application to send email via your ISP’s SMTP server.  Here is how I configured ATG to send email via Comcast’s SMTP server.

First you need to update ATG’s configuration to point to the Comcast SMTP server by modifying {ATG}/home/localconfig/atg/dynamo/Configuration.properties.

emailHandlerHost=smtp.comcast.net
emailHandlerPort=587

Typically you don’t need to set the emailHandlerPort, it is by default set to port 25.  But Comcast has recently been switching over to use port 587 because email viruses use port 25 on infected computers.

Next you need to update ATG’s SMTP Email service configuration by modifying {ATG}/home/localconfig/atg/dynamo/service/SMTPEmail.properties.

defaultFrom=betweengo@comcast.net
username=betweengo@comcast.net
password=betweengo

These values used to be optional but now are required because Comcast requires authentication as part of its increased security.