• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

errors.add() problem please help

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I want to display errors directly without writing key, value pairs in the properties file, i want to pass a string of my choice to errors.add("fatal error ") and make the <html:error> pick up the error and display on the JSP page, i know there is a way with message resource in the web.xml, but i am not sure.please help.
thanks
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

There is no option for this in struts but still its a very good farmework taht u can have ur customerrors which extends actionerrors and write a mwthod which just takes string and at the same time u need to write a custom tag <cutom:errors/>

CustomErrors will look like
public class IwebErrors extends ActionErrors implements Serializable {


public void add(String message) {

ActionMessageItem item = (ActionMessageItem) messages.get("exception");
List list = null;

if (item == null) {
list = new ArrayList();
item = new ActionMessageItem(list, iCount++);

messages.put("exception", item);
} else {
list = item.getList();
}

list.add(new ActionError(message));

}

}

and in ur tah just do the same as html:errors but in between add
if(message != null)
{
results.append(message);
}
else
{
results.append(report.getKey());
}

where message is the value of the key in resource bundle


i hope this would give a clue on how to go about
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!