• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display custom message for inputText field of integer type

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hi All,

rowNo is integer type property.


Now When jsf page renders RowNum input field will be rendered by default with 0 value. If the User enters alphabets then i should display validation message as "Enter Only Digits".

But I am getting the below validation message:

InsertForm:rowNum: 'shf' must be a number between -2147483648 and 2147483647 Example: 9346

How to display "Enter Only Digits" message for rowNum field of integer type

 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I suppose in your case, validation phase and Update Bean value phase has already been passed.
Your action method is basically tired to Invoke Application phase which comes after the validation
phase and validation on your data was already done with the appropriate messages. Thats what i
feel. Not sure though as i am also new in JSF.

Try to use a validator attribute inside that h:inputText and bind it to some user defined
custom validator. An example can be an email and it would look something like


This should help ideally.
HTH,
 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srikanth

You can override the defualt conversion message of the JSF, using the attribute converterMessage and for validation Messages you can use the validatorMessage in your case you must you use the coverterMessage as follow:

Regards
Cesar
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops!!

Cesar, thanks for sharing the insight It was so simple. Thanks for adding to our knowledge.

BR,
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given a choice, a validator is generally the best approach. It makes the action logic simpler. JSF likes to do an atomic update of the backing bean properties and that's easier to do when validators are used, since the bean has already been updated - possibly with bad values - if you attempt to do validation in the action method. Also, when you're talking binary object updates, attempts to update with blatantly bad values can end up with JSF throwing exceptions itself.

It is certainly possible to do custom messages. Whatever message text you supplied when you construct and throw the ValidatorException will be used as the message text for the
"messages" and "message for=" tags to display.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tim,

Can you describe the term binary updates? I am a little confused in this term.

Thanks,
 
srikanth Thandra
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hi Cesar Loachamin ,

I worked out with your suggestion and it worked well.
Thankx for the quick reply.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prithvi Sehgal wrote:Hello Tim,

Can you describe the term binary updates? I am a little confused in this term.

Thanks,



All items on a web page are text. But that doesn't mean that the control value properties in a backing bean have to all be String objects. You can define control value to reference an integer, floating-point, or Date object, for example. In the cases of integer and float, there are automatic converters that handle the job of taking the text from the page submission, converting it to binary (integer or float formats), and invoking the binary "set" methods such as "setField(int newValue)". In the case of Dates, you have to provide an explicit converter reference if you want to format your displayed date/time values in a format other than the default that the Date toString method uses.
 
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic