Posts Tagged ‘java’
Creating user registration page in ATG using DSPs and Handler.
This post is moved to
http://ourownjava.com/atg/user-registration-page-atg-dsps-handler
Log-In/Authentication page in ATG.
In my previous post I have written about adding users in ATG Commerce site using ACC. You may set up users with the help of any other processes like a registration page or back-end loading/batch process. You will be ideally writing an authentication/log-in page once the user is setup properly in the ATG Commerce site.
ATG comes with powerful out of the box components to create ‘authentication/log-in’ page, for that matter any GUI component. Today we will look at Dynamo Server Page (DSP) tag libraries and ProfileFormHandler Bean. atg.userprofiling.ProfileFormHandler is shipped with ATG, DSP tag library (dsp:input) pass the HTTP Request to ProfileFormHandler Component/Bean. Bean validate the request parameter against the ATG repository. If you want to change the current behavior of the ATG ProfileFormHandler.handleLogin method you may extend the ProfileFormHandler and override the handleLogin method. Below given code is very basic implementation of authentication/log-in page.
Here are the most important parts of the log-in page.
1. Import the DSP tag library to the page.
<%@taglib prefix="dsp" uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0"%>
2. Import the form handler bean. (This bean is a ATG dynamo request scope component)
<dsp:importbean bean="/atg/userprofiling/ProfileFormHandler" />
3. Import ErrorMesageForEach droplet to display all form validation exception. (This bean is also a ATG dynamo component)
<dsp:importbean bean="/atg/dynamo/droplet/ErrorMessageForEach"/>
4. Create a text box to enter user id using DSP Input tag library.
<dsp:input bean="ProfileFormHandler.value.login" maxlength="30" size="25" type="text" required="true" />
You would have noticed that the login 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)
5. Create a password text box to enter the password using DSP input tag library.
<dsp:input bean="ProfileFormHandler.value.password" maxlength="30" size="25" type="password" required="true" />
6. Create a submit button using the DSP input tag library.
<dsp:input bean="ProfileFormHandler.login" type="submit" value="Log In" />
ProfileFormHandler has got method named handleLogin, (in fact its in the super type ProfileForm), that method gets invoked when you click the submit button.
7. Let the handler know the success url, user will be redirected to this page upon a successful authentication. You may give a failure url also.
<dsp:input bean="ProfileFormHandler.loginSuccessURL" type="hidden" value="myindex.jsp" />
8. ErrorMesageForEach Droplet is used to spit out all the form validation messages/exception. I think that doesn’t required any explanation.
Thats it. Without writing a line of java code we have implemented the authentication capability in our commerce site using ATG out of the box components.
<%@ 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <%@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"/> <title>ATG Login Page</title> </head> <dsp:page> <body> <div> <div>ATG out of the box authentication capability.</div> <br/> <dsp:form formid="loginForm" method="post" > <div> <div>Please enter your user id and password below</div> <table> <tbody> <tr> <td width="150">User ID:</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> </td> <td> <dsp:input bean="ProfileFormHandler.login" type="submit" value="Log In" /> <dsp:input bean="ProfileFormHandler.loginSuccessURL" 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> </div> </body> </dsp:page> </html>
Related articles
- How to add users using ATG ACC? (cleanjava.wordpress.com)
- How to write ATG collection query (RQL)? (cleanjava.wordpress.com)
- How to write contains/suggestion/match query using ATG RQL? (cleanjava.wordpress.com)
How to add users in ATG using ACC?
On development phase, you may have to set up users with valid credential to do authentication test in your ATG e-commerce web-site. I will explain you every step required to setup user using ATG ACC and how to verify if the user is indeed setup properly.
1. load dynamo admin tool using the below given URI.
http://host-name:port/dyn/admin
2. On the dynamo admin console click on Admin ACC link. (Third one from the top)
3. Click on “Start ACC in Server VM” button.
4. Now you should see a thick GUI written in java swings titled ATG Control Center. Default credential for ATG ACC is admin/admin
5. On the left hand site you should see a collection of menus.
6. Select the first item in left pane named People and Organization.
7. Now you should see six other items under the People and Organization main item
8. Select Users item. (Third one from the top)
9. This should bring up the user window. Punch in all users details and click on OK button.
10. Click on the save icon on the top right side of ACC window.
11. Now you can verify if the user is really added in the database.
12. Select JDBC browser from Dynamo Admin Page. (see the first step to load dyn admin page)
13. Select “Execute Query” under database operations.
14. Write “select * from dps_user” in the query text area and click execute button.
15. You should be able to the user you have added thru the ACC new user window.
Related articles
- How to write ATG collection query (RQL)? (cleanjava.wordpress.com)
- How to write contains/suggestion/match query using ATG RQL? (cleanjava.wordpress.com)
How to write ATG includes query (RQL)?
This post is moved to http://ourownjava.com/atg/how-to-write-atg-rql-includes-query
Wildcard File Filter in java.
This post is moved to http://ourownjava.com/java/wildcard-file-filter-in-java
Splitting tasks among threads.
Recently in an interview I was asked to write a program which prints running positive numbers, odd number shall be printed by one thread and even number shall be printed by another thread. I thought to share the program with you guys.
package org.sanju; /** * * @author sanju.org * * Example program which prints odd number by one thread * and even number by another thread. * * */ public class SplitTaskExample { private volatile Integer i = new Integer(0); private void printRunningNumbers(){ //odd thread new Thread(new Runnable() { public void run() { while(true){ if(i % 2 == 1){ System.out.println("odd thread :"+i); i++; } try{ i.wait(); i.notifyAll(); }catch (Exception e) { } } } }).start(); //even thread new Thread(new Runnable() { public void run() { while(true){ if(i % 2 == 0){ System.out.println("even thread : "+i); i++; } try{ i.wait(); i.notifyAll(); }catch (Exception e) { } } } }).start(); } public static void main(String[] args) { new SplitTaskExample().printRunningNumbers(); } }
/local/opt/java SplitTaskExample
even thread : 0
odd thread :1
even thread : 2
odd thread :3
even thread : 4
odd thread :5
Multiple attributes to compare objects.
There would be cases you would want use a second attribute to compare two objects of same type if the first attribute comparison is not good enough. In the compareTo method you can choose to go a second attribute to compare two objects of same type. Here is a simple example where the compareTo method used the lastName to compare two objects of Employee if the firstName of two employee objects are same.
package org.sanju; /** * * @author sanju.org * * Multiple attributes to compare Objects. * Multiple attributes in cmpareTo method. * */ public class Employee implements Comparable<Employee> { private Name name; class Name{ private String firstName; private String lastName; } public int compareTo(Employee o) { if(this.name.firstName.compareTo(o.name.firstName) == 0){ return this.name.lastName.compareTo(o.name.lastName); } return this.name.firstName.compareTo(o.name.firstName); } }