This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "errors.add() problem please help" Watch "errors.add() problem please help" New topic
Author

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.
thanks


SCJP1.4,SCBCD
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: errors.add() problem please help
 
Similar Threads
errors.add() question
how to invoke errors.clear() from javascript
how to use html:errors
ActionError Problem
handling errors vs. warnings in Struts 1.38