tags:

views:

432

answers:

2

I've just inherited some old Struts code.

If Struts (1.3) follows the MVC pattern, how do the Action classes fill the View with variables to render in HTML ?

So far, I've seen the Action classes push variables in (1) the HTTP request with

request.setAttribute("name", user.getName())

(2) in ActionForm classes, using methods specific to the application:

UserForm form = (UserForm) actionForm;
form.setUserName(user.getName());

and (3) a requestScope variable, that I see in the JSP layer (the view uses JSP), but I can't see in the Action classes.

<p style='color: red'><c:out value='${requestScope.userName}' /></p>

So, which of these is considered old-school, and what's the recommended way of pushing variables in the View in Struts ?

+1  A: 

My Struts days are long over, but as far as I remember we used to place one view-specific bean (which would work as a holder for fine-graner beans or collections of beans) into the request scope within our Action.perform() implementation. This view-specific bean would then be rendered by the view.

Arno
A: 

As Struts 1.3 is considered old-school, I'd recommend to go with the flow and use the style that already is used throughout the application you inherited.

If all different styles are already used, pick the most used one. After that, pick your personal favourite. Mine would be 1 or 3 - the form (2) is usually best suited for data that will eventually be rendered inside some form controls. If this is the case - use the form, otherwise - don't.

Olaf