Skip to main content

ATG - more about Forms and Form Handlers

An ATG form is defined by the dsp:form tag, which typically encloses DSP tags that specify form elements, such as dsp:input that provide direct access to Nucleus component properties. Find below a sample dsp:form tag.
   <dsp:form action="/testPages/showPersonProperties.jsp" method="post" target="_top">
     <p>Name: <dsp:input bean="/samples/Person.name" type="text"/>
     <p>Age: <dsp:input bean="/samples/Person.age" type="text" value="30"/>
     <p><dsp:input type="submit" bean="/samples/Person.submit"/> value="Click to submit"/>
   </dsp:form>
 
When the user submits the form, the /samples/Person.name property is set to the value entered in the input field.Unlike standard HTML, which requires the name attribute for most input tags; the name attribute is optional for DSP form element tags. If an input tag omits the name attribute, the ATG platform assigns one when it compiles the page. A text input field displays the component property’s current value unless the dsp:input tag also includes the value attribute. The value attribute overrides the property’s current value.

If an outer JSP has a dsp:form then the inner included page(dsp:include) can contain element tags such as dsp:input, dsp:textarea, and dsp:select only if the page is a complete JSP. Form elements cannot be embedded in a JSP fragment (.jspf) file.

ATG provides hundreds of readymade form handlers for performing all sorts of tasks, like updating a customer profile(CommerceProfileFormHandler), managing your shopping cart(CartModifierFormHandler), checking out(ExpressCheckoutFormHandler), or interacting with a repository(RepositoryFormHandler).

Following are the tasks assigned to Form Handlers by ATG :

  • Validate data before it is submitted.
  • Detect missing information and display appropriate messages to the user.
  • Direct users to different pages depending on form submission results.
  • Read and write database or repository data.

A better way to create a new form handler is to subclass a Dynamo class that implements DropletFormHandler interface. Dynamo provides three form handler base classes that implement this interface :

  • atg.droplet.DropletFormHandler --> inteface
  • atg.droplet.EmptyFormHandler --> implements DropletFormHandler
  • atg.droplet.GenericFormHandler --> extends EmptyFormHandler
  • atg.droplet.TransactionalFormHandler --> extends GenericFormHandler --> treats the form processing operation as a transaction.

Find below a sample call to /atg/search/formhandlers/SearchValidateFormHandler from a JSP :

      <dsp:input bean="SearchValidateFormHandler.validate" name="validate" id="validate" type="hidden" value="DAS" style="display:none" priority="-10"/>

A handler method will be specified with the name ‘handlex’ where x represents the name of the submit. The signature of the handle method is:

       public boolean  handlex(DynamoHttpServletRequest request,
DynamoHttpServletResponse response)throws IOException, ServletException{}

The handler method (handlex) returns a boolean value. This value indicates whether Dynamo should continue processing the rest of the page after this handler has finished. In the above example, there is a public boolean handleValidate(DynamoHttpServletRequest pRequest,DynamoHttpServletResponse pResponse) method @ SearchValidateFormHandler.

If there are any setx methods in the FormHandler, it will be called before the handlex method is invoked. Some of the other methods used by the form handler are:

  • beforeSet --> This is called before any setx methods are called.
  • afterSet --> This is called after all setx methods are called.
  • beforeGet  --> This is called before any tags that reference the component is rendered.
  • afterGet --> This is called after the page rendering gets completed.
  • handleFormException --> This is called when any exception occurs while trying to call the setx methods.
Following are the form handler component properties to handle form errors/exceptions:
  • formError --> Boolean that is set to true if any errors occur during form processing.
  • formExceptions  --> A vector of the exceptions that occur during form processing.  If your form handler is session-scoped, clear the formExceptions property after you display errors to the user.
  • propertyExceptions  --> A read-only property that returns a Dictionary of subproperties, one for each property set by the form. For each property that generates an exception, a corresponding subproperty in the propertyExceptions Dictionary contains that exception
Use the checkFormRedirect(String pSuccessURL, String pFailureURL, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) method of GenericFormHandler to redirect to a url from the formhandler on a success/error cases. A handler that redirects the user to another page should return false.

The atg.droplet.GenericFormHandler class (and any subclass of GenericFormHandler you write) includes a handleCancel method for implementing Cancel buttons in forms. This method redirects to the URL specified in the form handler’s cancelURL property.

When a dsp:setvalue tag is rendered for a form handler property, it invokes the setX and handleX methods of the form handler (if the methods exists).

A form handler component should be either request- scoped or session-scoped.When your form handler spans several pages, such as in a multi-page registration process,  you want the session-scoped form handler.It is especially important to clear error messages to ensure they do not appear in other forms where they are not relevant.



Comments

  1. hi sony,
    Iam really amazed the way you put efforts to write these blogs. Please could you write something about folder structure. how it is created, if you could. God bless you

    ReplyDelete
  2. check it @ http://tips4ufromsony.blogspot.com/2012/02/atg-how-to-create-and-deploy-new-atg.html

    If you want to know anything special, please raise it... :-)

    ReplyDelete
  3. this post is good one tag An ATG form is defined by the dsp:form tag, which typically encloses DSP tags that specify form elements

    ReplyDelete
  4. your efforts are brilliant. please try to increase the examples on form handlers and droplets. as i am a beginner your blog helping me alot!

    ReplyDelete
  5. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u


    Form Processing

    ReplyDelete
  6. Hi sony,

    Great effort!.it's really helpful for beginners like me.could you please explain login validations using form handlers?

    ReplyDelete
  7. hi sony,
    I want to know how to extend the oob(Out Of Box) components and how can i override those methods....

    ReplyDelete
  8. Hi Sony,

    Thanks for your valuable time that you gave here to write this blog.
    It is very very helpful and your effort is really appreciable.
    Wish to see more posts from you in coming future.

    Great job :)

    ReplyDelete
  9. i am new to ATG, Please explain me how ATG is Different From other tools or Frameworks to develop Websites. Thank you Somuch

    ReplyDelete
    Replies
    1. ATG is basically an e-Commerce platform which provide many capabilities. It provides an API for most of the eCommerce stuff... you can also have a detailed look on this blog.. lot of detail:-

      http://learnoracleatg.blogspot.in/p/atg-e-commerce.html

      Delete
  10. nice post.

    For atg related stuff, you can visit www.atg-tips.blogspot.com

    ReplyDelete

Post a Comment

Popular posts from this blog

How to convert your Blogger Blog to PDF ?

You can use a website called "blogbooker" @  http://www.blogbooker.com/blogger.php   to convert your Blogger Blog to a PDF . Please find the steps below : 1. Save your blog as an xml using Blogger Settings - Other - Export Blog option 2. Go to the website " http://www.blogbooker.com/blogger.php " and select this XML , give your blog address and select the options like date range, page size, font, ... 3. Click the  "Create Your BlogBook" button to view and save your blog as PDF

Eclipse plug-in to create Class and Sequence diagrams

ModelGoon is an Eclipse plug-in avaiable for UML diagram generation from Java code. It can be used to generate Package Dependencies Diagram, Class Diagram, Interaction Diagram and Sequence Diagram. You coud get it from http://marketplace.eclipse.org/content/modelgoon-uml4java Read more about it and see some vedios about how to create the class and sequence diagram @ http://www.modelgoon.org/?tag=eclipse-plugin Find some snapshots below which gives an idea about the diagram generation.

ATG Search - search engine tuning settings

In this blog, I am going to list the best tuning settings for ATG Search engine. The AESoapConfig.xml, AESoapWaspConfig.xml  and AEConfig.xml are the xmls referred below and you can find it @  <ATG_DIR>\<Searchx.x>\SearchEngine\<operating_system>\bin\ folder. (1)  Make sure that the AESoapConfig.xml's rwTimeout is less than or equal to routing's readTimeoutMs. You could find the routing's readTimeoutMs @ atg\search\routing\SearchEngineService component.               rwTimeout is the  length of time in seconds to wait before a read or write operation times out on an active connection. The number can be decreased to improve performance. However, a value that is too low could cause slow connections to be prematurely closed. (2)  Adjust the number of engine threads to match the number of CPUs available to the engine. Note that the minimal value for maxThreads and maxSpareThreads is 2, which applies to running with 1 CPU.  However, it is recommended to

Working Environment

It is always good to think about your working environment. Here I am listing mine,  expecting your comments to add other necessary tools to this list. Anti Virus Avast  –> http://www.avast.com/free-antivirus-download Avira  –> http://www.avira.com/en/avira-free-antivirus AVG  –> http://www.freeavg.com/?lng=in-en&cmpid=free Kaspersky  –> http://www.kaspersky.com/ McAfee  –> http://www.mcafee.com/us/ Symantec  –> http://www.symantec.com/index.jsp Application Server JBoss  –>   http://www.jboss.org/jbossas/ Tomcat –>   http://tomcat.apache.org/ Weblogic –>   http://www.oracle.com/technetwork/middleware/weblogic Browser Firefox –>   http://www.mozilla.com/en-US/firefox Google Chrome  –> http://www.google.com/chrome/ IE  –>   http://windows.microsoft.com/en-US/internet-explorer/downloads/ie Communication_Network IPMessenger –>   http://ipmsg.org/index.html.en Putty –>   http://www.chiark.greenend.org.uk/~sgtatham/putty

How to simulate Browser back button

When someone asks how to simulate a back button, they really mean to ask how to create a link that points to the previously visited page. Most browsers tend to keep a list of which websites the user has visited and in what order they have done so. The DOM window object provides access to the browser's history through the history object. Moving backward and forward through the user's history is done using the   back(), forward(), and go() methods of the  history  object. To move backward through history, just do window.history.back() ; This will act exactly like the user clicked on the Back button in their browser toolbar. Find below a sample html code: <html> <head> <script type="text/javascript"> function goBack(){  window.history.back() } </script> </head> <body>    <input type="button" value="Back" onclick="goBack()" /> </body> </html>