Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display appropriate error message in front of text field

 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am using standard convertor provide by JSF by default.
Its working fine but please tell me the way that how should i display the appropriate error message in front of particular text field.

Thanks
Regards
Gaurav
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configure your own property file for messages.
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
I am not talking about custom convertors , i am talking about the standard convertors which we get by default with JSF.Like :



Now like if it is not an Integer then it should display an error message in front of that text field , so i am asking about that how to show that error message.

Thanks
Gaurav
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant to say something like below


[ September 12, 2006: Message edited by: Adeel Ansari ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set application wide custom messages using these configurations

 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would like to replace the message "Validation Error: Value is required." by "Please enter the required value.".

Create a message bundle file in an appropriate package that you can choose, let's say, the file is called "MyErrors.properties" and is located in "WEB-INF/classes/com/example/i18n", thus the package name is "com.example.i18n".

In this file you write one single line:

javax.faces.component.UIInput.REQUIRED=Please enter the required value.

Now edit the faces configuration file (WEB-INF/faces-config.xml) and add the following entry in the application section:

<application>
<message-bundle>com.example.i18n.MyErrors</message-bundle>
</application>

Restart the web application and submit. If there is a required input field, you will see your customized message.

More details:
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
John Betts
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Green wrote:You would like to replace the message "Validation Error: Value is required." by "Please enter the required value.".

Create a message bundle file in an appropriate package that you can choose, let's say, the file is called "MyErrors.properties" and is located in "WEB-INF/classes/com/example/i18n", thus the package name is "com.example.i18n".

In this file you write one single line:

javax.faces.component.UIInput.REQUIRED=Please enter the required value.

Now edit the faces configuration file (WEB-INF/faces-config.xml) and add the following entry in the application section:

<application>
<message-bundle>com.example.i18n.MyErrors</message-bundle>
</application>

Restart the web application and submit. If there is a required input field, you will see your customized message.

More details:


Hi Richard. I am getting well all my internationalized messsages except the overriden JSF messages. Could you help me please?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if Richard is still around. This thread hasn't been touched since 2006!
 
John Betts
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:I don't know if Richard is still around. This thread hasn't been touched since 2006!


Thanks anyway Tim
 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get customized / localizated message, I defined the resource in faces-config and in top of the page I put


then, I use the bean-like notation:


in the label.properties i have:
username=Username
password=Password
required=required

if password is empty, the message "Password: required" is shown.
in the same way, if i use "${label.username}: ${label.required}"/>, the message "Username: required" is shown.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic