You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Matt Raible <ma...@raibledesigns.com> on 2004/02/28 21:56:13 UTC

Validation working, but not stopping action from processing

I'm using the 1.2.0 test build on Windows XP.

I have the following XDoclet-generated action-mapping:

    <action
      path="/savePerson"
      type="org.appfuse.webapp.action.PersonAction"
      name="personForm"
      scope="request"
      input="validationFailed"
      parameter="action"
      unknown="false"
      validate="true"
    >
      <forward
        name="validationFailed"
        path="/editPerson.do"
        redirect="false"
      />
      <forward
        name="edit"
        path=".personDetail"
        redirect="false"
      />
    </action>

When I click on a button to "save" my form, the validation kicks in -
but it let's my Action continue to execute.  I thought that any
validation errors were supposed to call mapping.getInputForward()?  Is
that correct?  I'm stumped.  Here's my save() method:

    public ActionForward save(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
    throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'save' method");
        }

        // Extract attributes and parameters we will need
        ActionMessages messages = getMessages(request);        
        PersonForm personForm = (PersonForm) form;
        boolean isNew = ("".equals(personForm.getId()));
        
        if (log.isDebugEnabled()) {
            log.debug("saving person: " + personForm);
        }

        // Exceptions are caught by ActionExceptionHandler
        PersonManager mgr = (PersonManager) getBean("personManager");
        personForm = (PersonForm) mgr.savePerson(personForm);

        // add success messages
        if (isNew) {
            messages.add(ActionMessages.GLOBAL_MESSAGE,
                         new ActionMessage("person.added",
                                           personForm.getFirstName() + "
" +
                                           personForm.getLastName()));
            request.getSession().setAttribute(Globals.MESSAGE_KEY,
messages);

            return mapping.findForward("mainMenu");
        } else {
            messages.add(ActionMessages.GLOBAL_MESSAGE,
                         new ActionMessage("person.updated",
                                           personForm.getFirstName() + "
" +
                                           personForm.getLastName()));
            saveMessages(request, messages);

            return mapping.findForward("edit");
        }
    }

The validation routes the user back to the form, but it also calles
mgr.savePerson and puts the message in the requestion.  So on my page, I
end up with the following messages:

'First Name' is a required field.
'Last Name' is a required field.
Information for has been updated successfully.

Hopefully I'm just banging my head against the wall and it's something
simple...

Matt



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