You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Frank Nestel <do...@bigfoot.com> on 2000/06/26 12:29:20 UTC

ValidatingActionForm.validate()

Hi there,

before I start building my OwnValidatingActionForm again,
just another little idea. I ended up with code like

        String errors[];
        if ( someApplicationCondition )
        {
            errors = new String[] {"application.condition.failed"};
        }
        else
        {
            errors = form.validate();
        }

with a ValidatingActionForm form. If validate() would return
the ErrorMessages object instead of a String-Array, this could be

        // Validate the request parameters specified by the user
	ErrorMessages errors = form.validate();
        if ( someApplicationCondition )
        {
            errors.addError("application.condition.failed");
        }

this is not only shorter, but would als give a user more hints at
once, why the application did not like his registration. I.e. mixed
bean and application error conditions. Of course one could implement
for the user the same effect by some more code... An ErrorMessages
returning validate() would also allow subclassing of ErrorMessages
which could be interesting anyway. Maybe ErrorMessages should be an
interface ...

In case validate() returned an ErrorMessage it would be NTH that the 
<struts:errors> tag would know about an type ErrorMessages attribute 
to display ... Anyway this example also seems to indicate, it might be 
useful to have a constructor

	ErrorMessages(String[] oldErrors)

which would allow to convert back and forth between a String-Array
and ErrorMessages.

Frank

---------------------------------ooO---"---Ooo--------------
Spiele von Doris und Frank, Dr. Frank Sven Nestel,
Wolfsstaudenring 32, D-91056 Erlangen-Kriegenbrunn, GERMANY.
dorisnfrank@bigfoot.com                 "I hate this game,
http://www.bigfoot.com/~dorisnfrank      lets play it again"
SOON moving to: http://doris-frank.de
AND ALSO on   : http://duf.damud.com
~
~