• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying component id for error message  RSS feed

 
John Tannel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay,

So where I was previously working we were using Tomcat 6, JSP 2.1, JSF 1.2 using Sun's RI. When we would display error messages using <h:messages> it would show the id of the component where the error occurred.

Now, I am working on a site for a family member. We are using Tomcat 5.5, JSP 2.0 and JSF 1.1 because the web host only lets us use Tomcat 5.5. The error messages do not display the same way, they now only show the error message itself and not any information about which component id caused the error.

Is this because we are using JSF 1.1 instead of 1.2? I believe that is the reason but I thought maybe someone on the forums here could verify. If that is the case, do I have any options besides writing custom validators to include the details myself?

Thanks!

John
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John

Yes, the problem is because you are using JSF 1.1 this version display only generic messages, in JSF 1.2 the components have a label attribute the value of this attribute is used in the message showed with <h:messages>, when you do not specify a value for the label attribute the jsf implementation use the ID of the component.

I think the option of custom validator is the best option, but you have another options, for example you can change the text of the standard error using a message bundle but you need to replace all the generic messages, or you can set the type of the properties in the Managed Bean as String and check if they are valid and if not you can add a message it will be displayed in the <h:messages />.



Regards

Cesar
 
John Tannel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cesar,

Thanks for the information! The main reason I wanted that level of detail was so I could have one location for errors, but indicate to the user which component is causing the problem (usually for missing or misformed inputs - $1,234 instead of 1234 for example). I can solve this by simply using separate message components for each input component. It is not quite the low maintenance solution I had hoped for but will work fine nonetheless. Thanks again!

John
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!