You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Asad Habib <ah...@engin.umich.edu> on 2006/03/27 22:56:45 UTC

Struts and Result Beans

What is the best way to use result beans with Struts (i.e. beans that are 
not associated with a form). In particular, I have a plugin class that's 
called by the Struts action servlet upon startup and this class calculates 
the current date. This date needs to be stored in a bean having session 
scope and displayed on all pages in the application. Currently, this bean 
is being instantiated in one of my actions and placed in session scope.

Is this the best way to achieve this? Also, should I be using a plugin 
class for this? Lastly, is there a design pattern that I could follow to 
achieve this? I am trying to use best practices without adding too much 
complexity and overhead (i.e. EJB is overkill).

Your input would be appreciated and if you know of any articles that 
discuss this, please send me the URLs. Thank you.

- Asad

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and Result Beans

Posted by Asad Habib <ah...@engin.umich.edu>.

On Mon, 27 Mar 2006, Dave Newton wrote:

> Asad Habib wrote:
>> Well, your right since the date will be shared by all sessions.
>> However, if I go this route I will need a method to update the date
>> every time it changes.
>
> You need that anyway, as a user might be on the site over the midnight hour.
>
> The bean can just return the current date every time the accessor is called.
>
>> Sorry, I mean a design pattern that outlines how non-form beans should
>> be used with Struts actions. Is a DTO applicable in this case?
>
> Sure.
>
> Just out of curiosity, what other design patterns were you considering?

This is the only one that I could think of that was applicable. If you 
know of any others, please let me know. Thanks.

> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and Result Beans

Posted by Dave Newton <ne...@pingsite.com>.
Asad Habib wrote:
> Well, your right since the date will be shared by all sessions.
> However, if I go this route I will need a method to update the date
> every time it changes.

You need that anyway, as a user might be on the site over the midnight hour.

The bean can just return the current date every time the accessor is called.

> Sorry, I mean a design pattern that outlines how non-form beans should
> be used with Struts actions. Is a DTO applicable in this case?

Sure.

Just out of curiosity, what other design patterns were you considering?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and Result Beans

Posted by Asad Habib <ah...@engin.umich.edu>.
On Mon, 27 Mar 2006, Dave Newton wrote:

> Asad Habib wrote:
>> What is the best way to use result beans with Struts (i.e. beans that
>> are not associated with a form). In particular, I have a plugin class
>> that's called by the Struts action servlet upon startup and this class
>> calculates the current date. This date needs to be stored in a bean
>> having session scope and displayed on all pages in the application.
>> Currently, this bean is being instantiated in one of my actions and
>> placed in session scope.

> Um... well, I would probably just place an instance of the "date
> calculator bean" in the application scope unless you anticipate the date
> being different for different users and not bother with the session
> scope for something like this.

Well, your right since the date will be shared by all sessions. However, 
if I go this route I will need a method to update the date every time it 
changes.

> I suppose a plugin is as good a place as any to instantiate a date
> calculation bean.
>
>> Lastly, is there a design pattern that I could follow to achieve this?
>
> A design pattern for putting a date calculation bean into a scope? You
> might be over-analyzing this ;)

Sorry, I mean a design pattern that outlines how non-form beans should 
be used with Struts actions. Is a DTO applicable in this case?

>
>> (i.e. EJB is overkill).
>
> Ya' think?
>
> IIRC Frank's Java WebParts has a class (filter?) that will make sure
> things are put into the appropriate scope based on a set of rules (I
> like filters for things like this since they're not attached to Struts)
> and it beats re-inventing it like I have several times and you don't
> need to use a larger framework like Spring for "mini-IoC" things.
>
> http://javawebparts.sourceforge.net/
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and Result Beans

Posted by Dave Newton <ne...@pingsite.com>.
Asad Habib wrote:
> What is the best way to use result beans with Struts (i.e. beans that
> are not associated with a form). In particular, I have a plugin class
> that's called by the Struts action servlet upon startup and this class
> calculates the current date. This date needs to be stored in a bean
> having session scope and displayed on all pages in the application.
> Currently, this bean is being instantiated in one of my actions and
> placed in session scope.

Um... well, I would probably just place an instance of the "date
calculator bean" in the application scope unless you anticipate the date
being different for different users and not bother with the session
scope for something like this.

I suppose a plugin is as good a place as any to instantiate a date
calculation bean.

> Lastly, is there a design pattern that I could follow to achieve this? 

A design pattern for putting a date calculation bean into a scope? You
might be over-analyzing this ;)

> (i.e. EJB is overkill).

Ya' think?

IIRC Frank's Java WebParts has a class (filter?) that will make sure
things are put into the appropriate scope based on a set of rules (I
like filters for things like this since they're not attached to Struts)
and it beats re-inventing it like I have several times and you don't
need to use a larger framework like Spring for "mini-IoC" things.

http://javawebparts.sourceforge.net/

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org