Search code examples
javastruts-1

How to get the name of the action from inside the form bean


Is it possible to know which action (method in a predefined map) will be executed from inside the form bean?

Based on the name of the method that will be executed I want to decide if some properties will be rested or not before reach the action.


Solution

  • The ActionMapping is available inside most ActionForm methods, which includes the ActionConfig.

    That said: forms shouldn't have to know how they're being used; the responsibility for deciding what's in the form bean should live outside of the form, e.g., the action. This is what you're doing anyway--you're just putting the logic for that in the form.

    This makes the bean needlessly complex since it now has to understand all of the ways in which it can be used, rather than isolating that logic in the real determiner of what should be in the bean.

    I'd argue that you should create separate form beans, inheriting from a parent if there's enough shared logic–then there's even less work as it's just configuration.