javastruts2jstlognlmodel-driven

The ideal strategy for calling beans using ModelDriven in Struts 2


I have used ModelDriven and getModel() method for calling POJO bean in action class.

But is it the best method? Which is best when it is required to call multiple beans model in one action?

Any other ideas in accessing a bean?


Solution

  • The easiest way to use multiple bean models in one action is to aggregate them to the bean returned by getModel() if you are using modelDriven interceptor.

    You cannot use multiple inheritance using the ModelDriven interface. You can use action class instead of ModelDriven, or use both.

    Actually, in Struts 2 you have to deal with the ValueStack on the view layer, however it's available to the ActionContext provided by the framework via handling a request, so you can use it everywhere.

    Any other ideas in accessing a bean?

    The bean is placed on top of the value stack that can be used in the view via OGNL or JSTL expressions. OGNL used in Struts tags or tags that are parsing OGNL, JSTL is used as usual but in Struts 2 it is also searching in the valueStack due to Struts 2 request wrapper.