Re: [S2] Accessing objects in the Spring context?

2009-09-10 Thread Marty Milligan
On Tue, Sep 8, 2009 at 6:54 PM, James Carr  wrote:
> Eh, that's the more complicated way... struts2 autowires by name, no
> need to implement ApplicationContextAware.

I didn't realize that.  The code in SpringObjectFactory looks for
ContextAware and sets it independently and then calls autowire.  I
just assumed it did this because the Spring contexts was not
autowired.

>I think people are missing
> the point.

I did miss your point as the link you sent as part of this solved the
problem fairly well.  I thought you were looking for a different
approach.

I have not used a filter for this in the past as filtering isn't
related to setting the application context in the servlet context.  I
have subclassed ContextLoaderListener to accomplish this task.  Here
is an example:

public class ApplicationServletContextLoaderListener extends
ContextLoaderListener {
public void contextInitialized(ServletContextEvent event){
super.contextInitialized(event);
ServletContext servletContext = event.getServletContext();
final ApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
servletContext.setAttribute("applicationContex",
new AbstractMap(){
ApplicationContext context = ctx;
public Object get(Object key) {
if(key == null){ return null; }
return context.getBean(key.toString());
}
public Set entrySet(){ return Collections.EMPTY_SET; }
}
);
}
}


I do like the ability of the filter to populate a prototype object
from a request and use it in a later jsp.  I can see how this could
make simple searches easy.  Thanks for posting that.

> I got it working just fine by adding 10 properties to my action with
> appropriate getters and setters, but I'm trying to sneak around having
> to add them to my Actions because I'd rather just have them available
> in my JSPs. No big deal I guess because I got it to work by adding the
> properties to my Action and they get auto-wired by Spring, but it'd be
> REALLY nice if they were available on the context map... it looks like
> I can either writer an Interceptor to put the beans on the stack.

I have tried to avoid the discussions as to why Spring doesn't just
add the application context to the servlet context without additional
work.  This seems to be more of a Spring question than Struts. Most of
the examples I have seen use accessors in a super class to accomplish
what you are doing.  I wish I knew why.

I am confused about why doing this in an interceptor would be better
than in the action.  If you wish to expose a subset of the Spring
beans, the action solution already does that.  If you want to
generally expose the Spring beans to the page, doing it as part of web
app initialization seems like the most convenient approach.

-- 
cordially,
Marty Milligan PO Box 434, Falling Waters, WV 25419
http://milligansisland.com/ http://byteslinger.com/

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



RE: [S2] Accessing objects in the Spring context?

2009-09-09 Thread Mike Baranski
Why not have a base action that has the setters and getters (which extends
ActionSupport), put the methods in there, and have all your actions extend
that instead of ActionSupport.

Mike.

>-Original Message-
>From: Musachy Barroso [mailto:musa...@gmail.com]
>Sent: Tuesday, September 08, 2009 10:11 PM
>To: Struts Users Mailing List
>Subject: Re: [S2] Accessing objects in the Spring context?
>
>I stand corrected. For some (unknown) reason I always thought that
>interceptors and results where created by Class.forName(...)
>
>musachy
>
>On Tue, Sep 8, 2009 at 6:37 PM, Musachy Barroso
>wrote:
>> nope.
>>
>> On Tue, Sep 8, 2009 at 6:32 PM, James Carr
>wrote:
>>> Couldn't I just make it ApplicationContextAware?
>>>
>>> On Tue, Sep 8, 2009 at 8:27 PM, Musachy Barroso
>wrote:
>>>>
>WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActio
>nContext.getServletContext());
>>>>
>>>> On Tue, Sep 8, 2009 at 6:12 PM, James Carr
>wrote:
>>>>> I can try it out... how can I make the bean factory available to my
>interceptor?
>>>>>
>>>>> Thanks,
>>>>> James
>>>>>
>>>>> On Tue, Sep 8, 2009 at 6:12 PM, Wes Wannemacher
>wrote:
>>>>>> I guess I sort of misunderstood your problem. Another approach
>would
>>>>>> be to retrieve the beans in an interceptor and push them onto the
>>>>>> value stack. As long as you give them a name they should be
>available
>>>>>> from the view. This approach will keep you from changing any of
>the
>>>>>> action code. If you want to get really tricky you could try to
>figure
>>>>>> out a declarative way to indicate which beans you want, per action
>>>>>> invocation. I would whip up a quick example but I'm on my phone,
>maybe
>>>>>> later tonight if no one else steps to the challenge.
>>>>>>
>>>>>> On 9/8/09, James Carr  wrote:
>>>>>>> Yeah, I was looking for a way around it... these are simple hash
>maps
>>>>>>> that are used to display select options. I wound up with an
>action
>>>>>>> with 5 Maps in it :(
>>>>>>>
>>>>>>> Thanks,
>>>>>>> James
>>>>>>>
>>>>>>> On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher
>wrote:
>>>>>>>> You could use the @Autowire annotation directly on a property...
>But I
>>>>>>>> don't really see how that is better than using setter-based
>injection.
>>>>>>>> Just because the beans are singletons doesn't mean anything
>special,
>>>>>>>> you still need a reference to them in your struts action.
>>>>>>>>
>>>>>>>> -Wes
>>>>>>>>
>>>>>>>> On Tue, Sep 8, 2009 at 5:13 PM, James
>Carr wrote:
>>>>>>>>> I have several singleton based beans defined in my
>>>>>>>>> applicationContext.xml and I'd like to just use these rather
>than
>>>>>>>>> being forced to set them on my action. is there any way to
>accomplish
>>>>>>>>> this?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> James
>>>>>>>>>
>>>>>>>>> ---
>--
>>>>>>>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>>>>>>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Wes Wannemacher
>>>>>>>>
>>>>>>>> Head Engineer, WanTii, Inc.
>>>>>>>> Need Training? Struts, Spring, Maven, Tomcat...
>>>>>>>> Ask me for a quote!
>>>>>>>>
>>>>>>>> 
>-
>>>>>>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>>>>>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>>>>>>
>>>>>

Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Musachy Barroso
I stand corrected. For some (unknown) reason I always thought that
interceptors and results where created by Class.forName(...)

musachy

On Tue, Sep 8, 2009 at 6:37 PM, Musachy Barroso wrote:
> nope.
>
> On Tue, Sep 8, 2009 at 6:32 PM, James Carr wrote:
>> Couldn't I just make it ApplicationContextAware?
>>
>> On Tue, Sep 8, 2009 at 8:27 PM, Musachy Barroso wrote:
>>> WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
>>>
>>> On Tue, Sep 8, 2009 at 6:12 PM, James Carr wrote:
 I can try it out... how can I make the bean factory available to my 
 interceptor?

 Thanks,
 James

 On Tue, Sep 8, 2009 at 6:12 PM, Wes Wannemacher wrote:
> I guess I sort of misunderstood your problem. Another approach would
> be to retrieve the beans in an interceptor and push them onto the
> value stack. As long as you give them a name they should be available
> from the view. This approach will keep you from changing any of the
> action code. If you want to get really tricky you could try to figure
> out a declarative way to indicate which beans you want, per action
> invocation. I would whip up a quick example but I'm on my phone, maybe
> later tonight if no one else steps to the challenge.
>
> On 9/8/09, James Carr  wrote:
>> Yeah, I was looking for a way around it... these are simple hash maps
>> that are used to display select options. I wound up with an action
>> with 5 Maps in it :(
>>
>> Thanks,
>> James
>>
>> On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
>>> You could use the @Autowire annotation directly on a property... But I
>>> don't really see how that is better than using setter-based injection.
>>> Just because the beans are singletons doesn't mean anything special,
>>> you still need a reference to them in your struts action.
>>>
>>> -Wes
>>>
>>> On Tue, Sep 8, 2009 at 5:13 PM, James Carr 
>>> wrote:
 I have several singleton based beans defined in my
 applicationContext.xml and I'd like to just use these rather than
 being forced to set them on my action. is there any way to accomplish
 this?

 Thanks,
 James

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


>>>
>>>
>>>
>>> --
>>> Wes Wannemacher
>>>
>>> Head Engineer, WanTii, Inc.
>>> Need Training? Struts, Spring, Maven, Tomcat...
>>> Ask me for a quote!
>>>
>>> -
>>> 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
>>
>>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> -
> 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


>>>
>>>
>>>
>>> --
>>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>>
>>> -
>>> 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
>>
>>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Wes Wannemacher
On Tuesday 08 September 2009 09:32:19 pm James Carr wrote:
> Couldn't I just make it ApplicationContextAware?
>
> On Tue, Sep 8, 2009 at 8:27 PM, Musachy Barroso wrote:
> > WebApplicationContextUtils.getRequiredWebApplicationContext(ServletAction
> >Context.getServletContext());

You *can* make it ApplicationContextAware, if and only if you are 
instantiating the interceptor via spring. The benefit to Musachy's suggestion 
is that it will work whether it is Spring instantiated or Struts instantiated. 
Not a big difference tho... 

-W
-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat... 
Ask me for a quote!

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Musachy Barroso
nope.

On Tue, Sep 8, 2009 at 6:32 PM, James Carr wrote:
> Couldn't I just make it ApplicationContextAware?
>
> On Tue, Sep 8, 2009 at 8:27 PM, Musachy Barroso wrote:
>> WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
>>
>> On Tue, Sep 8, 2009 at 6:12 PM, James Carr wrote:
>>> I can try it out... how can I make the bean factory available to my 
>>> interceptor?
>>>
>>> Thanks,
>>> James
>>>
>>> On Tue, Sep 8, 2009 at 6:12 PM, Wes Wannemacher wrote:
 I guess I sort of misunderstood your problem. Another approach would
 be to retrieve the beans in an interceptor and push them onto the
 value stack. As long as you give them a name they should be available
 from the view. This approach will keep you from changing any of the
 action code. If you want to get really tricky you could try to figure
 out a declarative way to indicate which beans you want, per action
 invocation. I would whip up a quick example but I'm on my phone, maybe
 later tonight if no one else steps to the challenge.

 On 9/8/09, James Carr  wrote:
> Yeah, I was looking for a way around it... these are simple hash maps
> that are used to display select options. I wound up with an action
> with 5 Maps in it :(
>
> Thanks,
> James
>
> On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
>> You could use the @Autowire annotation directly on a property... But I
>> don't really see how that is better than using setter-based injection.
>> Just because the beans are singletons doesn't mean anything special,
>> you still need a reference to them in your struts action.
>>
>> -Wes
>>
>> On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
>>> I have several singleton based beans defined in my
>>> applicationContext.xml and I'd like to just use these rather than
>>> being forced to set them on my action. is there any way to accomplish
>>> this?
>>>
>>> Thanks,
>>> James
>>>
>>> -
>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Wes Wannemacher
>>
>> Head Engineer, WanTii, Inc.
>> Need Training? Struts, Spring, Maven, Tomcat...
>> Ask me for a quote!
>>
>> -
>> 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
>
>


 --
 Wes Wannemacher

 Head Engineer, WanTii, Inc.
 Need Training? Struts, Spring, Maven, Tomcat...
 Ask me for a quote!

 -
 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
>>>
>>>
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> -
>> 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
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread James Carr
Couldn't I just make it ApplicationContextAware?

On Tue, Sep 8, 2009 at 8:27 PM, Musachy Barroso wrote:
> WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
>
> On Tue, Sep 8, 2009 at 6:12 PM, James Carr wrote:
>> I can try it out... how can I make the bean factory available to my 
>> interceptor?
>>
>> Thanks,
>> James
>>
>> On Tue, Sep 8, 2009 at 6:12 PM, Wes Wannemacher wrote:
>>> I guess I sort of misunderstood your problem. Another approach would
>>> be to retrieve the beans in an interceptor and push them onto the
>>> value stack. As long as you give them a name they should be available
>>> from the view. This approach will keep you from changing any of the
>>> action code. If you want to get really tricky you could try to figure
>>> out a declarative way to indicate which beans you want, per action
>>> invocation. I would whip up a quick example but I'm on my phone, maybe
>>> later tonight if no one else steps to the challenge.
>>>
>>> On 9/8/09, James Carr  wrote:
 Yeah, I was looking for a way around it... these are simple hash maps
 that are used to display select options. I wound up with an action
 with 5 Maps in it :(

 Thanks,
 James

 On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
> You could use the @Autowire annotation directly on a property... But I
> don't really see how that is better than using setter-based injection.
> Just because the beans are singletons doesn't mean anything special,
> you still need a reference to them in your struts action.
>
> -Wes
>
> On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
>> I have several singleton based beans defined in my
>> applicationContext.xml and I'd like to just use these rather than
>> being forced to set them on my action. is there any way to accomplish
>> this?
>>
>> Thanks,
>> James
>>
>> -
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> -
> 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


>>>
>>>
>>> --
>>> Wes Wannemacher
>>>
>>> Head Engineer, WanTii, Inc.
>>> Need Training? Struts, Spring, Maven, Tomcat...
>>> Ask me for a quote!
>>>
>>> -
>>> 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
>>
>>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> -
> 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: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Musachy Barroso
WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());

On Tue, Sep 8, 2009 at 6:12 PM, James Carr wrote:
> I can try it out... how can I make the bean factory available to my 
> interceptor?
>
> Thanks,
> James
>
> On Tue, Sep 8, 2009 at 6:12 PM, Wes Wannemacher wrote:
>> I guess I sort of misunderstood your problem. Another approach would
>> be to retrieve the beans in an interceptor and push them onto the
>> value stack. As long as you give them a name they should be available
>> from the view. This approach will keep you from changing any of the
>> action code. If you want to get really tricky you could try to figure
>> out a declarative way to indicate which beans you want, per action
>> invocation. I would whip up a quick example but I'm on my phone, maybe
>> later tonight if no one else steps to the challenge.
>>
>> On 9/8/09, James Carr  wrote:
>>> Yeah, I was looking for a way around it... these are simple hash maps
>>> that are used to display select options. I wound up with an action
>>> with 5 Maps in it :(
>>>
>>> Thanks,
>>> James
>>>
>>> On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
 You could use the @Autowire annotation directly on a property... But I
 don't really see how that is better than using setter-based injection.
 Just because the beans are singletons doesn't mean anything special,
 you still need a reference to them in your struts action.

 -Wes

 On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
> I have several singleton based beans defined in my
> applicationContext.xml and I'd like to just use these rather than
> being forced to set them on my action. is there any way to accomplish
> this?
>
> Thanks,
> James
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>



 --
 Wes Wannemacher

 Head Engineer, WanTii, Inc.
 Need Training? Struts, Spring, Maven, Tomcat...
 Ask me for a quote!

 -
 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
>>>
>>>
>>
>>
>> --
>> Wes Wannemacher
>>
>> Head Engineer, WanTii, Inc.
>> Need Training? Struts, Spring, Maven, Tomcat...
>> Ask me for a quote!
>>
>> -
>> 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
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread James Carr
I can try it out... how can I make the bean factory available to my interceptor?

Thanks,
James

On Tue, Sep 8, 2009 at 6:12 PM, Wes Wannemacher wrote:
> I guess I sort of misunderstood your problem. Another approach would
> be to retrieve the beans in an interceptor and push them onto the
> value stack. As long as you give them a name they should be available
> from the view. This approach will keep you from changing any of the
> action code. If you want to get really tricky you could try to figure
> out a declarative way to indicate which beans you want, per action
> invocation. I would whip up a quick example but I'm on my phone, maybe
> later tonight if no one else steps to the challenge.
>
> On 9/8/09, James Carr  wrote:
>> Yeah, I was looking for a way around it... these are simple hash maps
>> that are used to display select options. I wound up with an action
>> with 5 Maps in it :(
>>
>> Thanks,
>> James
>>
>> On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
>>> You could use the @Autowire annotation directly on a property... But I
>>> don't really see how that is better than using setter-based injection.
>>> Just because the beans are singletons doesn't mean anything special,
>>> you still need a reference to them in your struts action.
>>>
>>> -Wes
>>>
>>> On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
 I have several singleton based beans defined in my
 applicationContext.xml and I'd like to just use these rather than
 being forced to set them on my action. is there any way to accomplish
 this?

 Thanks,
 James

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


>>>
>>>
>>>
>>> --
>>> Wes Wannemacher
>>>
>>> Head Engineer, WanTii, Inc.
>>> Need Training? Struts, Spring, Maven, Tomcat...
>>> Ask me for a quote!
>>>
>>> -
>>> 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
>>
>>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> -
> 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: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Wes Wannemacher
I guess I sort of misunderstood your problem. Another approach would
be to retrieve the beans in an interceptor and push them onto the
value stack. As long as you give them a name they should be available
from the view. This approach will keep you from changing any of the
action code. If you want to get really tricky you could try to figure
out a declarative way to indicate which beans you want, per action
invocation. I would whip up a quick example but I'm on my phone, maybe
later tonight if no one else steps to the challenge.

On 9/8/09, James Carr  wrote:
> Yeah, I was looking for a way around it... these are simple hash maps
> that are used to display select options. I wound up with an action
> with 5 Maps in it :(
>
> Thanks,
> James
>
> On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
>> You could use the @Autowire annotation directly on a property... But I
>> don't really see how that is better than using setter-based injection.
>> Just because the beans are singletons doesn't mean anything special,
>> you still need a reference to them in your struts action.
>>
>> -Wes
>>
>> On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
>>> I have several singleton based beans defined in my
>>> applicationContext.xml and I'd like to just use these rather than
>>> being forced to set them on my action. is there any way to accomplish
>>> this?
>>>
>>> Thanks,
>>> James
>>>
>>> -
>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Wes Wannemacher
>>
>> Head Engineer, WanTii, Inc.
>> Need Training? Struts, Spring, Maven, Tomcat...
>> Ask me for a quote!
>>
>> -
>> 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
>
>


-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread James Carr
Eh, that's the more complicated way... struts2 autowires by name, no
need to implement ApplicationContextAware. I think people are missing
the point.

I got it working just fine by adding 10 properties to my action with
appropriate getters and setters, but I'm trying to sneak around having
to add them to my Actions because I'd rather just have them available
in my JSPs. No big deal I guess because I got it to work by adding the
properties to my Action and they get auto-wired by Spring, but it'd be
REALLY nice if they were available on the context map... it looks like
I can either writer an Interceptor to put the beans on the stack.

Thanks,
James

On Tue, Sep 8, 2009 at 6:30 PM, Marty Milligan wrote:
> On Tue, Sep 8, 2009 at 5:55 PM, James Carr wrote:
>> Yeah, I was looking for a way around it... these are simple hash maps
>> that are used to display select options. I wound up with an action
>> with 5 Maps in it :(
>
> If it were me, this is what I would do.
>
> First,use a Spring object factory in your Struts configuration:
> 
>
> Second, in your action class, implement
> org.springframework.context.ApplicationContextAware:
>    public void setApplicationContext(ApplicationContext ctx) throws
> BeansException {
>        this.ctx = ctx;
>    }
>
> Third, implement any getters on the action that your view will need
> from the context.
>
> Fourth, define your action in the Spring configuration file:
>    
>        ...
>    
>
> Fifth, test this to see if my memory is as good as I recall.
>
> And lastly, sorry I have not yet introduced myself, I just joined
> because I'm converting one of my applications to Struts 2.
>
> --
> cordially,
> Marty Milligan PO Box 434, Falling Waters, WV 25419
> http://milligansisland.com/ http://byteslinger.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: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Marty Milligan
On Tue, Sep 8, 2009 at 5:55 PM, James Carr wrote:
> Yeah, I was looking for a way around it... these are simple hash maps
> that are used to display select options. I wound up with an action
> with 5 Maps in it :(

If it were me, this is what I would do.

First,use a Spring object factory in your Struts configuration:


Second, in your action class, implement
org.springframework.context.ApplicationContextAware:
public void setApplicationContext(ApplicationContext ctx) throws
BeansException {
this.ctx = ctx;
}

Third, implement any getters on the action that your view will need
from the context.

Fourth, define your action in the Spring configuration file:

...


Fifth, test this to see if my memory is as good as I recall.

And lastly, sorry I have not yet introduced myself, I just joined
because I'm converting one of my applications to Struts 2.

-- 
cordially,
Marty Milligan PO Box 434, Falling Waters, WV 25419
http://milligansisland.com/ http://byteslinger.com/

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread James Carr
Yeah, I was looking for a way around it... these are simple hash maps
that are used to display select options. I wound up with an action
with 5 Maps in it :(

Thanks,
James

On Tue, Sep 8, 2009 at 4:26 PM, Wes Wannemacher wrote:
> You could use the @Autowire annotation directly on a property... But I
> don't really see how that is better than using setter-based injection.
> Just because the beans are singletons doesn't mean anything special,
> you still need a reference to them in your struts action.
>
> -Wes
>
> On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
>> I have several singleton based beans defined in my
>> applicationContext.xml and I'd like to just use these rather than
>> being forced to set them on my action. is there any way to accomplish
>> this?
>>
>> Thanks,
>> James
>>
>> -
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> -
> 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: [S2] Accessing objects in the Spring context?

2009-09-08 Thread Wes Wannemacher
You could use the @Autowire annotation directly on a property... But I
don't really see how that is better than using setter-based injection.
Just because the beans are singletons doesn't mean anything special,
you still need a reference to them in your struts action.

-Wes

On Tue, Sep 8, 2009 at 5:13 PM, James Carr wrote:
> I have several singleton based beans defined in my
> applicationContext.xml and I'd like to just use these rather than
> being forced to set them on my action. is there any way to accomplish
> this?
>
> Thanks,
> James
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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



Re: [S2] Accessing objects in the Spring context?

2009-09-08 Thread James Carr
I suppose I may use this:
http://wiki.opensymphony.com/display/ABLE/Expose+Spring+Beans+in+JSP

But I really wish/hope that struts2 has something built in.

Thanks,
James

On Tue, Sep 8, 2009 at 4:13 PM, James Carr wrote:
> I have several singleton based beans defined in my
> applicationContext.xml and I'd like to just use these rather than
> being forced to set them on my action. is there any way to accomplish
> this?
>
> Thanks,
> James
>

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