• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to check if a particular error is present ?

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I add a number of errors in my action class , say

Error1
ErrorGeneral
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 .
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 %>" />
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic