ATG comes with powerful out of the box components to build e-commerce websites with minimal effort. Today we will create a simple user registration page using DSP tags and ProfileFormHandler Component.
Steps to create a user registration page.
1. Import the DSP tab libraries.
1 |
<%@taglib prefix="dsp" uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0"%> |
2. Import the ProfileFormHandler Component.
This is an out of the box component of ATG and registered as request scope bean.
1 |
<dsp:importbean bean="/atg/userprofiling/ProfileFormHandler" /> |
3. Import the ErrorMessageForEach droplet.
This droplet helps to display form validation exceptions and errors.
1 |
<dsp:importbean bean="/atg/dynamo/droplet/ErrorMessageForEach"/> |
4. Declare a form using DSP form tag.
A form shall be declared inside a tag.
1 |
<dsp:form id="registerForm" method="post" action="myRegister.jsp"> |
5. Declare all the required form field using DSP input tag.
1 |
<dsp:input bean="ProfileFormHandler.value.firstName" maxlength="30" size="25" type="text" required="true" /> |
You would have noticed that the firstName attribute is part of the value map, it gets mapped to the underlying ProfileAdapterRepostory value map. (you can see all the attributes in the userProfile.xml)
6. Create a submit button using the DSP input tag library.
ProfileFormHandler has got method named create. Create method gets invoked when you click the submit button.
1 |
<dsp:input bean="ProfileFormHandler.create" type="submit" value="Register" /> |
7. Register the success URL
User will be redirected to this page upon a successful authentication. You may give a failure URL also.
1 |
<dsp:input bean="ProfileFormHandler.createSuccessURL" type="hidden" value="myIndex.jsp" /> |
ErrorMesageForEach Droplet is used to spit out all the form validation messages/exception.
Thats it. Without writing a line of java code we have implemented the user registration page in our commerce site using ATG out of the box components.
Complete Example Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <%@taglib prefix="dsp" uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0"%> <dsp:importbean bean="/atg/userprofiling/ProfileFormHandler" /> <dsp:importbean bean="/atg/dynamo/droplet/ErrorMessageForEach"/> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User Registration Page</title> </head> <body> <dsp:page> <dsp:form id="registerForm" method="post" action="myRegister.jsp"> <div> <div>Please fill all the fields given below and click register button.</div> <br/> <table> <tbody> <tr> <td width="150">First Name *</td> <td><dsp:input bean="ProfileFormHandler.value.firstName" maxlength="30" size="25" type="text" required="true" /></td> </tr> <tr> <td>Last Name *</td> <td><dsp:input bean="ProfileFormHandler.value.lastName" maxlength="30" size="25" type="text" required="true" /></td> </tr> <tr> <td>Username *</td> <td><dsp:input bean="ProfileFormHandler.value.login" maxlength="30" size="25" type="text" required="true" /></td> </tr> <tr> <td>Password *</td> <td><dsp:input bean="ProfileFormHandler.value.password" maxlength="30" size="25" type="password" required="true" /></td> </tr> <tr> <td>Confirm Password *</td> <td><dsp:input bean="ProfileFormHandler.value.password" maxlength="30" size="25" type="password" required="true" /></td> </tr> <tr> <td>Email ID *</td> <td><dsp:input bean="ProfileFormHandler.value.email" maxlength="30" size="25" type="password" required="true" /></td> </tr> <tr> <td>Gender *</td> <td> <dsp:input bean="ProfileFormHandler.value.gender" type="radio" required="true" >Male </dsp:input> <dsp:input bean="ProfileFormHandler.value.gender" type="radio" required="true" >Female </dsp:input> </td> </tr> <tr> <td colspan="2"> <dsp:input bean="ProfileFormHandler.create" type="submit" value="Register" /> <dsp:input bean="ProfileFormHandler.createSuccessURL" type="hidden" value="myIndex.jsp" /> </td> </tr> <tr> <td colspan="2"> <ul> <dsp:droplet name="ErrorMessageForEach"> <dsp:param bean="ProfileFormHandler.formExceptions" name="exceptions"/> <dsp:oparam name="output"> <li> <dsp:valueof param="message"/> </li> </dsp:oparam> </dsp:droplet> </ul> </td> </tr> </tbody> </table> </div> </dsp:form> </dsp:page> </body> </html> |
You can verify if the user is indeed registered successfully using ACC or JDBC Browser from dyn/admin page.
A screen shot of out the box server side validation capability of ATG.
Pingback: Creating user registration page in ATG using DSPs and Handler. | Clean Java
Great resume and good example.
Thanks Vico.
very very useful for beginners..good ..please post more commerce concepts
Thanks Janakirman.
Superb Explanation !!!
Thanks
Thanks DK.
Well explained tutorial!
Unfortunately when I tried to run it I got some exceptions related (I guess) to a misconfiguration(s) on my web deployment descriptor.
Could you please publish a link to download the source code of your tutorial?
Regards!
good tutorial! thanks