My <url-pattern> is /do/* - where you have individual actions listed.
I'm abandoning my try at "using the validation outside of struts" and instead going for initializing it like the PlugIn does. However, I get a NPE in the Validator's Recources.java at: String prefix = ((ModuleConfig) request.getAttribute(Globals.MODULE_KEY)).getPrefix(); when using: Validator validator = Resources.initValidator("userFormEx", userForm, getServletContext(), request, errors, 2); What's the easiest way to create a ModuleConfig and set the prefix? I'm guessing it would be "", since I have no modules. Thanks, Matt -----Original Message----- From: Vic Cekvenich [mailto:[EMAIL PROTECTED] Sent: Friday, May 30, 2003 2:43 PM To: [EMAIL PROTECTED] Subject: Re: Using the Validator outside of Struts I do same thing. take a look at my WEB.XML in web CVS. Raible, Matt wrote: >I'm not using Struts for the self registration. I'm protecting all of the >struts actions (/do/*), so I cannot use struts w/o logging in. I cannot >login if I don't have a username... > >-----Original Message----- >From: Vic Cekvenich [mailto:[EMAIL PROTECTED] >Sent: Friday, May 30, 2003 2:23 PM >To: [EMAIL PROTECTED] >Subject: Re: Using the Validator outside of Struts > > >basicPortal has self register example code, w/validation using Struts >JSP, you can click join, on basebeans.com and then click login (and then >look under the monkey, I kill myslef). >So then you have a default role (you can aprove content if you are not >admin role). > >I can't imagine where you might be stuck, but here is the jsp: >http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/p ortle >ts/memberSec/User.jsp > >..V > > >Raible, Matt wrote: > > > >>Ok, now that I've gotten past super.init(config), onto the validator not >>working. I get the following error: >> >> [java] 2003-05-30 14:12:43,734 ERROR [Ajp13Processor[8009][0]] >>Validator.validateFieldForRule(4 >>61) | reflection: null >> [java] java.lang.reflect.InvocationTargetException >> [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native >>Method) >> [java] at >>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j ava:3 >> >> >9 > > >>) >> [java] at >>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess orImp >> >> >l > > >>..java >>:25) >> [java] at java.lang.reflect.Method.invoke(Method.java:324) >> [java] at >>org.apache.commons.validator.Validator.validateFieldForRule(Validator. java: >> >> >4 > > >>54) >> [java] at >>org.apache.commons.validator.Validator.validateField(Validator.java:54 4) >> [java] at >>org.apache.commons.validator.Validator.validate(Validator.java:582) >> [java] at >>com.comcast.cable.dmc.itd.cct.webapp.action.RegistrationServlet.execut e(Reg >> >> >i > > >>strat >>ionServlet.java:146) >> >> >> >>From the following code: > > >> ValidatorResources resources = new ValidatorResources(); >> >> InputStream rules = >> >>getServletContext().getResourceAsStream("/WEB-INF/validator-rules.xml" ); >> >> ValidatorResourcesInitializer.initialize(resources, rules); >> >> InputStream custom = >>getServletContext().getResourceAsStream("/WEB-INF/validator-rules-cust om.xm >> >> >l > > >>"); >> >> ValidatorResourcesInitializer.initialize(resources, custom); >> >> InputStream forms = >> >>getServletContext().getResourceAsStream("/WEB-INF/validation.xml"); >> >> ValidatorResourcesInitializer.initialize(resources, forms); >> >> // Create a validator with the userForm >> Validator validator = new Validator(resources, "userFormEx"); >> >> // Tell the validator which bean to validate against. >> validator.addResource(Validator.BEAN_KEY, userForm); >> >> // Validate the checkoutForm object and store the validation >> >> >results > > >> try { >> // Execute the validation rules >>146: ValidatorResults results = validator.validate(); <<-- Error >>occurs here >> >> if (log.isDebugEnabled()) { >> log.debug(results.getResultValueMap()); >> } >> } catch (ValidatorException ex) { >> // Log the validation exception >> log.warn("A validation exception occurred", ex); >> } >> >>The validator is working fine in my Action classes, just not outside. I'm >>trying to use it in a servlet that's not an Action because all my actions >>(/do/*) are protected by form-based authentication. This servlet is used >>for users to self-register. If anyone has an elegant solutions to >>self-register (not using a servlet), let me know. >> >>Thanks, >> >>Matt >> >>-----Original Message----- >>From: Raible, Matt >>Sent: Friday, May 30, 2003 7:13 AM >>To: '[EMAIL PROTECTED]' >>Subject: Using the Validator outside of Struts >> >> >>I'm trying to use the Validator to validate that a user has entered their >>information in a self-registration servlet. >> >>However, I'm getting a NullPointerException at the following line when >>running a test using Cactus: >> >> InputStream rules = >> >>getServletContext().getResourceAsStream("/WEB-INF/validator-rules.xml" ); >> >>Error: >> >> [junit] java.lang.NullPointerException >> [junit] at >>javax.servlet.GenericServlet.getServletContext()Ljavax.servlet.Servlet Conte >> >> >x > > >>t;(Ge >>nericServlet.java:204) >> [junit] at >>com.comcast.cable.dmc.itd.cct.webapp.action.RegistrationServlet.execut e(Lja >> >> >v > > >>ax.se >>rvlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )V(Re >> >> >g > > >>istrationServlet.java:12 >>2) >> >>Full code: >> >> ValidatorResources resources = new ValidatorResources(); >> >> InputStream rules = >> >>getServletContext().getResourceAsStream("/WEB-INF/validator-rules.xml" ); >> >> ValidatorResourcesInitializer.initialize(resources, rules); >> >> InputStream forms = >> >>getServletContext().getResourceAsStream("/WEB-INF/validation.xml"); >> >> ValidatorResourcesInitializer.initialize(resources, forms); >> >> // Create a validator with the userForm >> Validator validator = new Validator(resources, "userFormEx"); >> >> // Tell the validator which bean to validate against. >> validator.addResource(Validator.BEAN_KEY, userForm); >> >> // Validate the checkoutForm object and store the validation >> >> >results > > >> try { >> // Execute the validation rules >> ValidatorResults results = validator.validate(); >> >> if (log.isDebugEnabled()) { >> log.debug(results.getResultValueMap()); >> } >> } catch (ValidatorException ex) { >> // Log the validation exception >> log.warn("A validation exception occurred", ex); >> } >> >>Any help is appreciated. >> >>Thanks, >> >>Matt >> >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> >> > > > -- Vic Cekvenich, Struts Instructor, 1-800-917-JAVA Advanced <a href ="baseBeans.com">Struts Training</a> and project recovery in North East. Open Source <a href ="baseBeans.com">Content Management</a> basicPortal sofware Best practice<a href ="baseBeans.com">Struts Support</a> v.1.1 helper ScafflodingXPress --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]