struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phase Web and Multimedia" <m...@phase.ws>
Subject RE:[Gurus Invited] Why not an Action Based Validator?
Date Wed, 15 Jan 2003 09:13:38 GMT
But, can the Validator be called/used from within the action class?

For example, you need to extend your ActionForm to
ValidatorForm/ValidatorActionForm in order to use the Validator. Could the
same code be used to create a ValidatorAction that had a validate method
that could be called within classes that extended it to take advantage of
the Validator's validation simplicity.

The only reason why I mention this whole scenario has to do with organizing
and centralizing ones access to their "logic" code.

For example, I have a jsp form that has drop downs in it that are populated
by collections from the ValidatorActionForm. Now, if I have a validation
failure and my input forwards back to the jsp then the page explodes because
the collections are empty. So, what I need to do is populate the collections
in the ValidatorActionForm again. I can do this by overriding the validate
method from within my ValidatorActionForm and make a call to
super.validate(mapping,request) in order to perform the neccessary Validator
validation. Then I can check to see if the ActionErrors object generated by
the super.validate method is empty and call my "business logic" classes to
populate the collections in my form before it goes back to the jsp with the
errors. My feeling about this whole scenario is that I now have placed some
calls to the "business logic" in my ValidatorActionForm. This creates more
maintenance when having to update code. Wouldn't it be simpler to have
validation happening in the Action class so that if you have to access the
"business logic" that you can do so without decentralizing that code. I just
think it would be nice to allow for a validation using Validator to exist in
the/a base Action class that can be extended.

In summary this is what it seems to me should be the functional purpose of
each:

ActionForms - Pass form data to the Action with an option to validate
(maybe). No logic interaction. Currently we are forced to do this in many
cases.
Action	- Validate data and perform business logic interaction.

Final question, couldn't we whip up an Action class that takes advantage of
the Validators convenience and access it from an Action class instead of a
ActionForm?

Brandon Goodin
Phase Web and Multimedia
P (406) 862-2245
F (406) 862-0354
mail@phase.ws
http://www.phase.ws


-----Original Message-----
From: Gemes Tibor [mailto:tib@i-trade.hu]
Sent: Wednesday, January 15, 2003 1:13 AM
To: Struts Users Mailing List
Subject: Re: Why not an Action Based Validator?


2003. január 15. 09:12 dátummal Phase Web and Multimedia ezt írtad:
> No, that is different. That has to do with using the form bean name or the
> action 'mapping'. I am talking about having a validate method in the
action
> class rather than the ActionForm class.

Sorry, just didn't read the end of the mail.

I think that you can extend the action in the following way:

public class BaseAction extends Action {
ActionForward execute(...) {
	ActionErrors errors = validate(...);
	if (errors != null && !errors.empty()) {
		saveErrors(request, errors);
		String input = mapping.getInput();
		if (input != null)
			return new ActionForward(input);
		else
			// return sg, thow sg, or like
	}
	return executeOnValidatedInput(...);
}
ActionErrors validate(...) {
	// override this if you need validate in your action
	return null;
}
ActionForward executeOnValidatedInput(...) {
	// this is what you need to override in your actions.
	return null;
}
}

Tib

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



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


Mime
View raw message