|
I think your problem is that the CommonsValidator can't find the message.
There are a couple of places that you can register a custom message. You can load the resource bundle within the page and use the msg attribute. <val:commonsValidator type="evenInteger" msg="#{messages['validate.test.not.even']}" server="true" client="false"/> -- or --- Register the resource bundle in the faces-config.xml <application> <locale-config> <default-locale>en</default-locale> <supported-locale>en</supported-locale> <supported-locale>fr</supported-locale> <supported-locale>de</supported-locale> <supported-locale>es</supported-locale> </locale-config> <message-bundle>org.apache.shale.usecases.view.Bundle</message-bundle> </application> The error message key is specified in the rule itself, in custom-rules.xml. <global> <validator name="evenInteger" classname="org.apache.shale.usecases.validator.CustomValidationUtil" method="isEven" methodParams="int" msg="validate.test.not.even"> </validator> </global> There is no <message-bundle> tag in faces-config, and adding it didn't help. The attribute for val:commonsValidator is 'message' (not msg). Adding that fixes the NPE, but see above-- the message is specified in the rule, I shouldn't have to say it again. What do I need to do so that CommonsValidator.getErrorMessage can "see" the resource bundle? Try again, it works for me. And adding <message-bundle> should, since the method in question looks up the application's message bundle for the "msg" attribute of (in this case, the custom) <validator>. The "message" attribute of <val:commonsValidator> gets priority, if present (which is nice, since it allows to change the "default" error message for the custom, or "built-in", validator).
On a separate note, we could do better than an NPE here, let me take a stab at that. Per my last comment, I've committed a fix for this (one of Gary's suggestions), see:
http://svn.apache.org/viewvc?view=rev&rev=476703 If there are no other comments in a couple of days, I will resolve this issue. Looks like no other comments, so I'll go ahead and close this as FIXED.
|
||||||||||||||||||||||||||||||||||||||||
This is incomplete. I added a third section on the 'Commons Validator Integration' page. If you enter an odd number for 'Priority', you get:
java.lang.NullPointerException
java.text.MessageFormat.applyPattern(MessageFormat.java:414)
java.text.MessageFormat.<init>(MessageFormat.java:368)
org.apache.shale.validator.CommonsValidator.getErrorMessage(CommonsValidator.java:965)
org.apache.shale.validator.CommonsValidator.validate(CommonsValidator.java:849)
javax.faces.component._ComponentUtils.callValidators(_ComponentUtils.java:157)
javax.faces.component.UIInput.validateValue(UIInput.java:312)
javax.faces.component.UIInput.validate(UIInput.java:353)
javax.faces.component.UIInput.processValidators(UIInput.java:183)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
javax.faces.component.UIForm.processValidators(UIForm.java:70)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:146)
org.apache.myfaces.lifecycle.LifecycleImpl.processValidations(LifecycleImpl.java:262)
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
org.apache.shale.application.faces.ShaleApplicationFilter.doFilter(ShaleApplicationFilter.java:267)