• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

errors.add() problem please help

 
pradeep arum
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
 
sreenath reddy
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