Submitting an ATG Form Using a Text Link

It has always bedeviled me how to submit an ATG form using a text link. I have asked many people about this but no one seems to know. Finally with the help of ATG support I figured it out.

Below is a simple example of how to do it. The trick is the hidden submit input which triggers ATG to call the handleSubmit method of the form handler.

<%@ taglib uri="/dspTaglib" prefix="dsp"%>

<dsp:page>

<script>
  function submit(form) {
    form.submit();
  }
</script>

<dsp:form action="<%=request.getRequestURI()%>" method="post" name="testForm">

  Foo: <dsp:input type="text" bean="TestFormHandler.foo"/>

  <p><a href="javascript:submit(document.testForm)">Submit</a>

  <dsp:input type="hidden" bean="TestFormHandler.submit" value="Submit"/>

</dsp:form>

</dsp:page>

You can also invoke the JavaScript like this:

  <p><a href="#" onclick="submit(document.testForm); return false;">Submit</a>

JSP Dynamo Request Retrieval

In JHTML pages, the request object is of class DynamoHttpServletRequest which has many methods that are not part of the HttpServletRequest interface including the very useful resolveName method for looking up components in Nucleus.

In JSP pages on ATG there is no guarantee that the request object is of class DynamoHttpServletRequest. According to the JSP specification the request object always implements the HttpServletRequest interface.

If you need to get the DynamoHttpServletRequest do something like this:

DynamoHttpServletRequest dynRequest  = atg.servlet.ServletUtil.getDynamoRequest(request);

If you need to get a PortalServletRequest do something like this:

PortalServletRequest portalRequest = (PortalServletRequest) request.getAttribute(atg.portal.servlet.Attributes.PORTALSERVLETREQUEST);

JHTML Structure

The typical JHTML file is structured like this.

<importbean bean="/atg/dynamo/service/jdbc/RelationalViewDroplet">

<nucleus type=import>
  /atg/dynamo/droplet/ForEach
  /atg/dynamo/droplet/Switch
</nucleus>

<java type="import">
  java.util.*
  java.net.*
</java>

<java>
  List ll = (List) request.resolveName("/betweengo/BigList");
</java>

Mysterious 404 errors in ATG J2EE applications

Often during development of an ATG J2EE application one will suddenly run into a 404 error. 404 means that the server could not locate the requested page . But often when one sees this error it is not because ATG could not locate the requested page but because it could not generate the page due to some sort of error which unfortunately ATG sometimes does not log. The error could be one of several.

  1. The J2EE application that contains the page did not properly start or was not started at all. One can check if the application was started either by looking in the ACC under the J2EE Deployment Editor or checking in the dynamo.log if the application was started and/or listed in the list of modules at start up.
  2. A runtime exception occurred in one of the droplets that were invoked in the page. Unfortunately ATG does not log the runtime exception, it is swallowed up somewhere. The best way to debug this is to start removing parts of the JSP page until you discover which part of the page is causing the 404.

ATG forms do not work if action is an HTML page

When creating forms that are to interact with ATG form handlers, one cannot use an HTML page as the action. If one does then the ATG form handler will not be invoked.

For example, this form will not invoke the ATG form handler.

<form name="test" action="test.html" method="get">
  Name: <input type="text" bean="/TestFormHandler.name">
  <p><input type="submit" bean="/TestFormHandler.submit">
</form>

However this form will.

<form name="test" action="test.jhtml" method="get">
  Name: <input type="text" bean="/TestFormHandler.name">
  <p><input type="submit" bean="/TestFormHandler.submit">
</form>

Internet Explorer form does not invoke ATG handler

In Internet Explorer if you have a form that has only a single line text input and if you press Enter to submit the form instead of pressing the submit button then the ATG handler for this form will not be invoked. Instead the form will act like a regular HTML form.

To get around this problem on Internet Explorer one must explicitly call the handler using a hidden input tag.

Here is an example of a simple form that illustrates this problem. The action of this form is to go to wrong.jhtml but if the ATG handler is invoked then the request is redirected to right.jhtml.

<form name="test" action="wrong.jhtml" method="get">
  Name: <input type="text" bean="/TestFormHandler.name">
  <p><input type="submit" bean="/TestFormHandler.submit">
</form>

Here is a screenshot of this form.

test form with only one input field

When I press Enter I go to the wrong page, i.e. wrong.jhtml, because the handler is not invoked.

example of a form working incorrectly

When I press the Submit button I go to the right page, i.e. right.jhtml, because the handler is invoked.

example of a form working correctly

To fix this I add this line within the form of testForm.jhtml.

  <input type="hidden" bean="/TestFormHandler.submit">

I also add this getter, which does nothing and may not be necessary for later versions of ATG, in the form handler.

  public String getSubmit() { return null; }

After doing this when I press Enter I go to the right page.

Note that with a form that has more than one input field this is not a problem.

test form with two input fields

The source for this example can be downloaded here.