This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes How to check if a particular error is present ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to check if a particular error is present ? " Watch "How to check if a particular error is present ? " New topic

How to check if a particular error is present ?

Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
I add a number of errors in my action class , say

Error3 ...

Now in my JSP page is there any way to find out if a particular error is present in html:errors

In my JSP , I display all the errors as Popup . But in my jsp, now I need to find if "ErrorGeneral" is present in <html:errors/> tag , so that I can take a different course of action for this .
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you use the add method of ActionMessages, the first parameter can be used to categorize the messages. If it is a general error, you should use the constant ActionMessages.GLOBAL_MESSAGE as the first parameter. If it is an error specific to a property, use the property name as the first parameter (e.g. messages.add("userName", new ActionMessage(...)); ).

Then, in your JSP you can filter what is retrieved in <html:errors> by specifying a property attribute. In the above example, if you specify <html:errors property="userName" /> you will get only userName messages. If you want only global messages, specify:

<html:errors property="<%=org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE %>" />

Consultant, Sima Solutions
I agree. Here's the link:
subject: How to check if a particular error is present ?