struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yasser Zamani <yasserzam...@apache.org>
Subject Re: Struts2.x ActionError And ActionMessage
Date Fri, 17 Nov 2017 06:48:37 GMT


On 11/17/2017 9:12 AM, Yasser Zamani wrote:
> Hello Dhulipudi, Welcome!
> 
> Could you try below please....
> 
> ActionSupport myCurrentActionSupport = (ActionSupport) 
> ActionContext.getContext().getValueStack().peek();
> 
> myCurrentActionSupport.addActionError("my error");

Please remember if it even works, it's not a good design. I just try to 
know if you have an action context there where you're trying to add an 
error.

A better design maybe is to throw a specific exception if you're in 
lower layers than the action and action is not available there (e.g. 
you're in service layer) then simply catch that in your action and then ....

this.addActionError(e.getMessage());

Or don't catch this specific exception anywhere in actions and use 
global exception handling instead [1].

Regards,
Yasser.

[1] https://struts.apache.org/getting-started/exception-handling.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message