RE: Struts2 Action Class and EJB Injection

2009-07-16 Thread Martin Gainty

ive used OpenEJB with TC 
then again you could deploy your EAR to a true EJB3 container with a 
J2EE-AppServer such as GF, WL or AMSServer..even resin would handle EJBs
?
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, 16 Jul 2009 07:16:14 +0200
> From: ro...@mtndesigns.co.uk
> To: user@struts.apache.org
> Subject: Re: Struts2 Action Class and EJB Injection
> 
> Thanks for the example.  I shall download the source and give it a go.
> 
> Thanks again.
> 
> Nathan Schulte wrote:
> > Robin Mannering  mtndesigns.co.uk> writes:
> >   
> >> Can you please tell me how you obtained the EJB plugin and a short 
> >> example of using it.
> >>
> >> I would prefer to use this if possible.
> >> 
> >
> > Sorr, I misspoke earlier.  I'm actually using the EJB3 JBoss Plugin, from 
> > here
> > http://cwiki.apache.org/S2PLUGINS/ejb3-jboss-plugin.html.
> >
> > However, browsing the source for the EJB3 Plugin, the annotations and even
> > classes are named the same, so the following example should still apply;
> > http://pastebin.com/f7053a2bc.
> >
> >
> > -
> > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> > For additional commands, e-mail: user-h...@struts.apache.org
> >   
> > 
> >
> >
> > No virus found in this incoming message.
> > Checked by AVG - www.avg.com 
> > Version: 8.5.387 / Virus Database: 270.13.14/2238 - Release Date: 07/14/09 
> > 18:03:00
> >
> >   

_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009

Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Robin Mannering

Thanks for the example.  I shall download the source and give it a go.

Thanks again.

Nathan Schulte wrote:

Robin Mannering  mtndesigns.co.uk> writes:
  
Can you please tell me how you obtained the EJB plugin and a short 
example of using it.


I would prefer to use this if possible.



Sorr, I misspoke earlier.  I'm actually using the EJB3 JBoss Plugin, from here
http://cwiki.apache.org/S2PLUGINS/ejb3-jboss-plugin.html.

However, browsing the source for the EJB3 Plugin, the annotations and even
classes are named the same, so the following example should still apply;
http://pastebin.com/f7053a2bc.


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




No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.14/2238 - Release Date: 07/14/09 18:03:00


  


Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Nathan Schulte
Robin Mannering  mtndesigns.co.uk> writes:
> Can you please tell me how you obtained the EJB plugin and a short 
> example of using it.
> 
> I would prefer to use this if possible.

Sorr, I misspoke earlier.  I'm actually using the EJB3 JBoss Plugin, from here
http://cwiki.apache.org/S2PLUGINS/ejb3-jboss-plugin.html.

However, browsing the source for the EJB3 Plugin, the annotations and even
classes are named the same, so the following example should still apply;
http://pastebin.com/f7053a2bc.


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



Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Robin Mannering
Can you please tell me how you obtained the EJB plugin and a short 
example of using it.


I would prefer to use this if possible.

Nathan Schulte wrote:

Robin Mannering wrote:
  
Is there anybody that is using Struts2 as the 'frontend' to an EJB 3 
'backend' and what solution do you currently employ.



I am using the described setup, yes.  Our solution was to use the mentioned EJB3
plugin and it's @InjectEJB annotation.  It works well, I have not had any issues
thus far.

  

Wes Wannemacher wrote:


Would anyone else be interested in an ObjectFactory based plugin?
If so, would any of you also want it to work with Spring?
  


I am interested in this, particularly for supporting persistence annotations,
like the aforementioned @PersistenceContext.  Most of the persistence support
that I have seen for struts, and the questions posted regarding persistence, all
seem to be using application managed persistence.  Getting things to work with
CMT would be excellent.


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




No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.14/2238 - Release Date: 07/14/09 18:03:00


  


Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Nathan Schulte
Robin Mannering wrote:
> Is there anybody that is using Struts2 as the 'frontend' to an EJB 3 
> 'backend' and what solution do you currently employ.

I am using the described setup, yes.  Our solution was to use the mentioned EJB3
plugin and it's @InjectEJB annotation.  It works well, I have not had any issues
thus far.

> Wes Wannemacher wrote:
> > Would anyone else be interested in an ObjectFactory based plugin?
> > If so, would any of you also want it to work with Spring?

I am interested in this, particularly for supporting persistence annotations,
like the aforementioned @PersistenceContext.  Most of the persistence support
that I have seen for struts, and the questions posted regarding persistence, all
seem to be using application managed persistence.  Getting things to work with
CMT would be excellent.


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



Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Robin Mannering

Yes, using annotations would be the ideal method.

I think I remember reading that declaring beans as 'remote' when this is 
not that case, may cause unnecessary serialization/deserialization as 
calls are supposedly being made remotely.  Depending on the EJB app 
server configuration.


Obviously, this could cause significant overhead when returning large 
result sets from a session bean.


I've yet to find where I read that but will update this thread if/when I do.

Robin

Wes Wannemacher wrote:

I don't see anything wrong with that. I'd still like to eventually
create a plugin that removes the need to do that in your execute
method. The EJB spec added those annotations, so I'd like to figure
out a way to honor them (cleanly).

-Wes

On Wed, Jul 15, 2009 at 10:37 AM, Robin Mannering wrote:
  

Hi Wes,

I found a resource on the web that seems to be a simpler solution:

InitialContext ic = new InitialContext();
UserServiceBeanLocal userService = (UserServiceBeanLocal)
ic.lookup(UserServiceBeanLocal.class.getName());

As in the web resource I found, it was necessary to change @Local to @Remote
in the session bean for it to be found correctly.

It worked perfectly using the above.

Here is a link to the resource.  What do you think of this solution?

http://www.coderanch.com/t/58279/Struts/Connecting-ejb-session-bean-from

Thanks
Robin

Wes Wannemacher wrote:


You are right, there is only one, the other one in that list is a
jboss-ejb plugin. Take a look at the source for the plugin, it is not
particularly complex and I know the author is lurking around here
somewhere. I would suggest that you do one of two things -
1. Create an interceptor, probably identical to the one in the plugin.
If you have troubles, bring them to the list, we'll help.
2. Create an object factory implementation that creates actions using
your container's semantics. Again, if you have troubles, bring 'em
back here, we'll help you.

-Wes

On Wed, Jul 15, 2009 at 9:48 AM, Robin Mannering
wrote:

  

Many thanks for the prompt and detailed reply.

I understand why the use of injection does not work now within a Struts2
action class.

However, there only seems one EJB plugin available, which doesn't
actually
have a download available and hasn't had for some time it appears.

http://code.google.com/p/struts2ejb3/downloads/list

I'm wary to trust in a plugin that doesn't appear to be currently
maintained
(available to download).

Is there anybody that is using Struts2 as the 'frontend' to an EJB 3
'backend' and what solution do you currently employ.

Thanks
Robin

Wes Wannemacher wrote:



The difference is that the container did not instantiate your struts
action, struts did. There are EJB plugins available, check the plugin
registry.

http://cwiki.apache.org/S2PLUGINS/home.html

The ones I have seen are based on injection via interceptor. I've
toyed with the notion of creating an ObjectFactory based plugin so
that struts can delegate creation of action classes to the ejb
container. This would allow for injection for more than just @EJB
(@PersistenceContext comes to mind).

The only issue is that it doesn't seem like we see much traffic on
here from ejb users. Would anyone else be interested in an
ObjectFactory based plugin? If so, would any of you also want it to
work with Spring? The interceptor-based solution works good because it
doesn't interfere with object-creation-based plugins like
spring/guice/etc.

-Wes

On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering
wrote:


  

Hello,

Platform : Struts 2, EJB 3.0, Glassfish 2.1

I wish to obtain a reference to an EJB using injection.

This works fine within a servlet, but from within a Struts2 action
class,
all references to injected EJB variables hold a 'null' reference.

I've included a portion of my action class below.

I'm confused as to why a Servlet has no trouble using injection as
compared
to the Struts 2 action class.  Both the servlet and action class reside
in
the same Web application.

Does anybody have any ideas?

/public class UserAction extends ActionSupport implements
ServletRequestAware, SessionAware {

 private static Logger logger = Logger.getLogger(SetupServlet.class);
  @EJB
 SetupServiceBeanLocal setupService;
  @EJB
 UserServiceBeanLocal userService;
...
}/





 


No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
270.13.14/2238 - Release Date: 07/14/09 18:03:00



  


 


No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
270.13.14/2238 - Release Date: 07/14/09 18:03:00


  




  




No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.

Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Wes Wannemacher
I don't see anything wrong with that. I'd still like to eventually
create a plugin that removes the need to do that in your execute
method. The EJB spec added those annotations, so I'd like to figure
out a way to honor them (cleanly).

-Wes

On Wed, Jul 15, 2009 at 10:37 AM, Robin Mannering wrote:
> Hi Wes,
>
> I found a resource on the web that seems to be a simpler solution:
>
> InitialContext ic = new InitialContext();
> UserServiceBeanLocal userService = (UserServiceBeanLocal)
> ic.lookup(UserServiceBeanLocal.class.getName());
>
> As in the web resource I found, it was necessary to change @Local to @Remote
> in the session bean for it to be found correctly.
>
> It worked perfectly using the above.
>
> Here is a link to the resource.  What do you think of this solution?
>
> http://www.coderanch.com/t/58279/Struts/Connecting-ejb-session-bean-from
>
> Thanks
> Robin
>
> Wes Wannemacher wrote:
>>
>> You are right, there is only one, the other one in that list is a
>> jboss-ejb plugin. Take a look at the source for the plugin, it is not
>> particularly complex and I know the author is lurking around here
>> somewhere. I would suggest that you do one of two things -
>> 1. Create an interceptor, probably identical to the one in the plugin.
>> If you have troubles, bring them to the list, we'll help.
>> 2. Create an object factory implementation that creates actions using
>> your container's semantics. Again, if you have troubles, bring 'em
>> back here, we'll help you.
>>
>> -Wes
>>
>> On Wed, Jul 15, 2009 at 9:48 AM, Robin Mannering
>> wrote:
>>
>>>
>>> Many thanks for the prompt and detailed reply.
>>>
>>> I understand why the use of injection does not work now within a Struts2
>>> action class.
>>>
>>> However, there only seems one EJB plugin available, which doesn't
>>> actually
>>> have a download available and hasn't had for some time it appears.
>>>
>>> http://code.google.com/p/struts2ejb3/downloads/list
>>>
>>> I'm wary to trust in a plugin that doesn't appear to be currently
>>> maintained
>>> (available to download).
>>>
>>> Is there anybody that is using Struts2 as the 'frontend' to an EJB 3
>>> 'backend' and what solution do you currently employ.
>>>
>>> Thanks
>>> Robin
>>>
>>> Wes Wannemacher wrote:
>>>

 The difference is that the container did not instantiate your struts
 action, struts did. There are EJB plugins available, check the plugin
 registry.

 http://cwiki.apache.org/S2PLUGINS/home.html

 The ones I have seen are based on injection via interceptor. I've
 toyed with the notion of creating an ObjectFactory based plugin so
 that struts can delegate creation of action classes to the ejb
 container. This would allow for injection for more than just @EJB
 (@PersistenceContext comes to mind).

 The only issue is that it doesn't seem like we see much traffic on
 here from ejb users. Would anyone else be interested in an
 ObjectFactory based plugin? If so, would any of you also want it to
 work with Spring? The interceptor-based solution works good because it
 doesn't interfere with object-creation-based plugins like
 spring/guice/etc.

 -Wes

 On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering
 wrote:


>
> Hello,
>
> Platform : Struts 2, EJB 3.0, Glassfish 2.1
>
> I wish to obtain a reference to an EJB using injection.
>
> This works fine within a servlet, but from within a Struts2 action
> class,
> all references to injected EJB variables hold a 'null' reference.
>
> I've included a portion of my action class below.
>
> I'm confused as to why a Servlet has no trouble using injection as
> compared
> to the Struts 2 action class.  Both the servlet and action class reside
> in
> the same Web application.
>
> Does anybody have any ideas?
>
> /public class UserAction extends ActionSupport implements
> ServletRequestAware, SessionAware {
>
>  private static Logger logger = Logger.getLogger(SetupServlet.class);
>   @EJB
>  SetupServiceBeanLocal setupService;
>   @EJB
>  UserServiceBeanLocal userService;
> ...
> }/
>
>
>


  


 No virus found in this incoming message.
 Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
 270.13.14/2238 - Release Date: 07/14/09 18:03:00



>>
>>
>>
>>  
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
>> 270.13.14/2238 - Release Date: 07/14/09 18:03:00
>>
>>
>



-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

--

Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Robin Mannering

Hi Wes,

I found a resource on the web that seems to be a simpler solution:

InitialContext ic = new InitialContext();
UserServiceBeanLocal userService = (UserServiceBeanLocal) 
ic.lookup(UserServiceBeanLocal.class.getName());


As in the web resource I found, it was necessary to change @Local to 
@Remote in the session bean for it to be found correctly.


It worked perfectly using the above.

Here is a link to the resource.  What do you think of this solution?

http://www.coderanch.com/t/58279/Struts/Connecting-ejb-session-bean-from

Thanks
Robin

Wes Wannemacher wrote:

You are right, there is only one, the other one in that list is a
jboss-ejb plugin. Take a look at the source for the plugin, it is not
particularly complex and I know the author is lurking around here
somewhere. I would suggest that you do one of two things -
1. Create an interceptor, probably identical to the one in the plugin.
If you have troubles, bring them to the list, we'll help.
2. Create an object factory implementation that creates actions using
your container's semantics. Again, if you have troubles, bring 'em
back here, we'll help you.

-Wes

On Wed, Jul 15, 2009 at 9:48 AM, Robin Mannering wrote:
  

Many thanks for the prompt and detailed reply.

I understand why the use of injection does not work now within a Struts2
action class.

However, there only seems one EJB plugin available, which doesn't actually
have a download available and hasn't had for some time it appears.

http://code.google.com/p/struts2ejb3/downloads/list

I'm wary to trust in a plugin that doesn't appear to be currently maintained
(available to download).

Is there anybody that is using Struts2 as the 'frontend' to an EJB 3
'backend' and what solution do you currently employ.

Thanks
Robin

Wes Wannemacher wrote:


The difference is that the container did not instantiate your struts
action, struts did. There are EJB plugins available, check the plugin
registry.

http://cwiki.apache.org/S2PLUGINS/home.html

The ones I have seen are based on injection via interceptor. I've
toyed with the notion of creating an ObjectFactory based plugin so
that struts can delegate creation of action classes to the ejb
container. This would allow for injection for more than just @EJB
(@PersistenceContext comes to mind).

The only issue is that it doesn't seem like we see much traffic on
here from ejb users. Would anyone else be interested in an
ObjectFactory based plugin? If so, would any of you also want it to
work with Spring? The interceptor-based solution works good because it
doesn't interfere with object-creation-based plugins like
spring/guice/etc.

-Wes

On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering
wrote:

  

Hello,

Platform : Struts 2, EJB 3.0, Glassfish 2.1

I wish to obtain a reference to an EJB using injection.

This works fine within a servlet, but from within a Struts2 action class,
all references to injected EJB variables hold a 'null' reference.

I've included a portion of my action class below.

I'm confused as to why a Servlet has no trouble using injection as
compared
to the Struts 2 action class.  Both the servlet and action class reside
in
the same Web application.

Does anybody have any ideas?

/public class UserAction extends ActionSupport implements
ServletRequestAware, SessionAware {

 private static Logger logger = Logger.getLogger(SetupServlet.class);
   @EJB
 SetupServiceBeanLocal setupService;
   @EJB
 UserServiceBeanLocal userService;
...
}/





 


No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
270.13.14/2238 - Release Date: 07/14/09 18:03:00


  




  




No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.14/2238 - Release Date: 07/14/09 18:03:00


  


Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Wes Wannemacher
You are right, there is only one, the other one in that list is a
jboss-ejb plugin. Take a look at the source for the plugin, it is not
particularly complex and I know the author is lurking around here
somewhere. I would suggest that you do one of two things -
1. Create an interceptor, probably identical to the one in the plugin.
If you have troubles, bring them to the list, we'll help.
2. Create an object factory implementation that creates actions using
your container's semantics. Again, if you have troubles, bring 'em
back here, we'll help you.

-Wes

On Wed, Jul 15, 2009 at 9:48 AM, Robin Mannering wrote:
> Many thanks for the prompt and detailed reply.
>
> I understand why the use of injection does not work now within a Struts2
> action class.
>
> However, there only seems one EJB plugin available, which doesn't actually
> have a download available and hasn't had for some time it appears.
>
> http://code.google.com/p/struts2ejb3/downloads/list
>
> I'm wary to trust in a plugin that doesn't appear to be currently maintained
> (available to download).
>
> Is there anybody that is using Struts2 as the 'frontend' to an EJB 3
> 'backend' and what solution do you currently employ.
>
> Thanks
> Robin
>
> Wes Wannemacher wrote:
>>
>> The difference is that the container did not instantiate your struts
>> action, struts did. There are EJB plugins available, check the plugin
>> registry.
>>
>> http://cwiki.apache.org/S2PLUGINS/home.html
>>
>> The ones I have seen are based on injection via interceptor. I've
>> toyed with the notion of creating an ObjectFactory based plugin so
>> that struts can delegate creation of action classes to the ejb
>> container. This would allow for injection for more than just @EJB
>> (@PersistenceContext comes to mind).
>>
>> The only issue is that it doesn't seem like we see much traffic on
>> here from ejb users. Would anyone else be interested in an
>> ObjectFactory based plugin? If so, would any of you also want it to
>> work with Spring? The interceptor-based solution works good because it
>> doesn't interfere with object-creation-based plugins like
>> spring/guice/etc.
>>
>> -Wes
>>
>> On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering
>> wrote:
>>
>>>
>>> Hello,
>>>
>>> Platform : Struts 2, EJB 3.0, Glassfish 2.1
>>>
>>> I wish to obtain a reference to an EJB using injection.
>>>
>>> This works fine within a servlet, but from within a Struts2 action class,
>>> all references to injected EJB variables hold a 'null' reference.
>>>
>>> I've included a portion of my action class below.
>>>
>>> I'm confused as to why a Servlet has no trouble using injection as
>>> compared
>>> to the Struts 2 action class.  Both the servlet and action class reside
>>> in
>>> the same Web application.
>>>
>>> Does anybody have any ideas?
>>>
>>> /public class UserAction extends ActionSupport implements
>>> ServletRequestAware, SessionAware {
>>>
>>>  private static Logger logger = Logger.getLogger(SetupServlet.class);
>>>   �...@ejb
>>>  SetupServiceBeanLocal setupService;
>>>   �...@ejb
>>>  UserServiceBeanLocal userService;
>>> ...
>>> }/
>>>
>>>
>>
>>
>>
>>  
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
>> 270.13.14/2238 - Release Date: 07/14/09 18:03:00
>>
>>
>



-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

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



Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Robin Mannering

Many thanks for the prompt and detailed reply.

I understand why the use of injection does not work now within a Struts2 
action class.


However, there only seems one EJB plugin available, which doesn't 
actually have a download available and hasn't had for some time it appears.


http://code.google.com/p/struts2ejb3/downloads/list

I'm wary to trust in a plugin that doesn't appear to be currently 
maintained (available to download).


Is there anybody that is using Struts2 as the 'frontend' to an EJB 3 
'backend' and what solution do you currently employ.


Thanks
Robin

Wes Wannemacher wrote:

The difference is that the container did not instantiate your struts
action, struts did. There are EJB plugins available, check the plugin
registry.

http://cwiki.apache.org/S2PLUGINS/home.html

The ones I have seen are based on injection via interceptor. I've
toyed with the notion of creating an ObjectFactory based plugin so
that struts can delegate creation of action classes to the ejb
container. This would allow for injection for more than just @EJB
(@PersistenceContext comes to mind).

The only issue is that it doesn't seem like we see much traffic on
here from ejb users. Would anyone else be interested in an
ObjectFactory based plugin? If so, would any of you also want it to
work with Spring? The interceptor-based solution works good because it
doesn't interfere with object-creation-based plugins like
spring/guice/etc.

-Wes

On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering wrote:
  

Hello,

Platform : Struts 2, EJB 3.0, Glassfish 2.1

I wish to obtain a reference to an EJB using injection.

This works fine within a servlet, but from within a Struts2 action class,
all references to injected EJB variables hold a 'null' reference.

I've included a portion of my action class below.

I'm confused as to why a Servlet has no trouble using injection as compared
to the Struts 2 action class.  Both the servlet and action class reside in
the same Web application.

Does anybody have any ideas?

/public class UserAction extends ActionSupport implements
ServletRequestAware, SessionAware {

  private static Logger logger = Logger.getLogger(SetupServlet.class);
@EJB
  SetupServiceBeanLocal setupService;
@EJB
  UserServiceBeanLocal userService;
...
}/






  




No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.14/2238 - Release Date: 07/14/09 18:03:00


  


Re: Struts2 Action Class and EJB Injection

2009-07-15 Thread Wes Wannemacher
The difference is that the container did not instantiate your struts
action, struts did. There are EJB plugins available, check the plugin
registry.

http://cwiki.apache.org/S2PLUGINS/home.html

The ones I have seen are based on injection via interceptor. I've
toyed with the notion of creating an ObjectFactory based plugin so
that struts can delegate creation of action classes to the ejb
container. This would allow for injection for more than just @EJB
(@PersistenceContext comes to mind).

The only issue is that it doesn't seem like we see much traffic on
here from ejb users. Would anyone else be interested in an
ObjectFactory based plugin? If so, would any of you also want it to
work with Spring? The interceptor-based solution works good because it
doesn't interfere with object-creation-based plugins like
spring/guice/etc.

-Wes

On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering wrote:
> Hello,
>
> Platform : Struts 2, EJB 3.0, Glassfish 2.1
>
> I wish to obtain a reference to an EJB using injection.
>
> This works fine within a servlet, but from within a Struts2 action class,
> all references to injected EJB variables hold a 'null' reference.
>
> I've included a portion of my action class below.
>
> I'm confused as to why a Servlet has no trouble using injection as compared
> to the Struts 2 action class.  Both the servlet and action class reside in
> the same Web application.
>
> Does anybody have any ideas?
>
> /public class UserAction extends ActionSupport implements
> ServletRequestAware, SessionAware {
>
>   private static Logger logger = Logger.getLogger(SetupServlet.class);
>     @EJB
>   SetupServiceBeanLocal setupService;
>     @EJB
>   UserServiceBeanLocal userService;
> ...
> }/
>



-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

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