I have an action that receives some parameters from user (e.g. date). This action produces many different reports, so it has many different methods. I need to tune those parameters (set a time to midnight) before every method. The prepare
method is executed before parameters are bound. Is there any other interceptor or any other convention that allows me to do that?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Use the
<interceptor-ref name="paramsPrepareParamsStack"/>
If you are using the Convention Plugin apply it on action
Another way to go (cheap if you are coding right now, expensive if you've already coded everything) would be to modularize every action you have to perform in one single Struts2 Action.
Then you will have something like an
BaseReportAction
, containing all the common attributes and methods shared usingprotected
instead ofprivate
, doing your tuning on parameters and the common operations in theexecute()
method;And one Action for each report extending the BaseReportAction, let's say
or
or also
And the only requirement would be using
super.execute();
as first statement of every child Action'sexecute()
method.This way you could take advantage of the inheritance, to have a lot of smaller, cleaner (eventually packaged into several sub-packages) Actions instead of one huge Action with a lots of methods.
All the utility methods used by few reports would be available only for those reports, not for all the others (let's say PDF and XLS stuff for example)...
You could benefit of the XML Validation too for different Actions (maybe one report requires different inputs from another).
Finally, your tuning-up code would be Thread-Safe (Actions are Thread-Safe, Interceptors don't).
But as said, this is a choice of implementation that better suits the pre-code phase (even if it's not that hard to refactor, according to the size of the web application...).