RE: How to initialize business service objects?

2008-03-19 Thread Frank Fischer
Hi Dave
Hi all

Finally i got it working the spring-way, meaning, when also delegating the
instantiation of action classes to spring. The default way, meaning
letting struts2 creating the action instances still doesn't work and i
really don't understand why.

Thanks to everyone that help me getting it working!

For anybody having similar problems and reading this post some day in the
future in the archive:

- include spring.jar. Struts2-core.jar, struts2-spring-plugin.jar,
xwork.jar, ognl.jar, freemarker.jar and commons-logging.jar to your
/WEB-INF/lib dir.

- put web.xml under /WEB-INF.

- put applicationContex.xml somewehere to your classpath. Same for
struts.xml and if you need struts.properties (which is not needed as long as
you set the required params in the struts.xml. This mainly refers to the
setting of the object factory).

- You can use the default.properties from struts2-core.jar as template for
your own struts.properties (can by found unter org/apache/struts2/). Set
struts.objectFactory = spring and struts.objectFactory.spring.autoWire =
name.

- Your basic web.xml would look like:

-?xml version=1.0 encoding=UTF-8?
web-app version=2.5 xmlns=http://java.sun.com/xml/ns/javaee;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd;  
filter  
filter-namestruts2/filter-name  
 
filter-classorg.apache.struts2.dispatcher.FilterDispatcher/filter-class

/filter  
filter-mapping  
filter-namestruts2/filter-name  
url-pattern/*/url-pattern  
/filter-mapping  
listener
 
listener-classorg.springframework.web.context.ContextLoaderListener/liste
ner-class
/listener

welcome-file-list
welcome-fileindex.jsp/welcome-file
/welcome-file-list

context-param
param-namecontextConfigLocation/param-name

param-valueclasspath*:applicationContext*.xml/param-value
/context-param


/web-app

-

- Your applicationContext.xml could look like this. Note that you first have
to define the business logic beans you later on need upon definition of the
action class beans. Also make sure you understand, that in struts.xml you
will have to define the action classes using their spring bean id and not
there class names! In this case the injection works by defining a
constructor argument. This could also be done using a setter method (than
you would pass a property argument).

-
?xml version=1.0 encoding=UTF-8?
beans xmlns=http://www.springframework.org/schema/beans;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xmlns:aop=http://www.springframework.org/schema/aop;
xmlns:tx=http://www.springframework.org/schema/tx;
xsi:schemaLocation=
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd;

bean id=businessService
class=com.example.businesslogic.BusinessService /

bean id=someAction scope=prototype class=com.example.SomeAction
constructor-arg ref=businessService /
/bean

/beans

-

- Your struts.properties would look like:

-
?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts
Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;

struts

constant name=struts.objectFactory value=spring /
constant name=struts.devMode value=true /

package name=somePackageName extends=struts-default

action name=login method=login class=someAction
result name=input/login.jsp/result
result name=success/mainapplication.jsp/result
/action

action name=logout method=logout class=someAction
result name=success/login.jsp/result
/action

/package

/struts

-

I hope there's nothing wrong i wrote. Ohterwise plz feel free to
correct/comment. 

Frank






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



Re: How to initialize business service objects?

2008-03-17 Thread GF
I suggest you to read this simple but useful tutorial to have an idea about
how much is simple to use Struts2+Spring+Hibernate together.

http://struts.apache.org/2.x/docs/struts-2-spring-2-jpa-ajax.html

On Thu, Mar 13, 2008 at 10:32 PM, Frank Fischer 
[EMAIL PROTECTED] wrote:


 Now i don't understand (1) where to create/initialize these business logic
 classes and (2) how to get access to them from the action classes.



RE: How to initialize business service objects?

2008-03-17 Thread Frank Fischer

Hi all 

first i'd like to thank all of you that have given me valuable feedback to
my question. 

Following the answers from Dave and Jeromy i decided to go the hard way
with Spring and DI. After reading some manuals (thanks to GF, good reading)
i managed to load the Spring ContextLoaderListener and even define an POJO
bean that serves as my BusinessLogicService. From the Tomcat logs i can see
that an instance of that Service is created. 

As far as i read/unterstood, i now would only have to create a setter method
on my Action class and Spring then would automatically inject the related
dependcy to my Action class. So far, this doesn't seem to work, so i guess,
i must be missing something.

My applicationContext.xml looks quite simple (and seems to work, since the
DispatcherService is created on startup):

---
?xml version=1.0 encoding=UTF-8?
!DOCTYPE beans PUBLIC -//SPRING//DTD BEAN//EN
http://www.springframework.org/dtd/spring-beans.dtd;
beans default-autowire=autodetect
bean id=DispatcherService
class=com.demo.businesslogic.DispatcherService/
/beans
---

The Struts config looks like:

---
?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts
Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;

struts

package name=customerAgent extends=struts-default

action name=login method=login class=com.demo.CustomerAction
result name=input/CustomerLogin.jsp/result
result name=success/CustomerChat.jsp/result
/action

action name=logout method=logout
class=com.demo.CustomerAction
result name=success/CustomerLogin.jsp/result
result name=input/CustomerLogin.jsp/result
/action

action name=chat method=chat class=com.demo.CustomerAction
result name=success/CustomerChat.jsp/result
/action


/package

/struts
---

So i guess, i must be missing something. Is there a way i would have to tell
Spring which Action classes to inject?

Thanks a lot for your help
Frank





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



Re: How to initialize business service objects?

2008-03-17 Thread Piero Sartini
Am Donnerstag, 13. März 2008 22:32:34 schrieb Frank Fischer:
 Now i don't understand (1) where to create/initialize these business logic
 classes and (2) how to get access to them from the action classes.

Just build your business logic without thinking about s2 too much. From your 
action classes you can access your business logic like everything else. Its 
really more of a java problem how to do this =)

If you have to run initialization code at startup, maybe a normal Listener is 
what you are looking for...

Piero



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



RE: How to initialize business service objects?

2008-03-17 Thread Griffith, Michael *
Frank, 

Check two things:

1) You have included the struts2-spring-pliugin.jar in your classpath
2) Your applicationContext.xml file is getting loaded on startup.  If
you haven't already done so, check your web.xml for a context parameter
like this:
context-param
param-namecontextConfigLocation/param-name

param-valueclasspath*:applicationContext*.xml/param-value
/context-param

HTH, 
MG
-Original Message-
From: Frank Fischer [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 17, 2008 11:09 AM
To: 'Struts Users Mailing List'
Subject: RE: How to initialize business service objects?


Hi all 

first i'd like to thank all of you that have given me valuable feedback
to
my question. 

Following the answers from Dave and Jeromy i decided to go the hard
way
with Spring and DI. After reading some manuals (thanks to GF, good
reading)
i managed to load the Spring ContextLoaderListener and even define an
POJO
bean that serves as my BusinessLogicService. From the Tomcat logs i can
see
that an instance of that Service is created. 

As far as i read/unterstood, i now would only have to create a setter
method
on my Action class and Spring then would automatically inject the
related
dependcy to my Action class. So far, this doesn't seem to work, so i
guess,
i must be missing something.

My applicationContext.xml looks quite simple (and seems to work, since
the
DispatcherService is created on startup):

---
?xml version=1.0 encoding=UTF-8?
!DOCTYPE beans PUBLIC -//SPRING//DTD BEAN//EN
http://www.springframework.org/dtd/spring-beans.dtd;
beans default-autowire=autodetect
bean id=DispatcherService
class=com.demo.businesslogic.DispatcherService/
/beans
---

The Struts config looks like:

---
?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts
Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;

struts

package name=customerAgent extends=struts-default

action name=login method=login
class=com.demo.CustomerAction
result name=input/CustomerLogin.jsp/result
result name=success/CustomerChat.jsp/result
/action

action name=logout method=logout
class=com.demo.CustomerAction
result name=success/CustomerLogin.jsp/result
result name=input/CustomerLogin.jsp/result
/action

action name=chat method=chat
class=com.demo.CustomerAction
result name=success/CustomerChat.jsp/result
/action


/package

/struts
---

So i guess, i must be missing something. Is there a way i would have to
tell
Spring which Action classes to inject?

Thanks a lot for your help
Frank





-
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: How to initialize business service objects?

2008-03-17 Thread Randy Burgess
You also need to setup your action in the application context so that Spring
knows where to inject the business object. Your class name in the Struts
action also needs to be the *bean id of the action* so that the
Struts/Spring plugin can do it's work. So assuming you have a setter for
DispatcherService in CustomerAction your struts.xml would look like this.

 struts
 
 package name=customerAgent extends=struts-default
 
 action name=login method=login class=customerAction
 result name=input/CustomerLogin.jsp/result
 result name=success/CustomerChat.jsp/result
 /action
...

Application context:
...
bean id=customerAction class=com.demo.CustomerAction
property name=DispatcherService ref=DispatcherService/
/bean

I recommend making your bean id's lower case and lower case properties in
the Action.

Private DispatcherService dispatcherService;

Then the property would be
property name=dispatcherService ref=dispatcherService/

Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications



 From: Frank Fischer [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List user@struts.apache.org
 Date: Mon, 17 Mar 2008 17:08:30 +0100
 To: 'Struts Users Mailing List' user@struts.apache.org
 Subject: RE: How to initialize business service objects?
 
 
 Hi all 
 
 first i'd like to thank all of you that have given me valuable feedback to
 my question. 
 
 Following the answers from Dave and Jeromy i decided to go the hard way
 with Spring and DI. After reading some manuals (thanks to GF, good reading)
 i managed to load the Spring ContextLoaderListener and even define an POJO
 bean that serves as my BusinessLogicService. From the Tomcat logs i can see
 that an instance of that Service is created.
 
 As far as i read/unterstood, i now would only have to create a setter method
 on my Action class and Spring then would automatically inject the related
 dependcy to my Action class. So far, this doesn't seem to work, so i guess,
 i must be missing something.
 
 My applicationContext.xml looks quite simple (and seems to work, since the
 DispatcherService is created on startup):
 
 ---
 ?xml version=1.0 encoding=UTF-8?
 !DOCTYPE beans PUBLIC -//SPRING//DTD BEAN//EN
 http://www.springframework.org/dtd/spring-beans.dtd;
 beans default-autowire=autodetect
 bean id=DispatcherService
 class=com.demo.businesslogic.DispatcherService/
 /beans
 ---
 
 The Struts config looks like:
 
 ---
 ?xml version=1.0 encoding=UTF-8 ?
 !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts
 Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;
 
 struts
 
 package name=customerAgent extends=struts-default
 
 action name=login method=login class=com.demo.CustomerAction
 result name=input/CustomerLogin.jsp/result
 result name=success/CustomerChat.jsp/result
 /action
 
 action name=logout method=logout
 class=com.demo.CustomerAction
 result name=success/CustomerLogin.jsp/result
 result name=input/CustomerLogin.jsp/result
 /action
 
 action name=chat method=chat class=com.demo.CustomerAction
 result name=success/CustomerChat.jsp/result
 /action
 
 
 /package
 
 /struts
 ---
 
 So i guess, i must be missing something. Is there a way i would have to tell
 Spring which Action classes to inject?
 
 Thanks a lot for your help
 Frank
 
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 



This email and any attachments (Message) may contain legally privileged 
and/or confidential information.  If you are not the addressee, or if this 
Message has been addressed to you in error, you are not authorized to read, 
copy, or distribute it, and we ask that you please delete it (including all 
copies) and notify the sender by return email.  Delivery of this Message to any 
person other than the intended recipient(s) shall not be deemed a waiver of 
confidentiality and/or a privilege.

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



Re: How to initialize business service objects?

2008-03-17 Thread Rushikesh Thakkar
Frank,

AFAIU, you want your Business Service Object to be injected in your Struts2
actions. To achieve that, I have done this:

- Using Spring ObjectFactory.
- Declare Business Service Object (BSO) in Spring's
applicationContext.xml(you've already done that)
- Define action that has setter method for your BSO.
- Declare this action as a bean in applicationContext.xml, with BSO
injected as dependency.

Sample Code:

Action:

public class SetEndPoint extends ActionSupport {
private DispatcherService dispatcherService;
public String execute () throws Exception {
//-your business logic-
return SUCCESS;
}

// DispatcherService object will be set (i.e. injected) by Spring (see
applicationContext.xml)
*public void setDispatcherService(DispatcherService dispatcherService)*{
this.dispatcherService = dispatcherService;
}
}

applicationContext.xml

 !-- . your existing bean declaration for DispatcherService
remains  -

!-- . Declare action here, injecting DispatcherService  -
bean id=setEndPoint class=example.client.web.action.SetEndPoint
*property name=dispatcherService*
ref bean=DispatcherService/
/property
/bean

struts.xml

struts
*constant name=struts.objectFactory value=spring /*
package name=no.bbs extends=struts-default
action name=setEndPoint method=execute *class=setEndPoint* 
result name=consumeA/view/consumeAcos.jsp/result
result name=consumeB/view/consumeMapp.jsp/result
result name=error/view/error.jsp/result
/action
/package
/struts

I have underlined important parts of each artifact..
I hope this helps..

-Rushikesh

On Mon, Mar 17, 2008 at 5:28 PM, Piero Sartini [EMAIL PROTECTED]
wrote:

 Am Donnerstag, 13. März 2008 22:32:34 schrieb Frank Fischer:
  Now i don't understand (1) where to create/initialize these business
 logic
  classes and (2) how to get access to them from the action classes.

 Just build your business logic without thinking about s2 too much. From
 your
 action classes you can access your business logic like everything else.
 Its
 really more of a java problem how to do this =)

 If you have to run initialization code at startup, maybe a normal Listener
 is
 what you are looking for...

Piero



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




Re: How to initialize business service objects?

2008-03-17 Thread Dave Newton
--- Randy Burgess [EMAIL PROTECTED] wrote:
 You also need to setup your action in the application context so that
 Spring knows where to inject the business object. 

You *can* do it that way, but the default setup doesn't require it. It
depends on how you're wiring, whether or not your philosophically opposed to
magic, and so on.

Dave



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



RE: How to initialize business service objects?

2008-03-17 Thread Frank Fischer
Hi Michael

Thanks for your answer.

 1) You have included the struts2-spring-pliugin.jar in your classpath

Yes, it put it under WEB-INF/lib/ so it's packaged to the war file and
should be available to tomcat it think. I also can't see any error or
warning messages while deploying the application, so i guess the package can
be resolved. 

 2) Your applicationContext.xml file is getting loaded on startup.  If
 you haven't already done so, check your web.xml for a context 
 parameter
 like this:
   context-param
   param-namecontextConfigLocation/param-name
   
 param-valueclasspath*:applicationContext*.xml/param-value
   /context-param

I did not include that line because i read, that this is the default setting
Spring uses when no contextConfigLocation parameter is defined. I just added
it but it didn't change anything as far as i see.

Thanks again for your help.
Frank


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



RE: How to initialize business service objects?

2008-03-17 Thread Dave Newton
--- Frank Fischer [EMAIL PROTECTED] wrote:
 beans default-autowire=autodetect

Off the top of my head I don't recall what autodetect means.

Did you try leaving out the default-autowire attribute or switching it to
the default (name or something like that; I don't recall) and seeing if
that works?

That would at least help determine if everything is getting
deployed/initialized correctly.

Dave



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



RE: How to initialize business service objects?

2008-03-17 Thread Griffith, Michael *
Frank, 

I would check your struts.properties file:

Make sure it has these entries and that it is on your classpath (i.e. in
WEB-INF/classes)

struts.objectFactory = spring
struts.objectFactory.spring.autoWire = name

MG

-Original Message-
From: Frank Fischer [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 17, 2008 1:35 PM
To: 'Struts Users Mailing List'
Subject: RE: How to initialize business service objects?

Hi Michael

Thanks for your answer.

 1) You have included the struts2-spring-pliugin.jar in your classpath

Yes, it put it under WEB-INF/lib/ so it's packaged to the war file and
should be available to tomcat it think. I also can't see any error or
warning messages while deploying the application, so i guess the package
can
be resolved. 

 2) Your applicationContext.xml file is getting loaded on startup.  If
 you haven't already done so, check your web.xml for a context 
 parameter
 like this:
   context-param
   param-namecontextConfigLocation/param-name
   
 param-valueclasspath*:applicationContext*.xml/param-value
   /context-param

I did not include that line because i read, that this is the default
setting
Spring uses when no contextConfigLocation parameter is defined. I just
added
it but it didn't change anything as far as i see.

Thanks again for your help.
Frank


-
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]



How to initialize business service objects?

2008-03-13 Thread Frank Fischer
Hi all
 
i'm just starting with struts2 (even with struts at all). Of course i first
read some how-to-starts. But there is one thing i don't understand.
 
I'm trying to create a simple little chat app. I have two action classes,
one for the normal chat user, one for the moderators. Both classes need
access to the same instances of business service classes which mainly hold
runtime data such as a list of users currently logged in, list of chat rooms
and so on.
 
Now i don't understand (1) where to create/initialize these business logic
classes and (2) how to get access to them from the action classes. 
 
I'm very thankful for any hint.
 
Thanks a lot
Frank


Re: How to initialize business service objects?

2008-03-13 Thread Randy Burgess
For a POJO you can use dependency injection such as Spring or Guice or you
can instantiate the object the normal way

BusinessServiceObject bso = new BusinessServiceObject();

in your action class. There is nothing special about accessing your BSO's in
Struts.

Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications



 From: Frank Fischer [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List user@struts.apache.org
 Date: Thu, 13 Mar 2008 22:32:34 +0100
 To: user@struts.apache.org
 Subject: How to initialize business service objects?
 
 Hi all
  
 i'm just starting with struts2 (even with struts at all). Of course i first
 read some how-to-starts. But there is one thing i don't understand.
  
 I'm trying to create a simple little chat app. I have two action classes,
 one for the normal chat user, one for the moderators. Both classes need
 access to the same instances of business service classes which mainly hold
 runtime data such as a list of users currently logged in, list of chat rooms
 and so on.
  
 Now i don't understand (1) where to create/initialize these business logic
 classes and (2) how to get access to them from the action classes.
  
 I'm very thankful for any hint.
  
 Thanks a lot
 Frank



This email and any attachments (Message) may contain legally privileged 
and/or confidential information.  If you are not the addressee, or if this 
Message has been addressed to you in error, you are not authorized to read, 
copy, or distribute it, and we ask that you please delete it (including all 
copies) and notify the sender by return email.  Delivery of this Message to any 
person other than the intended recipient(s) shall not be deemed a waiver of 
confidentiality and/or a privilege.

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



RE: How to initialize business service objects?

2008-03-13 Thread Frank Fischer

Hi Randy
Hi all

I just read a bit regarding Spring. As far as i understand its focus is on
J2EE appllications. I guess for what i want to do in a first step (my simple
chat app) it would be overkill to use Spring. Do i get that right?

I would prefere to go the most simple way if possible. So, just
instantiating my BusinessServiceObject the common way would be fine for me.
I just don't understand how can i get access to a BusinessServiceObject
created in one of my Action classes from another Action class. Just by
declaring it as static?

Second thing i don't understand is, when will action objects be intatiated
in the application server? As far as i remember from the early days of
servlet programming (when i had to do with this technology the last time)
the servlets are intantiated upon the first request. In a normal Servlet
based Web app i would have intiantiated BusinessServiceObjects in a filter
and placed them to the ServletContext. So i could be sure it's instantiated
before the first request arrives and i can get a reference to it from
anywhere in my web app.  But with Struts i don't see how i could do so.

I know this might sound a little bit confused. Can you help me to get on
track again?

Thanks for your help
Frank
 

 -Original Message-
 From: Randy Burgess [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, March 13, 2008 11:02 PM
 To: Struts Users Mailing List
 Subject: Re: How to initialize business service objects?
 
 For a POJO you can use dependency injection such as Spring or 
 Guice or you
 can instantiate the object the normal way
 
 BusinessServiceObject bso = new BusinessServiceObject();
 
 in your action class. There is nothing special about 
 accessing your BSO's in
 Struts.
 
 Regards,
 Randy Burgess
 Sr. Web Applications Developer
 Nuvox Communications
 
 
 
  From: Frank Fischer [EMAIL PROTECTED]
  Reply-To: Struts Users Mailing List user@struts.apache.org
  Date: Thu, 13 Mar 2008 22:32:34 +0100
  To: user@struts.apache.org
  Subject: How to initialize business service objects?
  
  Hi all
   
  i'm just starting with struts2 (even with struts at all). 
 Of course i first
  read some how-to-starts. But there is one thing i don't understand.
   
  I'm trying to create a simple little chat app. I have two 
 action classes,
  one for the normal chat user, one for the moderators. Both 
 classes need
  access to the same instances of business service classes 
 which mainly hold
  runtime data such as a list of users currently logged in, 
 list of chat rooms
  and so on.
   
  Now i don't understand (1) where to create/initialize these 
 business logic
  classes and (2) how to get access to them from the action classes.
   
  I'm very thankful for any hint.
   
  Thanks a lot
  Frank
 
 
 
 This email and any attachments (Message) may contain 
 legally privileged and/or confidential information.  If you 
 are not the addressee, or if this Message has been addressed 
 to you in error, you are not authorized to read, copy, or 
 distribute it, and we ask that you please delete it 
 (including all copies) and notify the sender by return email. 
  Delivery of this Message to any person other than the 
 intended recipient(s) shall not be deemed a waiver of 
 confidentiality and/or a privilege.
 
 -
 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]



[OT] RE: How to initialize business service objects?

2008-03-13 Thread Dave Newton
--- Frank Fischer [EMAIL PROTECTED] wrote:
 I just read a bit regarding Spring. As far as i understand its focus is on
 J2EE appllications. I guess for what i want to do in a first step (my
 simple chat app) it would be overkill to use Spring. Do i get that right?

Not really.

IMO Spring is a light-weight(-ish) alternative to true JEE apps (note that
it's JEE now, not J2EE :)

S2's Spring integration is lightweight to the point of near-invisibility,
particularly for simple setups. It's as easy as defining a bean in a Spring
configuration file and providing a setter in your S2 action. There are
several benefits to doing so, but that's something you can discover on your
own if you decide to explore Spring. This particular usage is called
Inversion of Control (IoC) or (my preference) Dependency Injection (DI).

 I just don't understand how can i get access to a BusinessServiceObject
 created in one of my Action classes from another Action class. Just by
 declaring it as static?

No, by keeping it in session or application scope.

I'd recommend getting at least a minimal handle on some basic web application
technology and terminology before jumping in *too* deep: S2, like many
frameworks, pretty much requires a basic understanding of the fundamentals.
Without it it's hard to even know what questions to ask sometimes, and will
make the whole process much easier.

 Second thing i don't understand is, when will action objects be intatiated
 in the application server? 

Actions are instantiated per-request.

 As far as i remember from the early days of
 servlet programming (when i had to do with this technology the last time)
 the servlets are intantiated upon the first request. In a normal Servlet
 based Web app i would have intiantiated BusinessServiceObjects in a filter
 and placed them to the ServletContext. So i could be sure it's instantiated
 before the first request arrives and i can get a reference to it from
 anywhere in my web app.  But with Struts i don't see how i could do so.

You *could* do it the exact same way: S2 doesn't replace what you know about
web applications, it supplements it.

That said, it's probably better to perform tasks like that in
ServletContextListener (don't quote me on that; I have a notoriously bad
memory for anything camelCased) or whatever it's called.

Dave


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



Re: How to initialize business service objects?

2008-03-13 Thread Jeromy Evans

Hi Frank,

Have a read of Martin Fowler's article on deciding which option best 
suits you:

http://martinfowler.com/articles/injection.html

As Dave described you have many possibilities, but the common techniques 
are (not in order of preference):
 a. Use a ServletContextListener to to setup your services and place 
them in Application Scope.  Look them up from your action
 b. as per b, but include an interceptor to inject them into your 
actions based on interfaces (eg.MyServiceAware)
 c. Setup your business services as Singletons or accessed through a 
Registry (setup as per a)
 d. Use an IOC container.  Spring and Guice.  Guice is simple, elegant 
and does this single task extremely well; Spring knowledge is a 
must-have and reflects the community's consensus on best-practice in 
almost every imaginable aspect of a web application.


Hope that helps.
Jeromy Evans

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