File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to call a Validator when the input-field is empty? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to call a Validator when the input-field is empty?" Watch "How to call a Validator when the input-field is empty?" New topic
Author

How to call a Validator when the input-field is empty?

Manfred Ruebinger
Greenhorn

Joined: Jun 25, 2007
Posts: 4
How can i call a Validation-Method or class when the input of an h:inputtext is empty?

Validation is only called when an input was entered in an inputfield.

Any ideas? thanks!!
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
Here is one idea: don't do it!
I'm not sure why you would want to validate something that has no value to validate .
Maybe if you explain a little more what do you want to do...


Gabriel
Software Surgeon
Manfred Ruebinger
Greenhorn

Joined: Jun 25, 2007
Posts: 4
My problem is, that i want to use different Message-Bundles, each for an other application. E.g.

Application1 use application1.properties
Application2 use application2.properties
Application3 use application3.properties

The stupid on this thing is, that customized messages are overriden from the following message-bundles.

It is not a locale-thing! Just many applications.



Like this:

application1.properties
javax.faces.component.UIInput.REQUIRED=Input needed

application2.properties
javax.faces.component.UIInput.REQUIRED=Please type something useful

application3.properties
javax.faces.component.UIInput.REQUIRED=Hello World


The last message from application3.properties wins, the previous messages are ignored by validation. On every application, when an input field is empty, the shown message is "Hello World".

To solve this problem i want to create an own validator who reads the message-bundle which belong to the application and returns the correct error-value. But this doesnt work, because empty fields are not validated.

I am using MyFaces 1.1.5 which does not have the implementation-features from JSF-RI 1.2, where you can use the "requiredMessage"-attribute from the tags: http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/h/inputText.html

Any idea how i can solve this problem? I think i am not the only one who has this problem.
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
Why cant you do the validation in your action or actionListener?
Do not put required=true for the field. And in your action/actionListener check first to see if it is blank. If blank, then


Hope this helps.
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
Hmmm... should be a way to specify the bundle for each application, and write validators for each field you need a different message seems too much work!
I'm assuming the applications share the same page and JSF configuration.
Where is the specific application selected? How you distinguish one app from the other? Maybe when the app is started you can programatically set the right bundle (or better, inject it through JSF config).
Just an idea, maybe I'm totally wrong
Manfred Ruebinger
Greenhorn

Joined: Jun 25, 2007
Posts: 4
Hello A. Dusi,
thank you for your hint, i tried this solution. Hope that MyFace 1.1.6 will support JSF-RI 1.2
 
jQuery in Action, 2nd edition
 
subject: How to call a Validator when the input-field is empty?
 
Similar Threads
Click on the button
Conditional Validation Determined By Which Button Was Clicked
Loosing changes in html:select
validation with struts and tiles
strut validation frame work issue