struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Alexandersson" <>
Subject RE: Bean Population When Form Cancelled
Date Tue, 14 Feb 2006 13:14:52 GMT
I think so, look at this.
My implementation down here.

/*** CODE ***

     * This method is used to execute validation rules <br>
     * The good-part, 
     * <br>1. can chose to not validate if cancel is submitted .
     * <br>2. If validate exception is found the Form/Page can be
reInitialized and shown properly again.
     * <br>
     * The bad-part, normaly the user sets validate="true" in config but
     * can no longer be done, can feel strange. <br>
     * This method is used with recommendation from --> <br>
     * see
     * @author robert.alexandersson
     * Generic Struts stuff - cancel - validate
    public ActionForward validate(ActionMapping mapping, ActionForm
            HttpServletRequest request) {

        if (this.isDelete(request) || this.isCancel(request))
            return null;

        ActionErrors errors = form.validate(mapping, request);
        if (errors != null && !errors.isEmpty()) {
            saveErrors(request, logAndGetMessages(errors));
            return (mapping.getInputForward());
        return null;

     * Transform Errors to Messages according to the Deprecation warning
     * ActionErrors and super.saveErrors
     * @param errors
     * @return
    private ActionMessages logAndGetMessages(ActionErrors errors) {
        Iterator i =;
        ActionMessages messages = new ActionMessages();
        while (i.hasNext()) {
            String property = (String);
            Iterator j = errors.get(property);
            while (j.hasNext()) {
                ActionMessage err = (ActionMessage);
                messages.add(property, err);
        return messages;
/******* END CODE *******

-----Original Message-----
From: Tom Ansley [] 
Sent: Saturday, February 11, 2006 6:48 AM
To: Struts Users Mailing List
Subject: Bean Population When Form Cancelled

Hi all,

I have a form that uses validator to check for simple validation like
sure that a cash amount is a double.  I have the "cancel" button on the
set so that if it is pressed that validation does not take place.  This
great except when you type a letter into the cash text box and then
cancel.  The form gets returned along with the invalid cash amount, the
BeanUtils attempts to populate the form and the whole thing falls over
an exception.

Does somebody have a strategy for dealing with this situation?  Is there
way of telling struts that if the cancel button is pressed that NO bean
population should take place?

All help appreciated.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message