Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Manfred Ruebinger
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Manfred Ruebinger
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello A. Dusi,
thank you for your hint, i tried this solution. Hope that MyFace 1.1.6 will support JSF-RI 1.2
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic