Well Steve put it plain and simple and correctly. I
may be didn't get it right. I sort of thought you had
a view related object that your domain object was
extending. That wouldn't be good.
But, passing plain ol' domain objects on up to the
jsps is superbly simple!
- gene
-- From Steve --
Actually, passing middle tier object to the view does
not violate the
best
practice that says "do not let your
lower tiers depend on the upper ones." That's a good
best practice,
but
passing a middle tier or model object the view doesn't
violate that.
It
introduces a dependency from the from the upper to the
lower tiers --
which
is OK, and exists anyway. In the MVC, the view (JSP)
depends on the
model
(domain objects), but not vice versa. So having a
view look at a model
object is perfectly natural. Having the controller
(action) put a
model
object where the view (JSP) can see it is also normal.
Just make sure
the
model object doesn't know anything about the view or
controller.
MVC dependencies:
Model <-- View (jsp)
^ ^
| |
Controller (action)
Of course sometimes you need a buffer between the view
and the model,
to
handle special formatting needs, etc. So the view
helper pattern can
be
useful. But you don't need to do it everywhere up
front. That just
creates
an extra layer of indirection, and extra maintenance
as the view and
model
beans have to be kept in sync. Especially on a large
project, this can
be a
headache. You can always start off using the actual
domain object in
the
JSP, and transparently slide in a view helper later if
you need to:
package my.view;
public class UserView {
{
my.domain.User user;
public UserView()
{
user = new my.package.domain.User();
}
public getName() { return user.getFirstName() + " " +
user.getLastName(); }
}
If necessary, UserView could extend User, to keep it
the same type.
But
since most JSP tags use reflection, you really only
have to match up
the
method names with whatever's being used on the JSP.
Is the following JSP snippet using a User object or a
UserView object?
<bean:write name="user.name"/>
You can't tell. The JSP doesn't know or care. The
action can always
slide
in a UserView after the JSP has been written, if
required. If the
actions
get the user object from some factory method, the
change from User to
UserView can be transparently made in one place. It's
simpler to start
off
with using the the real model object, and only add
extra stuff
when/where
needed. Keep it simple.
IMHO.
Steve
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]