You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by dh...@lexmark.com on 2001/06/19 20:15:23 UTC

Breaking MVC separation?


I have a small architectural question...

I have a LoggingForm bean for displaying the logging parameters on our own
server.  This contains several variables - boolean whether logging enabled,
String current severity, Vector of possible severities, along with Vector of
categories, each of which is a Parameter object holding key, value, description.

I have a server bean which encapsulates all calls to the Server, and all of the
above variables are obtained from one call to the server which returns a list
containing the above in a specified order.  My question is whether it is okay to
pass the LoggingForm to the server bean and have it fill all the variables at
once, or is this breaking the MVC separation?  Should I, instead, call the
server bean each time, to get/set each of the variables?

I know all this gets a little fuzzy at times, but would appreciate any input.

Thanks,

Dave




Re: Breaking MVC separation?

Posted by Mike Thompson <mr...@instanton.com>.
Everyone is saying use value objects.  So you have your ServerBean return a
java class that just implements java.io.Serializable which is passed back to
your client.  Client does what it wishes to this value object, which is
where all the get/set methods are.  You can do validation here if you
please.  Then when you are ready to update, just pass the value object back
and tada, you have all your parameters set in one foul swoop.  So I
typically have something like

public class ServerObject (this is your EJB)
{
    public ServerModel getDetails() throws java.rmi.RemoteException
    {
        ...
    }

    public void update(ServerModel model)
        throws java.rmi.RemoteException,
SomeAppExceptionForInvalidStateIfYouLike
    {
        ...
    }
}

public class ServerModel implements java.io.Serializable
{
    public String getProperty1() {}
    public void setProperty1(String prop) {}
    public int getProperty1() {}
    public void setProperty1(int prop) {}
}

----- Original Message -----
From: <dh...@lexmark.com>
To: <st...@jakarta.apache.org>
Sent: Tuesday, June 19, 2001 1:15 PM
Subject: Breaking MVC separation?


>
>
> I have a small architectural question...
>
> I have a LoggingForm bean for displaying the logging parameters on our own
> server.  This contains several variables - boolean whether logging
enabled,
> String current severity, Vector of possible severities, along with Vector
of
> categories, each of which is a Parameter object holding key, value,
description.
>
> I have a server bean which encapsulates all calls to the Server, and all
of the
> above variables are obtained from one call to the server which returns a
list
> containing the above in a specified order.  My question is whether it is
okay to
> pass the LoggingForm to the server bean and have it fill all the variables
at
> once, or is this breaking the MVC separation?  Should I, instead, call the
> server bean each time, to get/set each of the variables?
>
> I know all this gets a little fuzzy at times, but would appreciate any
input.
>
> Thanks,
>
> Dave
>
>


Re: Breaking MVC separation?

Posted by Ted Husted <hu...@apache.org>.
Something I'm looking at now is having the various beans expose their
content as hashmaps that could be used with the populate method in
BeanUtils. If your ActionForm bean's methods matched what the server
bean returned, the Action could handle getting the map and passing it to
ActionForm bean from bean populate. 

populate( myActionFormBean, myServerBean.toMap() );

Using hashmaps for configuration is a very common technique, and
exposing values as strings is also common, so bulding a toMap() method
into into a data access or value object bean seems like a Good Thing --
with or without Struts. 

Personally, I would say that it is OK to design your ActionForm beans
methods to match the server bean (but not the other way around). 

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

dhay@lexmark.com wrote:
> 
> I have a small architectural question...
> 
> I have a LoggingForm bean for displaying the logging parameters on our own
> server.  This contains several variables - boolean whether logging enabled,
> String current severity, Vector of possible severities, along with Vector of
> categories, each of which is a Parameter object holding key, value, description.
> 
> I have a server bean which encapsulates all calls to the Server, and all of the
> above variables are obtained from one call to the server which returns a list
> containing the above in a specified order.  My question is whether it is okay to
> pass the LoggingForm to the server bean and have it fill all the variables at
> once, or is this breaking the MVC separation?  Should I, instead, call the
> server bean each time, to get/set each of the variables?
> 
> I know all this gets a little fuzzy at times, but would appreciate any input.
> 
> Thanks,
> 
> Dave