You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ray Madigan <ra...@madigans.org> on 2004/04/07 20:02:39 UTC

Struts Form Validation

I have a problem that I cannot see why it behaves the way it does, and was
hoping a couple more eyeballs might help, thanks!

I have a jsp that has

<html:errors/>

<html:form action='/signin' focus='username'>

A couple of input controls including username

</html:form>

When the user types in all of the fields correcly this work fine.
The execute method of action signin is called and all is well.

When the user doesn't fill in one of the fields is when the problem shows
itself.

The action looks like this

    <action path="/signin"
            type="com.mbresearch.main.action.SigninAction"
            name="signinForm"
            scope="session"
            input="/com/mbresearch/main/view/signin.jsp">
      <exception
         key="credential.exception"
         type="com.mbresearch.registrar.ejb.InvalidCredentialException"
         path="/com/mbresearch/main/view/icexcept.jsp"/>
      <exception
         key="system.exception"
         type="com.mbresearch.xrm.ejb.InvalidSystemException"
         path="/com/mbresearch/main/view/isexcept.jsp"/>

    </action>

When the user doesn't fill in the form correctly, the validate method of the
form is executed, and the page that is displayed is at URL

/signin.do

and not the input page as I thought was to happen, based on the doc.

The validate method look like this!

public final class SigninForm
extends ActionForm {

    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        if ((username == null) || (username.length() < 1))
            errors.add("username", new
ActionError("error.username.required"));
        if ((password == null) || (password.length() < 1))
            errors.add("password", new
ActionError("error.password.required"));
        return errors;
    }

Any help would be greatly appreciated!


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org