RE: spring, struts2, convention plugin, how to wire an action class

2010-05-14 Thread Martin Gainty

BeanNameAware Interface to be implemented by beans that want to be aware of 
their
 bean name in a bean factory. Note that it is not usually recommended
 that an object depend on its bean name, as this represents a 
potentially
 brittle dependence on external configuration, as well as a possibly
 unnecessary dependence on a Spring API

//where does your Bean class MyService implement BeanNameAware?

public interface BeanFactory



The root interface for accessing a Spring bean container.
 This is the basic client view of a bean container;
 further interfaces such as ListableBeanFactory
 and
 ConfigurableBeanFactory
 are available for specific purposes.

 
This interface is implemented by objects that hold a number of 
bean definitions,
 each uniquely identified by a String name. Depending on the bean 
definition,
 the factory will return either an independent instance of a contained 
object
 (the Prototype design pattern), or a single shared instance (a superior
 alternative to the Singleton design pattern, in which the instance is a
 singleton in the scope of the factory). Which type of instance will be 
returned
 depends on the bean factory configuration: the API is the same. Since 
Spring
 2.0, further scopes are available depending on the concrete application
 context (e.g. request and session scopes in a web environment). 


//where does you Bean class implment BeanFactory?


//applicationContext.xml
bean id=myAction class=com.vang.jake.web.actions.MyAction 
scope=singleton
property name=verbose value=${verbose}/
   property name=message value=${message}/
   property name=myService ref=myService/
/bean

package com.vang.jake.services;

public class MyService {

private boolean verbose = false;
private String message = default;

public boolean isVerbose() {
return verbose;
}

public void setVerbose(boolean verbose) {
this.verbose = verbose;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}


}

?
Martin Gainty 
__ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.




 Date: Thu, 13 May 2010 20:18:34 -0400
 Subject: Re: spring, struts2, convention plugin, how to wire an action class
 From: vangj...@googlemail.com
 To: user@struts.apache.org
 
 roger,
 
 thanks for the steps. i went through each of those steps and made sure
 my settings/configurations complied. however, i still cannot
 initialize Action classes using Spring.
 
 as an illustration of the problem i am facing, i have created an
 example that you may download and verify for yourself that this does
 not work.
 
 http://www.box.net/shared/iycamr9uo6
 
 this will download a zip file with an Eclipse project; unzip it. if
 you have Ant, you simply type in ant war and the war file will be
 created. if you have Tomcat, then drop the war file into the webapps
 directory (assuming you have Tomcat 6.0).
 
 if you go to http://localhost:8080/myapp/, you will see four lines displayed.
 String from Action: default
 boolean from Action: false
 String from Service: overwritten
 boolean from Service: true
 
 The first and second lines confirm that the String and boolean values
 are not injected into the Action class. The third and fourth lines
 confirm that the String and boolean values are injected into the
 service class.
 
 thanks.
 
 On Thu, May 13, 2010 at 9:32 AM, RogerV roger.var...@googlemail.com wrote:
 
 
 
  Jake Vang wrote:
 
  If you want Spring to create your action class (as opposed to Struts
  creating them) then you need to define your action in the
  applicationContext.xml file.
 
  how do you do that? here's a couple of ways i have tried that do NOT work.
 
 
  1) Add constant name=struts.objectFactory
  value=org.apache.struts2.spring.StrutsSpringObjectFactory / to your
  struts.xml file.
 
  2) Add  listener
 
  listener

spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
i am using struts 2.1.8.1 and the convention plugin. i am also using
spring for dependency injections (DI). my question is if it is
possible to to use struts2 + convention plugin with spring for DI on
my Action classes? i have searched  the internet but only seen
examples using struts 1 + spring for DI on Action classes. the
convention plugin makes life simpler (no XML), but also, partially
because of little documentation, makes it uneasy to do certain things.
i wonder if this is part of the reason why DI on Action classes using
spring + struts is not obvious for me.

Here's a simple code. This is my action class.

public class SpringWiringAction extends ActionSupport {
 private String message = no dependency injection;

 @Action(value=/spring-wiring)
 public String springWiring() {
  return SUCCESS;
 }

 public String getMessage() { return message; }
 public void setMessage(String message) { this.message = message; }
}

My view or the JSP page corresponding to the Action is:
/webapp/WEB-INF/content/spring-wiring-success.jsp.

%@ page language=java contentType=text/html; charset=ISO-8859-1
pageEncoding=ISO-8859-1%
%...@taglib uri=/struts-tags prefix=s %
html
 headtitleTest Spring Wiring/title/head
 body
 s:property value=message/
 /body
/html

My web.xml is setup according to
http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
as following.

...
bean id=placeholderConfig
class=org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
 property name=location value=WEB-INF/applicationContext.properties/
/bean
...
bean name=/spring-wiring class=com.me.actions.SpringWiringAction
 property name=message value=${message}/
/bean

My /webapp/WEB-INF/applicationContext.properties file then has this content.

message=dependency inject success

when i start up tomcat 6, everything starts up correctly and there are
no complaints. however, when i go to
http://localhost/webapp/spring-wiring, the message that gets displayed
is no dependency injection.

is there something that i am missing using spring + struts2 (with the
convention plugin) to use DI on Actions?

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



RE: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread James Cook
Hmm. I use the same combo.

I found at some point I could jsut do

public class MyAction extends ActionSupport {

private MyInjectedService service 

etc etc

But I have started doing:

public class MyAction extends ActionSupport {

@Autowired
private MyInjectedService service

I am not sure if that alters the way Struts2/Spring does it. But it does
make it a bit clearer to read.

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com] 
Sent: 13 May 2010 10:23
To: user@struts.apache.org
Subject: spring, struts2, convention plugin, how to wire an action
class

i am using struts 2.1.8.1 and the convention plugin. i am also using
spring for dependency injections (DI). my question is if it is
possible to to use struts2 + convention plugin with spring for DI on
my Action classes? i have searched  the internet but only seen
examples using struts 1 + spring for DI on Action classes. the
convention plugin makes life simpler (no XML), but also, partially
because of little documentation, makes it uneasy to do certain things.
i wonder if this is part of the reason why DI on Action classes using
spring + struts is not obvious for me.

Here's a simple code. This is my action class.

public class SpringWiringAction extends ActionSupport {
 private String message = no dependency injection;

 @Action(value=/spring-wiring)
 public String springWiring() {
  return SUCCESS;
 }

 public String getMessage() { return message; }
 public void setMessage(String message) { this.message = message; }
}

My view or the JSP page corresponding to the Action is:
/webapp/WEB-INF/content/spring-wiring-success.jsp.

%@ page language=java contentType=text/html; charset=ISO-8859-1
pageEncoding=ISO-8859-1%
%...@taglib uri=/struts-tags prefix=s %
html
 headtitleTest Spring Wiring/title/head
 body
 s:property value=message/
 /body
/html

My web.xml is setup according to
http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
as following.

...
bean id=placeholderConfig
class=org.springframework.beans.factory.config.PropertyPlaceholderConfi
gurer
 property name=location
value=WEB-INF/applicationContext.properties/
/bean
...
bean name=/spring-wiring class=com.me.actions.SpringWiringAction
 property name=message value=${message}/
/bean

My /webapp/WEB-INF/applicationContext.properties file then has this
content.

message=dependency inject success

when i start up tomcat 6, everything starts up correctly and there are
no complaints. however, when i go to
http://localhost/webapp/spring-wiring, the message that gets displayed
is no dependency injection.

is there something that i am missing using spring + struts2 (with the
convention plugin) to use DI on Actions?

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


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



Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
well, there's something strange about struts2 (with convention plugin)
+ spring. if your action has a field representing a service,
MyInjectedService myInjectedService, you just have to define that in
the spring xml file. for example, your Action class looks like the
following.

public class MyAction extends ActionSupport {
 private Service service;

 @Action(value=/dummy)
 public String dummy() { return SUCCESS; }
 public Service getService() { return service; }
 public void setService(Service service) { this.service = service; }
}

in your spring xml file (i.e. applicationContext.xml), you simply
define a bean with the id=service. for example,

bean id=service class=my.class.Service/

that's it; you don't have to do anything else. you don't even have to
explicitly say (using XML) to inject this when you are creating an
instance of MyAction. now when a user accesses /dummy, MyAction will
be created and its service field will actually be injected with what
is specified in the spring xml file.

what irks me or  bothers me is that it is not obvious at the moment
how to simply inject strings or booleans into the Action class. it
should be just as simple.

upon analyzing what i am doing, and in light of what you said, perhaps
i am trying to push some logic into the Action class that shouldn't be
there. perhaps i should push the logic to a service class instead. in
this case, this problem goes away. BUT, the question remains, how can
i use DI with struts2 (convention plugin)  and spring on Action
classes? or can i not? if i can't, end of story. if i can, how?

On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage() { return message; }
  public void setMessage(String message) { this.message = message; }
 }

 My view or the JSP page corresponding to the Action is:
 /webapp/WEB-INF/content/spring-wiring-success.jsp.

 %@ page language=java contentType=text/html; charset=ISO-8859-1
 pageEncoding=ISO-8859-1%
 %...@taglib uri=/struts-tags prefix=s %
 html
  headtitleTest Spring Wiring/title/head
  body
  s:property value=message/
  /body
 /html

 My web.xml is setup according to
 http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

 My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
 as following.

 ...
 bean id=placeholderConfig
 class=org.springframework.beans.factory.config.PropertyPlaceholderConfi
 gurer
  property name=location
 value=WEB-INF/applicationContext.properties/
 /bean
 ...
 bean name=/spring-wiring class=com.me.actions.SpringWiringAction
  property name=message value=${message}/
 /bean

 My /webapp/WEB-INF/applicationContext.properties file then has this
 content.

 message=dependency inject success

 when i start up tomcat 6, everything starts up correctly and there are
 no complaints. however, when i go to
 http://localhost/webapp/spring-wiring, the message that gets displayed
 is no dependency injection.

 is there something that i am missing using spring + struts2 (with the
 convention plugin) to use DI on Actions?

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


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



-
To unsubscribe, e-mail: user-unsubscr

RE: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread James Cook
Nope, no they are not in the xml for me. I use the @Service/@Repository 
annotations on the class, coupled with the component scan in the Spring xml.

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com] 
Sent: 13 May 2010 11:09
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

well, there's something strange about struts2 (with convention plugin)
+ spring. if your action has a field representing a service,
MyInjectedService myInjectedService, you just have to define that in
the spring xml file. for example, your Action class looks like the
following.

public class MyAction extends ActionSupport {
 private Service service;

 @Action(value=/dummy)
 public String dummy() { return SUCCESS; }
 public Service getService() { return service; }
 public void setService(Service service) { this.service = service; }
}

in your spring xml file (i.e. applicationContext.xml), you simply
define a bean with the id=service. for example,

bean id=service class=my.class.Service/

that's it; you don't have to do anything else. you don't even have to
explicitly say (using XML) to inject this when you are creating an
instance of MyAction. now when a user accesses /dummy, MyAction will
be created and its service field will actually be injected with what
is specified in the spring xml file.

what irks me or  bothers me is that it is not obvious at the moment
how to simply inject strings or booleans into the Action class. it
should be just as simple.

upon analyzing what i am doing, and in light of what you said, perhaps
i am trying to push some logic into the Action class that shouldn't be
there. perhaps i should push the logic to a service class instead. in
this case, this problem goes away. BUT, the question remains, how can
i use DI with struts2 (convention plugin)  and spring on Action
classes? or can i not? if i can't, end of story. if i can, how?

On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage() { return message; }
  public void setMessage(String message) { this.message = message; }
 }

 My view or the JSP page corresponding to the Action is:
 /webapp/WEB-INF/content/spring-wiring-success.jsp.

 %@ page language=java contentType=text/html; charset=ISO-8859-1
 pageEncoding=ISO-8859-1%
 %...@taglib uri=/struts-tags prefix=s %
 html
  headtitleTest Spring Wiring/title/head
  body
  s:property value=message/
  /body
 /html

 My web.xml is setup according to
 http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

 My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
 as following.

 ...
 bean id=placeholderConfig
 class=org.springframework.beans.factory.config.PropertyPlaceholderConfi
 gurer
  property name=location
 value=WEB-INF/applicationContext.properties/
 /bean
 ...
 bean name=/spring-wiring class=com.me.actions.SpringWiringAction
  property name=message value=${message}/
 /bean

 My /webapp/WEB-INF/applicationContext.properties file then has this
 content.

 message=dependency inject success

 when i start up tomcat 6, everything starts up correctly and there are
 no complaints. however, when i go to
 http://localhost/webapp/spring-wiring, the message that gets displayed
 is no dependency injection.

 is there something that i am missing using spring + struts2 (with the
 convention plugin) to use DI on Actions?

 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org

Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
by the way, which package is the @Autowired annotation in? using
eclipse and code assist, i can't get it to show up. is it in some
other jar file (it's not in the spring-core-x.jar)?

On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage() { return message; }
  public void setMessage(String message) { this.message = message; }
 }

 My view or the JSP page corresponding to the Action is:
 /webapp/WEB-INF/content/spring-wiring-success.jsp.

 %@ page language=java contentType=text/html; charset=ISO-8859-1
 pageEncoding=ISO-8859-1%
 %...@taglib uri=/struts-tags prefix=s %
 html
  headtitleTest Spring Wiring/title/head
  body
  s:property value=message/
  /body
 /html

 My web.xml is setup according to
 http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

 My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
 as following.

 ...
 bean id=placeholderConfig
 class=org.springframework.beans.factory.config.PropertyPlaceholderConfi
 gurer
  property name=location
 value=WEB-INF/applicationContext.properties/
 /bean
 ...
 bean name=/spring-wiring class=com.me.actions.SpringWiringAction
  property name=message value=${message}/
 /bean

 My /webapp/WEB-INF/applicationContext.properties file then has this
 content.

 message=dependency inject success

 when i start up tomcat 6, everything starts up correctly and there are
 no complaints. however, when i go to
 http://localhost/webapp/spring-wiring, the message that gets displayed
 is no dependency injection.

 is there something that i am missing using spring + struts2 (with the
 convention plugin) to use DI on Actions?

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


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



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



Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
doesn't answer the question but thanks anyways.

On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage() { return message; }
  public void setMessage(String message) { this.message = message; }
 }

 My view or the JSP page corresponding to the Action is:
 /webapp/WEB-INF/content/spring-wiring-success.jsp.

 %@ page language=java contentType=text/html; charset=ISO-8859-1
 pageEncoding=ISO-8859-1%
 %...@taglib uri=/struts-tags prefix=s %
 html
  headtitleTest Spring Wiring/title/head
  body
  s:property value=message/
  /body
 /html

 My web.xml is setup according to
 http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

 My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
 as following.

 ...
 bean id=placeholderConfig
 class=org.springframework.beans.factory.config.PropertyPlaceholderConfi
 gurer
  property name=location
 value=WEB-INF/applicationContext.properties/
 /bean
 ...
 bean name=/spring-wiring class=com.me.actions.SpringWiringAction
  property name=message value=${message}/
 /bean

 My /webapp/WEB-INF/applicationContext.properties file then has this
 content.

 message=dependency inject success

 when i start up tomcat 6, everything starts up correctly and there are
 no complaints. however, when i go to
 http://localhost/webapp/spring-wiring, the message that gets displayed
 is no dependency injection.

 is there something that i am missing using spring + struts2 (with the
 convention plugin

RE: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread James Cook
Yeah sorry, short on time here, didn't see your question at the bottom. Add the 
spring jar from the spring project.

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com] 
Sent: 13 May 2010 11:16
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

doesn't answer the question but thanks anyways.

On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage() { return message; }
  public void setMessage(String message) { this.message = message; }
 }

 My view or the JSP page corresponding to the Action is:
 /webapp/WEB-INF/content/spring-wiring-success.jsp.

 %@ page language=java contentType=text/html; charset=ISO-8859-1
 pageEncoding=ISO-8859-1%
 %...@taglib uri=/struts-tags prefix=s %
 html
  headtitleTest Spring Wiring/title/head
  body
  s:property value=message/
  /body
 /html

 My web.xml is setup according to
 http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.

 My spring XML file (/webapp/WEB-INF/applicationContext.xml) is defined
 as following.

 ...
 bean id=placeholderConfig
 class=org.springframework.beans.factory.config.PropertyPlaceholderConfi
 gurer
  property name=location
 value=WEB-INF/applicationContext.properties/
 /bean
 ...
 bean name=/spring-wiring class=com.me.actions.SpringWiringAction
  property name=message value=${message}/
 /bean

 My /webapp/WEB-INF/applicationContext.properties file then has this
 content.

 message

Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
thanks. i won't go that route. i noticed your example (in the first
response) and i realized that i may trying to push some business logic
into the Action class. and, i don't think that's too good of a
practice. i simply revised my Service class to hold these values
(booleans, String, int, etc...) and now the problem goes away. it's a
workaround.

if anyone is reading this post and knows how to use struts2 (w/
convention plugin) + spring to construct Action classes, please let me
know. the examples i've seen are only with struts1 (and though not too
complicated, seem verbose with the xml).

On Thu, May 13, 2010 at 6:20 AM, James Cook james.c...@wecomm.com wrote:
 Yeah sorry, short on time here, didn't see your question at the bottom. Add 
 the spring jar from the spring project.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:16
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 doesn't answer the question but thanks anyways.

 On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage() { return message; }
  public void setMessage(String message) { this.message = message; }
 }

 My view or the JSP page corresponding to the Action is:
 /webapp/WEB-INF/content/spring-wiring-success.jsp.

 %@ page language=java contentType=text/html; charset=ISO-8859-1
 pageEncoding=ISO-8859-1%
 %...@taglib uri=/struts-tags prefix=s %
 html

RE: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread James Cook
Oh, did you want your action as a spring managed bean? Ah I think i massively 
miss read you. You want to inject predefined values etc?


-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com] 
Sent: 13 May 2010 11:38
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

thanks. i won't go that route. i noticed your example (in the first
response) and i realized that i may trying to push some business logic
into the Action class. and, i don't think that's too good of a
practice. i simply revised my Service class to hold these values
(booleans, String, int, etc...) and now the problem goes away. it's a
workaround.

if anyone is reading this post and knows how to use struts2 (w/
convention plugin) + spring to construct Action classes, please let me
know. the examples i've seen are only with struts1 (and though not too
complicated, seem verbose with the xml).

On Thu, May 13, 2010 at 6:20 AM, James Cook james.c...@wecomm.com wrote:
 Yeah sorry, short on time here, didn't see your question at the bottom. Add 
 the spring jar from the spring project.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:16
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 doesn't answer the question but thanks anyways.

 On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action(value=/spring-wiring)
  public String springWiring() {
  return SUCCESS;
  }

  public String getMessage

Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
yes. precisely.

On Thu, May 13, 2010 at 6:41 AM, James Cook james.c...@wecomm.com wrote:
 Oh, did you want your action as a spring managed bean? Ah I think i massively 
 miss read you. You want to inject predefined values etc?


 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:38
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 thanks. i won't go that route. i noticed your example (in the first
 response) and i realized that i may trying to push some business logic
 into the Action class. and, i don't think that's too good of a
 practice. i simply revised my Service class to hold these values
 (booleans, String, int, etc...) and now the problem goes away. it's a
 workaround.

 if anyone is reading this post and knows how to use struts2 (w/
 convention plugin) + spring to construct Action classes, please let me
 know. the examples i've seen are only with struts1 (and though not too
 complicated, seem verbose with the xml).

 On Thu, May 13, 2010 at 6:20 AM, James Cook james.c...@wecomm.com wrote:
 Yeah sorry, short on time here, didn't see your question at the bottom. Add 
 the spring jar from the spring project.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:16
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 doesn't answer the question but thanks anyways.

 On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI on Action classes. the
 convention plugin makes life simpler (no XML), but also, partially
 because of little documentation, makes it uneasy to do certain things.
 i wonder if this is part of the reason why DI on Action classes using
 spring + struts is not obvious for me.

 Here's a simple code. This is my action class.

 public class SpringWiringAction extends ActionSupport {
  private String message = no dependency injection;

 �...@action

RE: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread James Cook
Ahh hmm.

You can use the autowired, You just have to declare you stuff in the spring 
xml. E.g.

bean id=myJDBCString class=java.lang.String 

I think you can also use the @Resource anno as well. Can't think off the top of 
my head. 

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com] 
Sent: 13 May 2010 11:44
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

yes. precisely.

On Thu, May 13, 2010 at 6:41 AM, James Cook james.c...@wecomm.com wrote:
 Oh, did you want your action as a spring managed bean? Ah I think i massively 
 miss read you. You want to inject predefined values etc?


 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:38
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 thanks. i won't go that route. i noticed your example (in the first
 response) and i realized that i may trying to push some business logic
 into the Action class. and, i don't think that's too good of a
 practice. i simply revised my Service class to hold these values
 (booleans, String, int, etc...) and now the problem goes away. it's a
 workaround.

 if anyone is reading this post and knows how to use struts2 (w/
 convention plugin) + spring to construct Action classes, please let me
 know. the examples i've seen are only with struts1 (and though not too
 complicated, seem verbose with the xml).

 On Thu, May 13, 2010 at 6:20 AM, James Cook james.c...@wecomm.com wrote:
 Yeah sorry, short on time here, didn't see your question at the bottom. Add 
 the spring jar from the spring project.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:16
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 doesn't answer the question but thanks anyways.

 On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2 + convention plugin with spring for DI on
 my Action classes? i have searched  the internet but only seen
 examples using struts 1 + spring for DI

RE: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread RogerV



James Cook-13 wrote:
 
 Oh, did you want your action as a spring managed bean? Ah I think i
 massively miss read you. You want to inject predefined values etc?
 

If you want Spring to create your action class (as opposed to Struts
creating them) then you need to define your action in the
applicationContext.xml file.

Regards

-- 
View this message in context: 
http://old.nabble.com/spring%2C-struts2%2C-convention-plugin%2C-how-to-%22wire%22-an-action-class-tp28545412p28546598.html
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
 If you want Spring to create your action class (as opposed to Struts
 creating them) then you need to define your action in the
 applicationContext.xml file.

how do you do that? here's a couple of ways i have tried that do NOT work.

1. (normal, naive way that works for defining services)
bean id=action class=com.services.MyAction
 property name=propertyA value=${propertyA}/
/bean

2. (in this case, we do not use the id attribute, but the name attribute)
bean name=/action class=com.services.MyAction
 property name=propertyA value=${propertyA}/
/bean

i've also tried configuring struts.properties to have the
ObjectFactory use spring and this does not help.

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



Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
thanks. example please? (when you have time).

On Thu, May 13, 2010 at 6:52 AM, James Cook james.c...@wecomm.com wrote:
 Ahh hmm.

 You can use the autowired, You just have to declare you stuff in the spring 
 xml. E.g.

 bean id=myJDBCString class=java.lang.String 

 I think you can also use the @Resource anno as well. Can't think off the top 
 of my head.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:44
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action class

 yes. precisely.

 On Thu, May 13, 2010 at 6:41 AM, James Cook james.c...@wecomm.com wrote:
 Oh, did you want your action as a spring managed bean? Ah I think i 
 massively miss read you. You want to inject predefined values etc?


 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:38
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 thanks. i won't go that route. i noticed your example (in the first
 response) and i realized that i may trying to push some business logic
 into the Action class. and, i don't think that's too good of a
 practice. i simply revised my Service class to hold these values
 (booleans, String, int, etc...) and now the problem goes away. it's a
 workaround.

 if anyone is reading this post and knows how to use struts2 (w/
 convention plugin) + spring to construct Action classes, please let me
 know. the examples i've seen are only with struts1 (and though not too
 complicated, seem verbose with the xml).

 On Thu, May 13, 2010 at 6:20 AM, James Cook james.c...@wecomm.com wrote:
 Yeah sorry, short on time here, didn't see your question at the bottom. Add 
 the spring jar from the spring project.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:16
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 doesn't answer the question but thanks anyways.

 On Thu, May 13, 2010 at 6:12 AM, James Cook james.c...@wecomm.com wrote:
 Nope, no they are not in the xml for me. I use the @Service/@Repository 
 annotations on the class, coupled with the component scan in the Spring 
 xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action 
 class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers me is that it is not obvious at the moment
 how to simply inject strings or booleans into the Action class. it
 should be just as simple.

 upon analyzing what i am doing, and in light of what you said, perhaps
 i am trying to push some logic into the Action class that shouldn't be
 there. perhaps i should push the logic to a service class instead. in
 this case, this problem goes away. BUT, the question remains, how can
 i use DI with struts2 (convention plugin)  and spring on Action
 classes? or can i not? if i can't, end of story. if i can, how?

 On Thu, May 13, 2010 at 5:44 AM, James Cook james.c...@wecomm.com wrote:
 Hmm. I use the same combo.

 I found at some point I could jsut do

 public class MyAction extends ActionSupport {

 private MyInjectedService service

 etc etc

 But I have started doing:

 public class MyAction extends ActionSupport {

 @Autowired
 private MyInjectedService service

 I am not sure if that alters the way Struts2/Spring does it. But it does
 make it a bit clearer to read.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 10:23
 To: user@struts.apache.org
 Subject: spring, struts2, convention plugin, how to wire an action
 class

 i am using struts 2.1.8.1 and the convention plugin. i am also using
 spring for dependency injections (DI). my question is if it is
 possible to to use struts2

Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Denis Cabasson
Jake, the short answer to your problem is : use the struts-spring plugin 
( http://struts.apache.org/2.1.8.1/docs/spring-plugin.html ). Include 
the jar for that plugin in your classpath, and Struts 2 will use Spring 
to manage the Action lifecycle, meaning you can inject anything the way 
you are describing it above (including String, etc...)

Denis.

Le 2010-05-13 08:09, Jake Vang a écrit :

thanks. example please? (when you have time).

On Thu, May 13, 2010 at 6:52 AM, James Cookjames.c...@wecomm.com  wrote:
   

Ahh hmm.

You can use the autowired, You just have to declare you stuff in the spring 
xml. E.g.

bean id=myJDBCString class=java.lang.String 

I think you can also use the @Resource anno as well. Can't think off the top of 
my head.

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com]
Sent: 13 May 2010 11:44
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

yes. precisely.

On Thu, May 13, 2010 at 6:41 AM, James Cookjames.c...@wecomm.com  wrote:
 

Oh, did you want your action as a spring managed bean? Ah I think i massively 
miss read you. You want to inject predefined values etc?


-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com]
Sent: 13 May 2010 11:38
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

thanks. i won't go that route. i noticed your example (in the first
response) and i realized that i may trying to push some business logic
into the Action class. and, i don't think that's too good of a
practice. i simply revised my Service class to hold these values
(booleans, String, int, etc...) and now the problem goes away. it's a
workaround.

if anyone is reading this post and knows how to use struts2 (w/
convention plugin) + spring to construct Action classes, please let me
know. the examples i've seen are only with struts1 (and though not too
complicated, seem verbose with the xml).

On Thu, May 13, 2010 at 6:20 AM, James Cookjames.c...@wecomm.com  wrote:
   

Yeah sorry, short on time here, didn't see your question at the bottom. Add the 
spring jar from the spring project.

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com]
Sent: 13 May 2010 11:16
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

doesn't answer the question but thanks anyways.

On Thu, May 13, 2010 at 6:12 AM, James Cookjames.c...@wecomm.com  wrote:
 

Nope, no they are not in the xml for me. I use the @Service/@Repository 
annotations on the class, coupled with the component scan in the Spring xml.

-Original Message-
From: Jake Vang [mailto:vangj...@googlemail.com]
Sent: 13 May 2010 11:09
To: Struts Users Mailing List
Subject: Re: spring, struts2, convention plugin, how to wire an action class

well, there's something strange about struts2 (with convention plugin)
+ spring. if your action has a field representing a service,
MyInjectedService myInjectedService, you just have to define that in
the spring xml file. for example, your Action class looks like the
following.

public class MyAction extends ActionSupport {
  private Service service;

  @Action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
}

in your spring xml file (i.e. applicationContext.xml), you simply
define a bean with the id=service. for example,

bean id=service class=my.class.Service/

that's it; you don't have to do anything else. you don't even have to
explicitly say (using XML) to inject this when you are creating an
instance of MyAction. now when a user accesses /dummy, MyAction will
be created and its service field will actually be injected with what
is specified in the spring xml file.

what irks me or  bothers me is that it is not obvious at the moment
how to simply inject strings or booleans into the Action class. it
should be just as simple.

upon analyzing what i am doing, and in light of what you said, perhaps
i am trying to push some logic into the Action class that shouldn't be
there. perhaps i should push the logic to a service class instead. in
this case, this problem goes away. BUT, the question remains, how can
i use DI with struts2 (convention plugin)  and spring on Action
classes? or can i not? if i can't, end of story. if i can, how?

On Thu, May 13, 2010 at 5:44 AM, James Cookjames.c...@wecomm.com  wrote:
   

Hmm. I use the same combo.

I found at some point I could jsut do

public class MyAction extends ActionSupport {

private MyInjectedService service

etc etc

But I have started doing:

public class MyAction extends ActionSupport {

@Autowired
private MyInjectedService service

I am not sure if that alters the way Struts2/Spring does it. But it does
make it a bit clearer to read.

-Original Message-
From

Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
yes, i read the documentation for that before posting here too. it
says to simply drop in the struts2-spring-plugin-version.jar. i
already have that in /WEB-INF/lib. however, towards the end of the
document, they are referencing how to initialize Actions from spring
using struts.xml and applicationContext.xml. since i am using
Annotations and the conventions plugin, i don't think this is what i
am looking for. currently, my struts.xml file is 3 lines only! (minus
the DOCTYPE lines).

there are little but significant differences in how a struts2 based
application behaves using the convention plugin (as opposed to using
the traditional struts.xml file).

i am committed to using the convention plugin + annotations and to
avoid as much as possible configurations in struts.xml. if there is an
example of how to get all this working (struts2 + convention +
annotations + spring), i would be most pleased. thanks.

On Thu, May 13, 2010 at 8:24 AM, Denis Cabasson
denis.cabas...@gmail.com wrote:
 Jake, the short answer to your problem is : use the struts-spring plugin (
 http://struts.apache.org/2.1.8.1/docs/spring-plugin.html ). Include the jar
 for that plugin in your classpath, and Struts 2 will use Spring to manage
 the Action lifecycle, meaning you can inject anything the way you are
 describing it above (including String, etc...)
 Denis.

 Le 2010-05-13 08:09, Jake Vang a écrit :

 thanks. example please? (when you have time).

 On Thu, May 13, 2010 at 6:52 AM, James Cookjames.c...@wecomm.com  wrote:


 Ahh hmm.

 You can use the autowired, You just have to declare you stuff in the
 spring xml. E.g.

 bean id=myJDBCString class=java.lang.String 

 I think you can also use the @Resource anno as well. Can't think off the
 top of my head.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:44
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action
 class

 yes. precisely.

 On Thu, May 13, 2010 at 6:41 AM, James Cookjames.c...@wecomm.com
  wrote:


 Oh, did you want your action as a spring managed bean? Ah I think i
 massively miss read you. You want to inject predefined values etc?


 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:38
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an action
 class

 thanks. i won't go that route. i noticed your example (in the first
 response) and i realized that i may trying to push some business logic
 into the Action class. and, i don't think that's too good of a
 practice. i simply revised my Service class to hold these values
 (booleans, String, int, etc...) and now the problem goes away. it's a
 workaround.

 if anyone is reading this post and knows how to use struts2 (w/
 convention plugin) + spring to construct Action classes, please let me
 know. the examples i've seen are only with struts1 (and though not too
 complicated, seem verbose with the xml).

 On Thu, May 13, 2010 at 6:20 AM, James Cookjames.c...@wecomm.com
  wrote:


 Yeah sorry, short on time here, didn't see your question at the bottom.
 Add the spring jar from the spring project.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:16
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an
 action class

 doesn't answer the question but thanks anyways.

 On Thu, May 13, 2010 at 6:12 AM, James Cookjames.c...@wecomm.com
  wrote:


 Nope, no they are not in the xml for me. I use the
 @Service/@Repository annotations on the class, coupled with the component
 scan in the Spring xml.

 -Original Message-
 From: Jake Vang [mailto:vangj...@googlemail.com]
 Sent: 13 May 2010 11:09
 To: Struts Users Mailing List
 Subject: Re: spring, struts2, convention plugin, how to wire an
 action class

 well, there's something strange about struts2 (with convention plugin)
 + spring. if your action has a field representing a service,
 MyInjectedService myInjectedService, you just have to define that in
 the spring xml file. for example, your Action class looks like the
 following.

 public class MyAction extends ActionSupport {
  private Service service;

 �...@action(value=/dummy)
  public String dummy() { return SUCCESS; }
  public Service getService() { return service; }
  public void setService(Service service) { this.service = service; }
 }

 in your spring xml file (i.e. applicationContext.xml), you simply
 define a bean with the id=service. for example,

 bean id=service class=my.class.Service/

 that's it; you don't have to do anything else. you don't even have to
 explicitly say (using XML) to inject this when you are creating an
 instance of MyAction. now when a user accesses /dummy, MyAction will
 be created and its service field will actually be injected with what
 is specified in the spring xml file.

 what irks me or  bothers

Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread RogerV



Jake Vang wrote:
 
 If you want Spring to create your action class (as opposed to Struts
 creating them) then you need to define your action in the
 applicationContext.xml file.
 
 how do you do that? here's a couple of ways i have tried that do NOT work.
 

1) Add constant name=struts.objectFactory
value=org.apache.struts2.spring.StrutsSpringObjectFactory / to your
struts.xml file.

2) Add  listener
   
listener-classorg.springframework.web.context.ContextLoaderListener/listener-class
/listener

to your web.xml

3) Make sure that you have the Struts2 Spring plugin installed.

4) Put something along the lines of
bean id=myAction class=com.somwhere.mypackage.MyAction
scope=prototype/ (The scope prototype is important otherwise Spring
creates a singleton rather than a new action on each invocation which is
what Struts 2 expects)

and that should get Spring instantiating your action classes for you.

Although I'm guessing from your response you've already got to that stage.

I'm not sure that I understand what you are trying to acheive with 

bean name=/action class=com.services.MyAction
 property name=propertyA value=${propertyA}/
/bean  

If you're trying to inject another class, then the format is on the lines of

bean name=/action class=com.services.MyAction
 property name=classA ref=classA/
/bean  

where you need a setter that matches the name parameter (setClassA(ClassA
classA)) in MyAction. The ref value points to another bean id=classA
class=com.services.classA/

HTH and I haven't completely misunderstood what you are trying to do.

Regards


-- 
View this message in context: 
http://old.nabble.com/spring%2C-struts2%2C-convention-plugin%2C-how-to-%22wire%22-an-action-class-tp28545412p28547552.html
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Jake Vang
roger,

thanks for the steps. i went through each of those steps and made sure
my settings/configurations complied. however, i still cannot
initialize Action classes using Spring.

as an illustration of the problem i am facing, i have created an
example that you may download and verify for yourself that this does
not work.

http://www.box.net/shared/iycamr9uo6

this will download a zip file with an Eclipse project; unzip it. if
you have Ant, you simply type in ant war and the war file will be
created. if you have Tomcat, then drop the war file into the webapps
directory (assuming you have Tomcat 6.0).

if you go to http://localhost:8080/myapp/, you will see four lines displayed.
String from Action: default
boolean from Action: false
String from Service: overwritten
boolean from Service: true

The first and second lines confirm that the String and boolean values
are not injected into the Action class. The third and fourth lines
confirm that the String and boolean values are injected into the
service class.

thanks.

On Thu, May 13, 2010 at 9:32 AM, RogerV roger.var...@googlemail.com wrote:



 Jake Vang wrote:

 If you want Spring to create your action class (as opposed to Struts
 creating them) then you need to define your action in the
 applicationContext.xml file.

 how do you do that? here's a couple of ways i have tried that do NOT work.


 1) Add constant name=struts.objectFactory
 value=org.apache.struts2.spring.StrutsSpringObjectFactory / to your
 struts.xml file.

 2) Add  listener

 listener-classorg.springframework.web.context.ContextLoaderListener/listener-class
    /listener

 to your web.xml

 3) Make sure that you have the Struts2 Spring plugin installed.

 4) Put something along the lines of
 bean id=myAction class=com.somwhere.mypackage.MyAction
 scope=prototype/ (The scope prototype is important otherwise Spring
 creates a singleton rather than a new action on each invocation which is
 what Struts 2 expects)

 and that should get Spring instantiating your action classes for you.

 Although I'm guessing from your response you've already got to that stage.

 I'm not sure that I understand what you are trying to acheive with

 bean name=/action class=com.services.MyAction
  property name=propertyA value=${propertyA}/
 /bean

 If you're trying to inject another class, then the format is on the lines of

 bean name=/action class=com.services.MyAction
  property name=classA ref=classA/
 /bean

 where you need a setter that matches the name parameter (setClassA(ClassA
 classA)) in MyAction. The ref value points to another bean id=classA
 class=com.services.classA/

 HTH and I haven't completely misunderstood what you are trying to do.

 Regards


 --
 View this message in context: 
 http://old.nabble.com/spring%2C-struts2%2C-convention-plugin%2C-how-to-%22wire%22-an-action-class-tp28545412p28547552.html
 Sent from the Struts - User mailing list archive at Nabble.com.


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



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



Re: spring, struts2, convention plugin, how to wire an action class

2010-05-13 Thread Denis Cabasson
My best guess is that the Action instance used in the web application is 
not actually loaded from the configuration in your applicationContext, 
but directly by Struts 2 (through the Spring Factory, but still Struts 2).


That mean that you will have a bean named myAction in you application 
context, but that is not the bean that will actually be used by Struts 
to serve your request. Struts will create another instance, which won't 
have any of your configuration. This different instance is then 
autowired by type (defaut behaviour) which means your service 
(configured in your context) gets injected because it has the right type.


I can't actually confirm that behaviour, but that seems like the likely 
explanation. I will be able to double check tomorrow.


To check that, I can recommend 2 things :
* Set the autowiring to be by name, create 2 beans named verbose and 
message, and see how that works
* Leaving the autowiring by type, create 2 instances of your service, 
and my best guess is that Struts will crash, unable to decide between the 2


I think what your are missing is the fact that while struts uses Spring 
to manage the lifecycle of its action, it doesn't use the action defined 
in your application context, but will load its own instances, and 
autowire them.


Denis.

Le 2010-05-13 20:18, Jake Vang a écrit :

roger,

thanks for the steps. i went through each of those steps and made sure
my settings/configurations complied. however, i still cannot
initialize Action classes using Spring.

as an illustration of the problem i am facing, i have created an
example that you may download and verify for yourself that this does
not work.

http://www.box.net/shared/iycamr9uo6

this will download a zip file with an Eclipse project; unzip it. if
you have Ant, you simply type in ant war and the war file will be
created. if you have Tomcat, then drop the war file into the webapps
directory (assuming you have Tomcat 6.0).

if you go to http://localhost:8080/myapp/, you will see four lines displayed.
String from Action: default
boolean from Action: false
String from Service: overwritten
boolean from Service: true

The first and second lines confirm that the String and boolean values
are not injected into the Action class. The third and fourth lines
confirm that the String and boolean values are injected into the
service class.

thanks.

On Thu, May 13, 2010 at 9:32 AM, RogerVroger.var...@googlemail.com  wrote:
   



Jake Vang wrote:
 
   

If you want Spring to create your action class (as opposed to Struts
creating them) then you need to define your action in the
applicationContext.xml file.
 

how do you do that? here's a couple of ways i have tried that do NOT work.

   

1) Addconstant name=struts.objectFactory
value=org.apache.struts2.spring.StrutsSpringObjectFactory /  to your
struts.xml file.

2) Addlistener

listener-classorg.springframework.web.context.ContextLoaderListener/listener-class
/listener

to your web.xml

3) Make sure that you have the Struts2 Spring plugin installed.

4) Put something along the lines of
bean id=myAction class=com.somwhere.mypackage.MyAction
scope=prototype/  (The scope prototype is important otherwise Spring
creates a singleton rather than a new action on each invocation which is
what Struts 2 expects)

and that should get Spring instantiating your action classes for you.

Although I'm guessing from your response you've already got to that stage.

I'm not sure that I understand what you are trying to acheive with

bean name=/action class=com.services.MyAction
  property name=propertyA value=${propertyA}/
/bean

If you're trying to inject another class, then the format is on the lines of

bean name=/action class=com.services.MyAction
  property name=classA ref=classA/
/bean

where you need a setter that matches the name parameter (setClassA(ClassA
classA)) in MyAction. The ref value points to anotherbean id=classA
class=com.services.classA/

HTH and I haven't completely misunderstood what you are trying to do.

Regards


--
View this message in context: 
http://old.nabble.com/spring%2C-struts2%2C-convention-plugin%2C-how-to-%22wire%22-an-action-class-tp28545412p28547552.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


 

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


   



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