Re: Homework for Struts Basics

I want to have a special error page (.jsp) in addition to the
indexpassionname.jsp and indexnopassionname.jsp.  So my controller
HelloAction needs to figure out when to forward the request to the
error page.  Right now I'm doing something like this in
HelloAction.execute():

        if (name.isEmpty() || name.length() < 3) {
            return mapping.findForward("default");
        } else if...

But this doesn't feel right, because it's essentially a repeat of test
done in HelloForm.validate() which looks like this;

        if (name.isEmpty()) {
            errors.add("Name", new
ActionMessage("error.name_missing"));
        } else if (name.length() < 3) {
            errors.add("Name", new
ActionMessage("error.name_too_short"));
        }

How can I reuse the result from HelloForm.validate(), or otherwise
avoid doing this check twice?  One way to reuse the code would be to
call the validate method from HelloAction.execute() like this:

        ActionErrors errors = form.validate(mapping, request);
        // if there are any errors in here, then forward to the error
page

But that would still mean performing the same check more than once.
Any ideas out there?

Thanks,
Mike


-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Reply via email to