I want to display a dynamic error message ,i am having the code as
ActionMessages errors = new ActionMessages();
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.plan.foundForUser"));
saveErrors(reque开发者_如何学运维st, errors);
error.plan.foundForUser={1} Not Found
I want to replace 1 with a dynamic value,how to do so ?
In Struts 1.x, if you are trying to display an dynamic ActionMessage (type can be a String,Integer etc.) using Struts ActionMessages class please have a look at the below snippet:
ActionMessages msg = new ActionMessages();
msg.add(ACtionMessages.GLOBAL_MESSAGE, new ActionMessage(
"msg.displaymsg", new Object[] {"Message to be displayed"}));
In Property file we must set the property value like this:
msg.displaymsg={0}
Above defines that argument of zero holds the first value of Object ActionMessage.
Above worked for me.
You need to pass the variable to ActionMEssage like this,
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
"error.plan.foundForUser", new Object[] {"username"}));
精彩评论