You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian Rook <br...@hotmail.com> on 2003/04/20 03:18:13 UTC
Validator and collections in request
I've been banging my head against the validator framework and must ask a
question. If it has already been addressed, I apologize and would
appreciate being directed to the appropriate thread.
Basically, I'm creating a select input and populating it's options from a
collection that I store in the _request_ from an action class called
PromptAddEditUserAction.
However, when I use the validator plugin to validate the input I get an
error on the page when the validation fails and it's due to the collection
not residing in the request anymore.
I believe that one of the suggested solutions was to place the collection
into the session, but I feel that this is an unaccepable solution as it
clutters up the session with unnecessary objects.
So, I've decided to create a new, intermediaty Action class called
ValidateAddEditUserAction in which I pull the validator resources from the
servlet context and perform the validation manually and thereby control the
forwards based on the errors produced (so I can go back to
PromptAddEditUserAction instead of being redirected to the .jsp page when
errors are produced). However, I'm having problems getting the error
messages out of the ValidatorResults object and the documentation on the
validator in pretty sparse.
Questions:
1)Am I going down the wrong path?
2)Has anyone dealt directly with the Validator classes before, specifically
ValidatorResults in order to retrieve the messages?
p.s. I have successfully created a validator from the resources that the
plug-in created and ran the validate() method and produced
ValidationResults, I just don't know how to get the error messages:
Code snippet: (From my ValidateUserInputAction)
ActionServlet as = getServlet();
ServletContext sc = as.getServletContext();
ModuleConfig mc = mapping.getModuleConfig();
String prefix = mc.getPrefix();
ValidatorResources vr =
(ValidatorResources)sc.getAttribute(
"org.apache.commons.validator.VALIDATOR_RESOURCES" + prefix);
logger.debug("got resources" + vr);
Validator validator = new Validator(vr,"userForm");
validator.addResource(Validator.BEAN_KEY, thisForm);
ValidatorResults results = new ValidatorResults();
try{
results = validator.validate();
}catch (ValidatorException ve){
ve.printStackTrace();
}
logger.debug("results empty: " + results.empty());
Thanks for any assistance
brian
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org