The Strangely Behaved ATG textarea Tag

Escalera al cielo / Stairway to heaven on Flickr 
(Photo: Escalera al cielo / Stairway to heaven by Davichi)

When I create a DSP textarea tag like this it outputs the value of the bean property in the text area box.

<dsp:textarea bean="MyFormHandler.foo" rows="5" cols="20"/>

Similarly if I create a DSP textarea tag like this I get the same output.

<dsp:textarea bean="MyFormHandler.foo" rows="5" cols="20"></dsp:textarea>

However when I leave some space between the textarea opening and closing tag I get a blank instead of the value of the bean property in the text area box.

<dsp:textarea bean="MyFormHandler.foo" rows="5" cols="20">
</dsp:textarea>

Anyone know why there is a difference?

Anyway after reading the documentation it turns out if I want to control what is output in the text box I can use the default attribute.

<dsp:textarea bean="MyFormHandler.foo" rows="5" cols="20" default="bar"/>

Maybe I should have read the documentation before writing this post. 🙂

Update 2009-09-03: I also found this strange pattern of behavior with the DSP droplet tag.  When I invoked a droplet that took no parameters and had no open parameters like this:

<dsp:droplet name="MyDroplet"/>

or like this:

<dsp:droplet name="MyDroplet"></dsp:droplet>

the droplet would not be invoked.

However when I did this the droplet was invoked.  Strange …

<dsp:droplet name="MyDroplet">
</dsp:droplet>

Enums in Java

Slide-together : now with cards on Flickr
(Photo: Slide-together : now with cards by fdecomite)

Enums are highly useful data types introduced in Java SE 5.0.  Though I love using them I often forget the exact syntax so this post is to remind me later how to use it.

public enum Example {
  FOO,BAR
}

// create one using its name
Example myExample = Example.valueOf(“bar”.toUpperCase());

// if statement
if (myExample == Example.FOO) System.out.println(“FOO!”);

// switch statement
switch (myExample) {
  case FOO: System.out.println(“FOO!”);
  case BAR: System.out.println(“BAR!”);
}

// output as String using name
System.out.println(myExample.name());

For further reading please see Java’s Enums guide and Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects).

betweenGo Consults with Cineplex to Release Latest Version of Online Store on ATG

Cineplex Store

On Monday, August 30 Cineplex launched the latest version of its store running on ATG 2007.1 and JBoss 4.0.5.GA.

Cineplex ..:: Gift Cards betweenGo with Bell Canada was proud to be part of this release.  betweenGo implemented the handling of gift cards and product bundles and other eCommerce features.

Specific features we implemented for gift cards and product bundles included:

  • product listing
  • search listing
  • display in cart and throughout checkout
  • handling of taxes and shipping costs
  • promotions
  • inventory status
  • adding gift cards to the cart (required some JavaScript magic

Other features we implemented included:

  • lightbox to display after login if user’s cart has been modified to include items from their last session
  • fixed order transaction issues

betweenGo was proud to be part of this enjoyable project.  If you need expert ATG consulting please contact us.

How to Set an Array Property in an ATG Form

Cool Blue Hive on Flickr
(Photo: Cool Blue Hive by jurvetson)

In the Setting Property Values in Forms section of the ATG Page Developer’s Guide there are two examples for setting values of array properties in forms.

  1. Grouped Checkboxes
  2. Multiple-Selection List Box

Both examples are for a simple form.  But what if you are generating a form using a ForEach droplet and want to set an array property in each iteration of the loop.  Fortunately it turns out to be relatively easy.

Hidden or Text Inputs

<dsp:droplet name="/atg/dynamo/droplet/ForEach">
  <dsp:oparam name="output">
    <dsp:input type="hidden" paramvalue="element.id" bean="MyFormHandler.ids"/>
  </dsp:oparam>
</dsp:droplet>

Select Inputs

<dsp:droplet name="/atg/dynamo/droplet/ForEach">
  <dsp:oparam name="output">
    <dsp:select bean="MyFormHandler.answers">
     <dsp:option value="foo">foo</dsp:option>
     <dsp:option value="bar">bar</dsp:option>
    </dsp:select>
  </dsp:oparam>
</dsp:droplet>

By the way if you try to set the array element directly using the param:index notation as in the following example it will not work.

<dsp:droplet name="/atg/dynamo/droplet/ForEach">
  <dsp:oparam name="output">
    <dsp:select bean="MyFormHandler.answers[param:index]">
     <dsp:option value="foo">foo</dsp:option>
     <dsp:option value="bar">bar</dsp:option>
    </dsp:select>
  </dsp:oparam>
</dsp:droplet>

When submitting the above form you will get this exception.

atg.droplet.DropletException:
  Can't set an element of the array property without a set <name> (int index, Object value) method.

The exception message is a red herring, there is no way you can set the element of an array property no matter what kind of set method you create.  Trust me, I spent many hours delving into the ATG code to verify this. 🙂

SQL*Plus Commit on Exit

EXIT on Flickr

I was always doing a commit before exiting SQL*Plus when it occurred to me today that maybe I didn’t need to do that.  Doing a Google search quickly answered that for me.

If you issue a graceful exit (via the “exit” or “quit” command), sqlplus will always issue a commit. However, if you were to be ungracefully disconnected, for example by closing your terminal window, then PMON will issue a rollback like it does with any other disconnected session.

sqlplus commit-on-exit?

Therefore there is no need to do a commit before you exit.

You can also set autocommit on, it is off by default, but I would not recommend doing this.

During interactive usage with sqlplus, Oracle also supports an AUTOCOMMIT option. With this option set to ON each individual SQL statement is treated as a transaction an will be automatically commited right after it is executed. A user can change the AUTOCOMMIT option by typing

 SET AUTOCOMMIT ON

or

 SET AUTOCOMMIT OFF

whereas by typing

 SHOW ALL

a user can see the current setting for the option (including other ones).

Oracle SQL Transactions

Twitter Weekly Updates for 2009-10-15

  • How to Debug an InvalidVersionException from Updating an ATG Order. Eclipse debugging and JSP debug code. http://bit.ly/MUMIH #
  • How to Debug an InvalidVersionException from Updating an Order in @ATG_ecommerce. Eclipse debugging and JSP debug code. http://bit.ly/MUMIH #
  • ATGLogColorizer for Colorizing ATG Server Outputs and Logs. Color is wonderful. Red means errors, yellow means warnings. http://bit.ly/IQLBv #

Duplicating and Modifying Eclipse User Libraries

Twilight books on Flickr

Eclipse user libraries are wonderfully convenient ways of packaging together related JAR files.  In my Eclipse I create user libraries for each ATG version I install.  As a consultant I am always installing different versions and today I installed ATG 9.0.

Normally I use the GUI to create the user library for the latest ATG server.  However I thought this is quite inefficient because I already have user libraries for previous versions of the ATG server.  I just need to duplicate one of the other ATG user libraries and then tweak the duplicate to have the right path to the JAR files.

Unfortunately the Eclipse GUI does not provide a way to duplicate a library.  So I searched in my workspace files and found in my .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs file the settings for all my user libraries.

I then edited that file and copied an entry for an older ATG library, org.eclipse.jdt.core.userLibrary.ATG\ 2007.1.  I renamed it org.eclipse.jdt.core.userLibrary.ATG\ 9.0 and updated the paths to where ATG 9.0 is installed and I was done!

ATGLogColorizer for Colorizing ATG Server Outputs and Logs

ATGLogColorizer

Color is wonderful.  With color we can immediately recognize patterns, signals, warnings, etc.  By using a utility that color codes your logs and server outputs to highlight errors in red, warnings in yellow, etc. you can be much more efficient about how you monitor and search.

Back in the day we used to use DynamoFilter.exe to color code the output of running ATG on the Dynamo Application Server (DAS).  Now that people no longer use DAS that application is no longer useful.

Today though I found out about the open source project ATGLogColorizer.  This fantastic utility works with JBoss, WebLogic, DAS and WebSphere.  It works on Windows, Mac OSX, Solaris and other UNIX variants.  It even works on Cygwin.

This is how I start JBoss with ATGLogColorizer on Cygwin.

${ATG}/home/bin/startDynamoOnJBOSS.bat -f -run-in-place -c default -m Foo | ATGLogColorizer.exe'

And this is how I start JBoss with ATGLogColorizer on Mac OS X.

${ATG}/home/bin/startDynamoOnJBOSS.sh -f -run-in-place -c default -m Foo | ATGLogColorizer_v1_2_OSX'

Life has become a little better. 🙂

For further reading please see and ATGLogColorizer and ATG Log Colorizer for JBoss.

How to Debug an InvalidVersionException from Updating an ATG Order

I thought I saw a puddy cat.... on Flickr

If you ever update an order outside of a transaction then the next time you update it within a transaction you will get the infamous, dreaded InvalidVersionException.

WARN  atg.commerce.order.ShoppingCartModifier
atg.commerce.order.InvalidVersionException: This order (o3830002) is out of date. Changes have been made to the order and the operation should be resubmitted. Order version 333, Repository item version 334.
   at atg.commerce.order.OrderManager.updateOrder(OrderManager.java:2557)

For example this could happen if you update your order in your JSP page.

<dsp:setvalue bean=”order.foo” value=”bar” />

To fix this problem you must always make sure to update an order within a transaction like this.

Transaction tr = null;
try {
  tr = ensureTransaction();
  synchronized (getOrder()) {
    getOrder().setFoo("bar");
    try {
      getOrderManager().updateOrder(order);
    }
    catch (Exception exc) {
      processException(exc, MSG_ERROR_UPDATE_ORDER, pRequest, pResponse);
    }
  }
}
finally {
  if (tr != null) commitTransaction(tr);
}

In some cases you might find a method is called within a transaction by another method and in other cases it is not.

public boolean handleFoo(DynamoHttpServletRequest req, DynamoHttpServletResponse res) {
  Transaction tr = null;
  try {
    tr = ensureTransaction();
    synchronized (getOrder()) {
      setFoo("bar");
      try {
        getOrderManager().updateOrder(order);
      }
      catch (Exception exc) {
        processException(exc, MSG_ERROR_UPDATE_ORDER, pRequest, pResponse);
      }
    }
    return checkFormRedirect(getSuccessUrl(), getErrorUrl(), req, res);
  }
  finally {
    if (tr != null) commitTransaction(tr);
  }
}

public void setFoo(String foo) {
  getOrder().setFoo(foo);
}

In the above example the handleFoo method properly updates the order within the transaction.  However calling the setFoo method directly will cause a problem since the order is not updated within a transaction.  To fix this you use the same pattern again to ensure the order is updated within a transaction.  It is okay to do this more than once during a request.

To debug this problem you can use Eclipse to make sure that wherever you update an order is always within a transaction. You can use the debugger to find which methods are called and/or you can use the call hierarchy to find out how methods are called.

Another way to help debug this is adding JSP code similar to the one I list below. It outputs the version of the order that the form handler has and the version that is in the repository.  If there is a difference then you know that the action you took before at some point updated the order outside of a transaction.

<dspel:getvalueof bean="ShoppingCartModifier.order.id" var="orderId" />
FORM HANDLER ORDER ID: ${orderId}<br/>
FORM HANDLER ORDER VERSION: <dsp:valueof bean="ShoppingCartModifier.order.version" /><br/>
<dsp:droplet name="/atg/dynamo/droplet/RQLQueryForEach">
  <dsp:param name="queryRQL" value="ID IN { \"${orderId}\" }"/>
  <dsp:param name="repository" value="/atg/commerce/order/OrderRepository"/>
  <dsp:param name="itemDescriptor" value="order"/>
  <dsp:oparam name="output">
    REPOSITORY ORDER VERSION: <dsp:valueof param="element.version"/><br/>
  </dsp:oparam>
</dsp:droplet>

For further reading please see Nabble – ATG Dynamo – Commerce Assist Returns and the Transaction Management section in the ATG Programming Guide.

Twitter Weekly Updates for 2009-08-16

  • JavaScript Invalid Argument in Internet Explorer Only. You can't have spaces in windowName argument of window.open method. ://bit.ly/5JUZk #
  • ATG Currency Converter Not Working With JSTL c:set. Debugging with Eclipse helped solve the problem. http://bit.ly/kMmSV #
  • SugarSync promo ends 8/31. Sign up for free service and we each get 500 MB more. http://bit.ly/5Lu69 Why I like it lots http://bit.ly/17UwyP #