2

I am new to ATG. And I am trying to use RepositoryFormHandler of my own. But I am not able to do the validations on the form.

Here is my .java file:

public class MyLoginBean extends RepositoryFormHandler {

    private String logname;
    private String logpwd;
    private String message;

    public String getLogname() {
        return logname;
    }

    public void setLogname(String logname) {
        this.logname = logname;
    }

    public String getLogpwd() {
        return logpwd;
    }

    public void setLogpwd(String logpwd) {
        this.logpwd = logpwd;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean handleLogname(DynamoHttpServletRequest pRequest,
            DynamoHttpServletResponse pResponse) throws ServletException,
            IOException {
        boolean tf=true;
        if(logname.isEmpty() || logname==null)
        {
            tf=false;
            setMessage("User name can't empty");
        }

        System.out.println("inside logname");
        return tf;
    }

    public void handleFormException(DropletFormException exception,
            DynamoHttpServletRequest request, DynamoHttpServletResponse response) {
        // TODO Auto-generated method stub
        super.handleFormException(exception, request, response);
    }

}

And here is my .jsp file:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:importbean bean="/atg/dynamo/droplet/ErrorMessageForEach"/>
<dsp:importbean bean="/dynamusic/MyLoginBean"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Custom Login</title>
</head>
<body>
<dsp:form style="color:white">
    <table style="background:#3b5998">
        <tr>
            <td>
                <ul>
                    <dsp:droplet name="ErrorMessageForEach">
                        <dsp:param bean="MyLoginBean.formExceptions" name="exceptions"/>
                        <dsp:oparam name="output">
                            <li>
                                <dsp:valueof param="message"/>
                            </li>
                        </dsp:oparam>
                    </dsp:droplet>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                User Name:
            </td>
            <td>
                Password:
            </td>
        </tr>
        <tr>
            <td>
                <dsp:input type="text" name="logname" bean="MyLoginBean.logname"> </dsp:input>
            </td>
            <td>
                <dsp:input type="password" name="logpwd" bean="MyLoginBean.logpwd"> </dsp:input>
            </td>
            <td>
                <dsp:input type="submit" bean="MyLoginBean.login"> </dsp:input>
            </td>
        </tr>
    </table>
</dsp:form>
</body>
</html>

This is all I've tried so far and still trying something else. Please suggest the solution for it and also tell me the mistakes, if any, in the code pasted here.

Buddha
  • 4,339
  • 2
  • 27
  • 51
Varun Jain
  • 1,371
  • 12
  • 26
  • 1
    Your accessor to `logname` will conflict with your `handleLogname` method as both of these will be referred to by the form as `MyLoginBean.logname`. Looks like you subsequently fixed this by having `MyLoginBean.login` on the JSP but without a related `handle` method in the Java code. Also see Patrick's comments for more guidance. – radimpe Oct 28 '14 at 08:31

1 Answers1

8
  1. Don't override handleFormException
  2. Instead of using setMessage, use ATG's built-in behavior. All form handlers inherit a Vector of form exceptions from the GenericFormHandler superclass. To add an error, use:

addFormException(new DropletException("Your error message"));

Then, at the end of your method, call:

return checkFormRedirect(getSuccessUrl(), getFailUrl(), pRequest, pResponse);

This checks if any form exceptions have been added, and if so, redirects to the failUrl, otherwise redirects to the successUrl.

  1. By convention, you should name your form handler *FormHandler, for example ProfileFormHandler, BillingInfoFormHandler, PaymentInfoFormHandler etc.

Hope this helps. See http://docs.oracle.com/cd/E22630_01/Platform.1002/apidoc/atg/droplet/GenericFormHandler.html#getFormExceptions()

Patrick
  • 730
  • 1
  • 5
  • 10