Re: Simple way to configure an action?

2005-01-24 Thread Fredrik Jonson
On 2005-01-24, Larry Meadors [EMAIL PROTECTED] wrote:

 Maybe we are approaching this from the wrong direction. what is 
 the problem you are trying to solve?

Perhaps I am. I have an action which retrieves a couple of values
from a database. If the retreival fails, it return some reasonable
default values instead. It is these defaults which I want to be
user configurable, that is, configurable from some initialization
file. 

The introspection/set-parameter feature, found in PlugIns, would
solve my problem, but it isn't available for actions, only
actionmappings.

 On Sun, 23 Jan 2005 17:09:45 -0600, Eddie Bush [EMAIL PROTECTED] wrote:

 Actions are, effectively, singletons. [...]  This means actions have
 to be thread-safe, and suggests that the best place to configure
 things would be in the mapping itself, or some other way (resource
 bundle, propeties file, singleton, factory).

The action is specialized, it is only responsible for making sure the
values are set in the request's session, so it will not be called
from different actionmappings. Further, as soon as the action have
been instantiated the configurable member variables will be used as
read-only values. So there is no concurrency issue involved.

-- 
Fredrik Jonson


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Simple way to configure an action?

2005-01-24 Thread Larry Meadors
OK, I think i understand what you are trying to do. You could override
the constructor of your action to read in a properties file. If you
have multiple actions, you could make it a base class that uses some
common naming convention, that may simplify things.


On Mon, 24 Jan 2005 08:02:04 + (UTC), [EMAIL PROTECTED] wrote:
 On 2005-01-24, Larry Meadors [EMAIL PROTECTED] wrote:
 
  Maybe we are approaching this from the wrong direction. what is
  the problem you are trying to solve?
 
 Perhaps I am. I have an action which retrieves a couple of values
 from a database. If the retreival fails, it return some reasonable
 default values instead. It is these defaults which I want to be
 user configurable, that is, configurable from some initialization
 file.
 
 The introspection/set-parameter feature, found in PlugIns, would
 solve my problem, but it isn't available for actions, only
 actionmappings.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Simple way to 'configure' an action?

2005-01-24 Thread fzlists
Another possible approach is to create a DefaultValues class, something along 
these lines:

public class DefaultValues {
  private HashMap defaultValues;
  {
setDefaultValues();
  }
  public static HashMap getDefaultValues() {
return defaultValues;
  }
  private static void setDefaultValues() {
// Insert code to read in property file here
// and store them in defaultValues
  }
  public static void resetDefaultValues() {
setDefaultValues();
  }
}

The benefit I think is that it keeps your default values independant of the 
Actions.  Having the resetDefaultValues() method gives you a way to 
reinitialize the values without taking your app down (i.e., maybe on an Admin 
page you provide a Reset Default Values button that results in that method 
being called).  By putting the property file read in the Action constructor, 
I'm not sure you'd be able to do this since Struts creates the one instance of 
your Action and gets a reference to it per request.  I suppose you could do the 
above in an Action essentially and call setDefaultValues() from the constructor 
rather than a static initializer, but then you get into the question of whether 
that's thread-safe, since an Action has to be.

In either case, just mentioning another possibility. :)

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Mon, January 24, 2005 8:13 am, Larry Meadors said:
 OK, I think i understand what you are trying to do. You could override
 the constructor of your action to read in a properties file. If you
 have multiple actions, you could make it a base class that uses some
 common naming convention, that may simplify things.
 
 
 On Mon, 24 Jan 2005 08:02:04 + (UTC), [EMAIL PROTECTED] wrote:
 On 2005-01-24, Larry Meadors [EMAIL PROTECTED] wrote:

  Maybe we are approaching this from the wrong direction. what is
  the problem you are trying to solve?

 Perhaps I am. I have an action which retrieves a couple of values
 from a database. If the retreival fails, it return some reasonable
 default values instead. It is these defaults which I want to be
 user configurable, that is, configurable from some initialization
 file.

 The introspection/set-parameter feature, found in PlugIns, would
 solve my problem, but it isn't available for actions, only
 actionmappings.

 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: Simple way to configure an action?

2005-01-24 Thread Jim Barrows
On Mon, 24 Jan 2005 06:13:23 -0700, Larry Meadors
[EMAIL PROTECTED] wrote:
 OK, I think i understand what you are trying to do. You could override
 the constructor of your action to read in a properties file. If you
 have multiple actions, you could make it a base class that uses some
 common naming convention, that may simplify things.

You could also implement this as a filter, which will give you more
options then an action for this kind of thing.  Espeically in terms of
adding this check to a lot of different URLS.

 
 
 On Mon, 24 Jan 2005 08:02:04 + (UTC), [EMAIL PROTECTED] wrote:
  On 2005-01-24, Larry Meadors [EMAIL PROTECTED] wrote:
 
   Maybe we are approaching this from the wrong direction. what is
   the problem you are trying to solve?
 
  Perhaps I am. I have an action which retrieves a couple of values
  from a database. If the retreival fails, it return some reasonable
  default values instead. It is these defaults which I want to be
  user configurable, that is, configurable from some initialization
  file.
 
  The introspection/set-parameter feature, found in PlugIns, would
  solve my problem, but it isn't available for actions, only
  actionmappings.
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Simple way to configure an action?

2005-01-24 Thread Joe Germuska
Eddie Bush's solution is the right one.  The ActionMapping is 
specifically intended for the purpose you have in mind, and is 
available every time an Action's execute method is called.  Even if 
the Action will not be called from different action mappings, it will 
always have one action mapping.  What's the problem with reading the 
values from the ActionMapping when the action executes?

I'm generally believing that the original motivation for Struts to 
work this way (pool actions instead of creating one per request) has 
proven not to be all that useful, and some of the benefits of being 
able to treat an Action as a request-scoped instance are part of what 
people like about frameworks like Webwork.  It might be worth 
investigating whether there actually are meaningful performance 
implications to instantiating an Action upon every request, although 
a bug in the Struts Chain code (fixed only a month or two ago) was 
causing this very situation, and it didn't have a noticeable impact 
on a production application I had built upon it.

Don Brown's Struts-Spring project had a proxy action which created a 
new Action instance for each request based on a Spring configuration. 
The project is discontinued in favor of equivalent behavior in the 
Spring core, but you can get the details on that (and a link to 
currently active substitutes) at
http://struts.sourceforge.net/struts-spring/index.html

Joe
At 8:02 AM + 1/24/05, Fredrik Jonson wrote:
On 2005-01-24, Larry Meadors [EMAIL PROTECTED] wrote:
 Maybe we are approaching this from the wrong direction. what is
 the problem you are trying to solve?
Perhaps I am. I have an action which retrieves a couple of values
from a database. If the retreival fails, it return some reasonable
default values instead. It is these defaults which I want to be
user configurable, that is, configurable from some initialization
file.
The introspection/set-parameter feature, found in PlugIns, would
solve my problem, but it isn't available for actions, only
actionmappings.
 On Sun, 23 Jan 2005 17:09:45 -0600, Eddie Bush [EMAIL PROTECTED] wrote:
 Actions are, effectively, singletons. [...]  This means actions have
 to be thread-safe, and suggests that the best place to configure
 things would be in the mapping itself, or some other way (resource
 bundle, propeties file, singleton, factory).
The action is specialized, it is only responsible for making sure the
values are set in the request's session, so it will not be called
from different actionmappings. Further, as soon as the action have
been instantiated the configurable member variables will be used as
read-only values. So there is no concurrency issue involved.
--
Fredrik Jonson
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
Narrow minds are weapons made for mass destruction  -The Ex

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Simple way to configure an action?

2005-01-23 Thread Eddie Bush
Actions are, effectively, singletons.  There is a single instance
created, no matter how many mappings use it.  This means actions have
to be thread-safe, and suggests that the best place to configure
things would be in the mapping itself, or some other way (resource
bundle, propeties file, singleton, factory, ... ), depending on what
you're really trying to do.

On Sun, 23 Jan 2005 22:42:20 +0100, Fredrik Jonson
[EMAIL PROTECTED] wrote:
 Hello,
 
 I've only just started using struts, so I need some input on
 how to approach struts designs...

snip /

-- 
Eddie Bush

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Simple way to configure an action?

2005-01-23 Thread Larry Meadors
Maybe we are approaching this from the wrong direction...what is the
problem you are trying to solve?


On Sun, 23 Jan 2005 17:09:45 -0600, Eddie Bush [EMAIL PROTECTED] wrote:
 Actions are, effectively, singletons.  There is a single instance
 created, no matter how many mappings use it.  This means actions have
 to be thread-safe, and suggests that the best place to configure
 things would be in the mapping itself, or some other way (resource
 bundle, propeties file, singleton, factory, ... ), depending on what
 you're really trying to do.
 
 On Sun, 23 Jan 2005 22:42:20 +0100, Fredrik Jonson
 [EMAIL PROTECTED] wrote:
  Hello,
 
  I've only just started using struts, so I need some input on
  how to approach struts designs...
 
 snip /
 
 --
 Eddie Bush
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]