Re: Can I directly access properties in my ApplicationResources file?

2002-01-28 Thread Steven D. Wilkinson

The ActionServlet loads the MessageResources via the initApplication()
method.  One should really request the MessageResources from the
ActionServlet to eliminate extra I/O calls.  In general, Action classes
extend the ActionForm and can access these via the following call:

public class MyAction extends Action {

  public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException (

MessageResources recources = this.getServlet().getResources();

  }


Note, that an Action can gain access to the servlet via the call to the
getServlet() method.  See the Action class.  Once you have a reference
to the ActionServlet you can get the MessageResources via a call to the
getResources() on the ActionServlet.  Though a direct call to
getResourceAsStream() works, it's not as effective since the
ActionServlet has already loaded these values.

Note, the ActionForm also has access to these resource since the
ActionForm has a method getServlet().  One the MessageResources is
loaded in the ActionServlet most classes have access to this via the
ActionServlet.

Hope this helps,
Steve

Mike Olivieri wrote:
> 
> A similar approach is using the getResourceAsStream() method from any class.
> 
> InputStream propFileStream =
> getClass().getResourceAsStream("/com/companyname/appname/app.properties");
> Properties props = new Properties();
> props.load(propFileStream);
> 
> This works well for any kind of application, and will search the classpath
> rather than the filesystem for the properties file.
> 
> Sometimes, there can be an extreme proliferation of properties files. In a
> large app, you'll have potentially hundreds of properties. Make sure that your
> properties keys are descriptive enough that you could potentially combine them
> into one properties file. You wouldn't want to just use:
> driver=oracle.jdbc.drivers.OracleDriver
> Instead, use
> appname.subsystem.jdbc.driver=oracle.jdbc.drivers.OracleDriver
> 
> And finally, Mark is absolutely right about not mixing logic in your tiers.
> Make sure that any business logic you have is encapsulated in classes that are
> used by the Action class - don't put the business logic directly in the Action
> class. It's not really much more typing, and will actually be easier to debug
> and support... and reuse!
> 
> --- Mark Rines <[EMAIL PROTECTED]> wrote:
> > Scope, scope, scope. Once you're in your Action class, you are in the
> > business logic scope of your application. Your business logic should have
> > nothing to do with Struts, or any other non business related architectural
> > implementation ( such as Swing, JAAS, etc...), architecturally speaking. So,
> > use the classes and methods used for manipulating any other properties file,
> > which is just what the ApplicationResources.properties file is, no more, no
> > less. For more info see the Properties class , and the supporting classes
> > Property*. Reading can be as  easy as:
> > ...
> > PropertyResourceBundle p = new PropertyResourceBundle( new
> > FileInputStream("ApplicationResources.properties") );
> > ...
> > String propertyValue = p.getString("myKeyName");
> > ...
> >
> > Hope this helps.
> > Mark
> > - Original Message -
> > From: "Michael Mehrle" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Sunday, January 27, 2002 12:01 AM
> > Subject: Can I directly access properties in my ApplicationResources file?
> >
> >
> > > Okay, I'm in my Action class and would like to access some application
> > > specific configuration settings stored in my ApplicationResources.config
> > > file . What method do I call from my Action subclass in order to get to
> > > those? I have been looking all over the place and can't make sense out of
> > > this...
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > 
> > > For additional commands, e-mail:
> > 
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:   
> > For additional commands, e-mail: 
> >
> 
> __
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: Can I directly access properties in my ApplicationResources file?

2002-01-27 Thread Mike Olivieri

When you call request.getAttribute("application.attribute1"), you're using the
HttpServletRequest object. The attribute you are accessing is tied to the
request itself, not to the app or even the user's session. The request only has
a lifetime starting when the request for a page comes into the servlet engine
and is done when the servlet is done executing its doGet, doPost, or service
method. In the case of struts, it's actually when your ActionForm has completed
its process() method.

I don't know of too many uses for request attributes except for setting
request-scoped beans which are used by the JSP to build the display.

--- Michael Mehrle <[EMAIL PROTECTED]> wrote:
> Thanks for the quick update - I of course realize that this is a scope
> issue, but with the plethora of attributes and properties one can get
> confused with all that... I will try this as suggested.
> 
> One more question: Am I correct to assume that I could retrieve values from
> my ApplicationResources file also from within my form subclass by calling:
> 
> String myAttribute = request.getAttribute("application.attribute1"));
> 
> Cheers,
> 
> Michael
> 
> - Original Message -
> From: "Mark Rines" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Sunday, January 27, 2002 8:49 AM
> Subject: Re: Can I directly access properties in my ApplicationResources
> file?
> 
> 
> > Scope, scope, scope. Once you're in your Action class, you are in the
> > business logic scope of your application. Your business logic should have
> > nothing to do with Struts, or any other non business related architectural
> > implementation ( such as Swing, JAAS, etc...), architecturally speaking.
> So,
> > use the classes and methods used for manipulating any other properties
> file,
> > which is just what the ApplicationResources.properties file is, no more,
> no
> > less. For more info see the Properties class , and the supporting classes
> > Property*. Reading can be as  easy as:
> > ...
> > PropertyResourceBundle p = new PropertyResourceBundle( new
> > FileInputStream("ApplicationResources.properties") );
> > ...
> > String propertyValue = p.getString("myKeyName");
> > ...
> >
> > Hope this helps.
> > Mark
> > - Original Message -
> > From: "Michael Mehrle" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Sunday, January 27, 2002 12:01 AM
> > Subject: Can I directly access properties in my ApplicationResources file?
> >
> >
> > > Okay, I'm in my Action class and would like to access some application
> > > specific configuration settings stored in my ApplicationResources.config
> > > file . What method do I call from my Action subclass in order to get to
> > > those? I have been looking all over the place and can't make sense out
> of
> > > this...
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
> >
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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




Re: Can I directly access properties in my ApplicationResources file?

2002-01-27 Thread Michael Mehrle

Excellent - this sounds like a great approach and will tie the request to
the classpath rather than the filesystem (always a good thing :-)
Actually, just to clarify - I am using Tiles and I am trying to validate the
template name, which I think should be done either by my form or the Action
class. My ApplicationResources.properties file contains the following
entries:

template=basic
template=article

These are the mapping names of the templates that I have available (and
there will be more) - I am attempting to check whether or not the proper
template key was passed into the request...

Any suggestions would be welcome...

Cheers,

Michael


- Original Message -
From: "Mike Olivieri" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Sunday, January 27, 2002 9:46 AM
Subject: Re: Can I directly access properties in my ApplicationResources
file?


> A similar approach is using the getResourceAsStream() method from any
class.
>
> InputStream propFileStream =
> getClass().getResourceAsStream("/com/companyname/appname/app.properties");
> Properties props = new Properties();
> props.load(propFileStream);
>
> This works well for any kind of application, and will search the classpath
> rather than the filesystem for the properties file.
>
> Sometimes, there can be an extreme proliferation of properties files. In a
> large app, you'll have potentially hundreds of properties. Make sure that
your
> properties keys are descriptive enough that you could potentially combine
them
> into one properties file. You wouldn't want to just use:
> driver=oracle.jdbc.drivers.OracleDriver
> Instead, use
> appname.subsystem.jdbc.driver=oracle.jdbc.drivers.OracleDriver
>
> And finally, Mark is absolutely right about not mixing logic in your
tiers.
> Make sure that any business logic you have is encapsulated in classes that
are
> used by the Action class - don't put the business logic directly in the
Action
> class. It's not really much more typing, and will actually be easier to
debug
> and support... and reuse!
>



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




Re: Can I directly access properties in my ApplicationResources file?

2002-01-27 Thread Michael Mehrle

Thanks for the quick update - I of course realize that this is a scope
issue, but with the plethora of attributes and properties one can get
confused with all that... I will try this as suggested.

One more question: Am I correct to assume that I could retrieve values from
my ApplicationResources file also from within my form subclass by calling:

String myAttribute = request.getAttribute("application.attribute1"));

Cheers,

Michael

- Original Message -
From: "Mark Rines" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Sunday, January 27, 2002 8:49 AM
Subject: Re: Can I directly access properties in my ApplicationResources
file?


> Scope, scope, scope. Once you're in your Action class, you are in the
> business logic scope of your application. Your business logic should have
> nothing to do with Struts, or any other non business related architectural
> implementation ( such as Swing, JAAS, etc...), architecturally speaking.
So,
> use the classes and methods used for manipulating any other properties
file,
> which is just what the ApplicationResources.properties file is, no more,
no
> less. For more info see the Properties class , and the supporting classes
> Property*. Reading can be as  easy as:
> ...
> PropertyResourceBundle p = new PropertyResourceBundle( new
> FileInputStream("ApplicationResources.properties") );
> ...
> String propertyValue = p.getString("myKeyName");
> ...
>
> Hope this helps.
> Mark
> - Original Message -
> From: "Michael Mehrle" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Sunday, January 27, 2002 12:01 AM
> Subject: Can I directly access properties in my ApplicationResources file?
>
>
> > Okay, I'm in my Action class and would like to access some application
> > specific configuration settings stored in my ApplicationResources.config
> > file . What method do I call from my Action subclass in order to get to
> > those? I have been looking all over the place and can't make sense out
of
> > this...
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>



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




Re: Can I directly access properties in my ApplicationResources file?

2002-01-27 Thread Mike Olivieri

A similar approach is using the getResourceAsStream() method from any class.

InputStream propFileStream =
getClass().getResourceAsStream("/com/companyname/appname/app.properties");
Properties props = new Properties();
props.load(propFileStream);

This works well for any kind of application, and will search the classpath
rather than the filesystem for the properties file.

Sometimes, there can be an extreme proliferation of properties files. In a
large app, you'll have potentially hundreds of properties. Make sure that your
properties keys are descriptive enough that you could potentially combine them
into one properties file. You wouldn't want to just use:
driver=oracle.jdbc.drivers.OracleDriver
Instead, use
appname.subsystem.jdbc.driver=oracle.jdbc.drivers.OracleDriver

And finally, Mark is absolutely right about not mixing logic in your tiers.
Make sure that any business logic you have is encapsulated in classes that are
used by the Action class - don't put the business logic directly in the Action
class. It's not really much more typing, and will actually be easier to debug
and support... and reuse!

--- Mark Rines <[EMAIL PROTECTED]> wrote:
> Scope, scope, scope. Once you're in your Action class, you are in the
> business logic scope of your application. Your business logic should have
> nothing to do with Struts, or any other non business related architectural
> implementation ( such as Swing, JAAS, etc...), architecturally speaking. So,
> use the classes and methods used for manipulating any other properties file,
> which is just what the ApplicationResources.properties file is, no more, no
> less. For more info see the Properties class , and the supporting classes
> Property*. Reading can be as  easy as:
> ...
> PropertyResourceBundle p = new PropertyResourceBundle( new
> FileInputStream("ApplicationResources.properties") );
> ...
> String propertyValue = p.getString("myKeyName");
> ...
> 
> Hope this helps.
> Mark
> - Original Message -
> From: "Michael Mehrle" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Sunday, January 27, 2002 12:01 AM
> Subject: Can I directly access properties in my ApplicationResources file?
> 
> 
> > Okay, I'm in my Action class and would like to access some application
> > specific configuration settings stored in my ApplicationResources.config
> > file . What method do I call from my Action subclass in order to get to
> > those? I have been looking all over the place and can't make sense out of
> > this...
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> 
> > For additional commands, e-mail:
> 
> >
> 
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 


__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: Can I directly access properties in my ApplicationResources file?

2002-01-27 Thread Mark Rines

Scope, scope, scope. Once you're in your Action class, you are in the
business logic scope of your application. Your business logic should have
nothing to do with Struts, or any other non business related architectural
implementation ( such as Swing, JAAS, etc...), architecturally speaking. So,
use the classes and methods used for manipulating any other properties file,
which is just what the ApplicationResources.properties file is, no more, no
less. For more info see the Properties class , and the supporting classes
Property*. Reading can be as  easy as:
...
PropertyResourceBundle p = new PropertyResourceBundle( new
FileInputStream("ApplicationResources.properties") );
...
String propertyValue = p.getString("myKeyName");
...

Hope this helps.
Mark
- Original Message -
From: "Michael Mehrle" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Sunday, January 27, 2002 12:01 AM
Subject: Can I directly access properties in my ApplicationResources file?


> Okay, I'm in my Action class and would like to access some application
> specific configuration settings stored in my ApplicationResources.config
> file . What method do I call from my Action subclass in order to get to
> those? I have been looking all over the place and can't make sense out of
> this...
>
>
>
> --
> To unsubscribe, e-mail:

> For additional commands, e-mail:

>


--
To unsubscribe, e-mail:   
For additional commands, e-mail: