File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes errors.add() problem please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "errors.add() problem please help" Watch "errors.add() problem please help" New topic

errors.add() problem please help

pradeep arum
Ranch Hand

Joined: Oct 01, 2003
Posts: 130
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.

Failure is not when you fall down; its only when you fail to get up again.
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415

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)

where message is the value of the key in resource bundle

i hope this would give a clue on how to go about
I agree. Here's the link:
subject: errors.add() problem please help
It's not a secret anymore!