Issue Details (XML | Word | Printable)

Key: SHALE-325
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Wendy Smoak
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Shale

Add a custom validation example to the Use Cases example app

Created: 06/Nov/06 10:23 PM   Updated: 23/Jan/07 04:40 PM
Return to search
Component/s: Validator
Affects Version/s: None
Fix Version/s: 1.0.4


 Description  « Hide
Add an example of using a custom validator to the Commons Validator Integration section of the use-cases example app.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Wendy Smoak added a comment - 06/Nov/06 10:43 PM
See: http://svn.apache.org/viewvc?view=rev&rev=471907

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)


Gary VanMatre added a comment - 06/Nov/06 11:24 PM
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>


Wendy Smoak added a comment - 07/Nov/06 02:29 AM

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?

Rahul Akolkar added a comment - 07/Nov/06 06:16 AM
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.

Rahul Akolkar added a comment - 19/Nov/06 04:41 AM
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.

Craig McClanahan added a comment - 14/Dec/06 01:21 AM
Looks like no other comments, so I'll go ahead and close this as FIXED.