struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pontarelli <>
Subject Re: SmartURLs MailReader Example (was Re: Should I announce SmartURLs or wait?)
Date Tue, 02 Oct 2007 14:58:14 GMT
Finally got a chance to look this over. Here's a few things:

1. You don't need action annotations unless you are actually doing work. 
You can safely hit URLs without actions and only results. I noticed that 
you had a empty Hello action and a number of actions inside classes that 
didn't do anything (i.e. login-input inside Login). My favored pattern 
is to keep it simple like this:

===== code =====
package actions;
@Result(name="success", location="bar", type="redirect-action")
public class Foo extends ActionSupport {

===== JSP =====

Links into the foo form reference foo-input and the form submits to foo. 
You can also do the GET/POST check that Rails suggests and collapse 
everything to just foo. In most cases I just use inline redirect actions 
for cancel buttons and redirect after post and this reduces the clutter 
even more.

2. I tend to shy away from multiple actions inside classes. For crud I 
use s:action for form preparation (this is actually better because it 
reduces overhead of preparing the form on success). For other types of 
forms, if I have to share logic (rarely) I use a base class, but 
otherwise I just make one class per URL. In most re-use cases I 
introduce re-usable services in a separate tier to clean out actions and 
make the one action per URL simpler to code.

3. Likewise, I try to avoid heavy re-use of result pages and try to 
stick with the convention based approach. It seems to make the code more 
readable and easy to get into. For CRUD I setup something like this:

==== Classes ==== - Fetches the existing entities for display - Used only via the s:action and implements Action - Fetches an existing entity and renders the edit form - Inserts a new entity - Updates the existing entity - Deletes an entity or entities

==== Results ====
add.jsp - Includes form.jsp and passes a parameter to set the action 
type (i.e. save)
edit.jsp - Includes form.jsp and passes a parameter to set the action 
type (i.e. update)
form.jsp - The CRUD form used for insert and update
list.jsp - Lists the current entities

I'm planning on putting up a CRUD demo for SmartURLs at some point, when 
I get time. This will help illustrate what I'm talking about a bit more.


Ted Husted wrote:
> I have a first run at a Zero Configuratinn,/SmartURLs MailReader under SVN at
>  *
> Everything is checked in, including the JARs (ugh!), and it should be
> easy to import as an IDE project.
> MailReader Zero uses no XML configuration, other than to set global
> options. It does use a lot of annotation, probably too much, but a lot
> of that could be resolved via additional conventions.
> I'd like this to be an "best practices" application, though I'm not
> sure if we yet know what all the best practices :), so comments and
> patches are welcome.
> I'm hoping to tag a JPA implementation on to this next.
> -Ted.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View raw message