You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pan Li <pu...@yahoo.com.cn> on 2001/07/14 10:03:59 UTC

How do I shape this application to match Struts?

Hi all!
Currently I have to rewrite a web application use
struts.

Currently all type of data is accessed via one EJB(so
called "DataPakage"),
the "DataPakage" is basically a map of database table,

For example,a "DataPakage" of a "People" will have
these "Field":name,age,sex etc.
the jsp use some code like"<%=
dataPackage.getField("name") %>"to get the data.

I'm wonder if this is confilced with the cluture of
struts.Since many struts sample 
I've seen will define a class for every data
type(usually as a ActionForm),and use some
 code like"<strutsbean:write  name="pepleForm"
property="name"  />" to access the data.
 
So their solution is focus on database table,while
struts solution is more OO.

I don't want to touch their tons of EJBs,but how can I
shape their code to match the normal solution of 
struts?or reverse?

Pan.

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Re: How do I shape this application to match Struts?

Posted by Ted Husted <hu...@apache.org>.
Most of the Struts samples are meant to demonstrate coding patterns,
rather than overall architecture. So, you should not take them ~too~
seriously ;-)

IMHO, the framework's design makes it an adapter between your model
(whatever it may be) and HTTP. A Struts application should adapt to your
model -- not the other way around! 

I would suggest that you think about a custom tag that could read the
DataPackage directly, and just output the fields, so it would look
something like 

<app:dataPackage name="people" field="age"/>

For retrievals, you could then retrieve the DataPackage in your Action,
and just put it into request scope.

You might want to take a look at the RowSet Tags on More About Struts,
which does something similar with retrieving columns from a RowSets. 

< http://husted.com/about/struts/resources.htm#new >

For input, don't be afraid to construct larger ActionForms if it meets
your needs. Some developers like to use smaller ActionForms since it
simplifies the validation. But, the ActionMapping is passed to
validate(), and that can be used to perform selective validation, if
that's what you want (along with strategies like hidden fields). So, if
convenient, go ahead and construct one ActionForm for a DataPackage that
contains all of it's fields, regardless of what table they came from. 

In general, I would personally recommend thinking of ActionForms as the
representation of the "logical views" of a model, which may include
fields from several tables. They represent what the actor sees, rather
than what the model stores.

Your ActionForms may also have some type of a bulk accessor that matches
how the DataPackages accept data for insert or update. Again, IMHO, the
ActionForm can be adapted to the needs of your model, by any means
necessary.

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


Pan Li wrote:
> 
> Hi all!
> Currently I have to rewrite a web application use
> struts.
> 
> Currently all type of data is accessed via one EJB(so
> called "DataPakage"),
> the "DataPakage" is basically a map of database table,
> 
> For example,a "DataPakage" of a "People" will have
> these "Field":name,age,sex etc.
> the jsp use some code like"<%=
> dataPackage.getField("name") %>"to get the data.
> 
> I'm wonder if this is confilced with the cluture of
> struts.Since many struts sample
> I've seen will define a class for every data
> type(usually as a ActionForm),and use some
>  code like"<strutsbean:write  name="pepleForm"
> property="name"  />" to access the data.
> 
> So their solution is focus on database table,while
> struts solution is more OO.
> 
> I don't want to touch their tons of EJBs,but how can I
> shape their code to match the normal solution of
> struts?or reverse?
> 
> Pan.
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/

Re: How do I shape this application to match Struts?

Posted by Ted Husted <hu...@apache.org>.
For input, I would suggest that you create an ActionForm for each
DataPackage. 

For output, I would suggest that you create a custom tag that can access
the DataPackage fields directly. 

Using ActionForms to represent larger views of the data is an
interesting topic, but I'm not sure if it applies to your project, if
the DataPackages are "basically a map of the database table", and your
application can input to one DataPackage at a time.

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


Pan Li wrote:
> 
> Ted,thanks a lot.
> 
> So your suggestion is to use an ActionForm as an
> "view" of all database tables.So how would I resove
> these problems?
> 
> 1.When use JSP to input data.
> If the JSP has an input field named "foo" and the
> ActionForm has a property named "foo",Struts will fill
> the property "foo" with the value of input filed "foo"
> (If I'm not wrong).
> But my ActionForm will not has a property "foo".
> 
> 2.Validation
> It seems that validation will be much harder.
m/

Re: How do I shape this application to match Struts?

Posted by Pan Li <pu...@yahoo.com.cn>.
Ted,thanks a lot.

So your suggestion is to use an ActionForm as an
"view" of all database tables.So how would I resove
these problems?

1.When use JSP to input data.
If the JSP has an input field named "foo" and the
ActionForm has a property named "foo",Struts will fill
the property "foo" with the value of input filed "foo"
(If I'm not wrong).
But my ActionForm will not has a property "foo".

2.Validation
It seems that validation will be much harder.

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/