tags:

views:

109

answers:

2

Hi ,

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(request, errors);
error.plan.foundForUser={1} Not Found

I want to replace 1 with a dynamic value,how to do so ?

A: 

You need to pass the variable to ActionMEssage like this,

       errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "error.plan.foundForUser", new Object[] {"username"}));
ZZ Coder
i have an list of users to be appended to the error messageerror.plan.foundForUser={1} Not Foundlike a,b,,c not found how to handle this and errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( "error.plan.foundForUser", new Object[] {"username"}));is not valid ,i am getting an error to remove second attribute
sarah
A: 

@sarah, what struts version are you using? @zz's code looks right to me and it shouldn't give you compilation error. By the way, if you want to append a list of users into {1} param, you probably need to loop through the users using StringBuilder to construct the "denormalize" string.

// loop through the list to construct comma delimited user names    
String allUsers = ...; 

errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "error.plan.foundForUser", "allUsers"));
limc