Inject bean in overriden locale picker

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Inject bean in overriden locale picker

rob_gar
Hi all,

I created my own LocalePicker implementation, I just created a new class and mapped it in web.xml:

        <!-- Override the default localepicker class -->
        <init-param>
            <param-name>LocalePicker.Class</param-name>
            <param-value>com.my.own.LocalePicker</param-value>
        </init-param>

it works, however I have Spring integrated in my app, so I need to inject a Spring bean, I tried this:

public class LocalePicker extends DefaultLocalePicker {
MyBean myBean;

    @SpringBean("myBean")
    protected void setMyBean(MyBean mybean) {
        this.myBean = myBean;
    }


It's not working, the "myBean" bean is properly created by Spring but I cannot inject it in my overriden default locale picker.

Kindly advice, thanks.

///RGB




------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Inject bean in overriden locale picker

Freddy D.
If you have the Stripes book, there are more details about this
in the "Dependency Injection with Spring" section. In summary,
you have to subclass the Stripes default locale picker factory,
call the superclass method to create the object, and use
SpringHelper.injectBeans( ) on the object before returning it.

Cheers,
Freddy

On Thu, Jun 13, 2013, at 07:24 AM, Rob GB wrote:

Hi all,

I created my own LocalePicker implementation, I just created a new
class and mapped it in web.xml:

        <!-- Override the default localepicker class -->
        <init-param>
            <param-name>LocalePicker.Class</param-name>
            <param-value>com.my.own.LocalePicker</param-value>
        </init-param>

it works, however I have Spring integrated in my app, so I need to
inject a Spring bean, I tried this:

public class LocalePicker extends DefaultLocalePicker {
MyBean myBean;

    @SpringBean("myBean")
    protected void setMyBean(MyBean mybean) {
        this.myBean = myBean;
    }


It's not working, the "myBean" bean is properly created by Spring but I
cannot inject it in my overriden default locale picker.

Kindly advice, thanks.

///RGB



-----------------------------------------------------------------------
-------

This SF.net email is sponsored by Windows:



Build for Windows Store.



[1]http://p.sf.net/sfu/windows-dev2dev

_______________________________________________

Stripes-users mailing list

[2][hidden email]

[3]https://lists.sourceforge.net/lists/listinfo/stripes-users

References

1. http://p.sf.net/sfu/windows-dev2dev
2. mailto:[hidden email]
3. https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Inject bean in overriden locale picker

VANKEISBELCK Remi
Hi Rob,

You can also use the Spring APIs directly and skip the annotation and SpringHelper...

I mean, calling beanFactory.getBean("myBean") doesn't hurt if you do it only there. 

You can access the servletContext at init time :

So store a ref to your ApplicationContext (WebApplicationContext if I remember well, it's been a while with Spring), and invoke getBean() when necessary...

Cheers

Remi


 


2013/6/13 Freddy Daoud <[hidden email]>
If you have the Stripes book, there are more details about this
in the "Dependency Injection with Spring" section. In summary,
you have to subclass the Stripes default locale picker factory,
call the superclass method to create the object, and use
SpringHelper.injectBeans( ) on the object before returning it.

Cheers,
Freddy

On Thu, Jun 13, 2013, at 07:24 AM, Rob GB wrote:

Hi all,

I created my own LocalePicker implementation, I just created a new
class and mapped it in web.xml:

        <!-- Override the default localepicker class -->
        <init-param>
            <param-name>LocalePicker.Class</param-name>
            <param-value>com.my.own.LocalePicker</param-value>
        </init-param>

it works, however I have Spring integrated in my app, so I need to
inject a Spring bean, I tried this:

public class LocalePicker extends DefaultLocalePicker {
MyBean myBean;

    @SpringBean("myBean")
    protected void setMyBean(MyBean mybean) {
        this.myBean = myBean;
    }


It's not working, the "myBean" bean is properly created by Spring but I
cannot inject it in my overriden default locale picker.

Kindly advice, thanks.

///RGB



-----------------------------------------------------------------------
-------

This SF.net email is sponsored by Windows:



Build for Windows Store.



[1]http://p.sf.net/sfu/windows-dev2dev

_______________________________________________

Stripes-users mailing list

[2][hidden email]

[3]https://lists.sourceforge.net/lists/listinfo/stripes-users

References

1. http://p.sf.net/sfu/windows-dev2dev
2. mailto:[hidden email]
3. https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Inject bean in overriden locale picker

rob_gar
In reply to this post by Freddy D.
Thanks Fred!

> From: [hidden email]

> To: [hidden email]
> Date: Thu, 13 Jun 2013 08:11:31 -0400
> Subject: Re: [Stripes-users] Inject bean in overriden locale picker
>
> If you have the Stripes book, there are more details about this
> in the "Dependency Injection with Spring" section. In summary,
> you have to subclass the Stripes default locale picker factory,
> call the superclass method to create the object, and use
> SpringHelper.injectBeans( ) on the object before returning it.
>
> Cheers,
> Freddy
>
> On Thu, Jun 13, 2013, at 07:24 AM, Rob GB wrote:
>
> Hi all,
>
> I created my own LocalePicker implementation, I just created a new
> class and mapped it in web.xml:
>
> <!-- Override the default localepicker class -->
> <init-param>
> <param-name>LocalePicker.Class</param-name>
> <param-value>com.my.own.LocalePicker</param-value>
> </init-param>
>
> it works, however I have Spring integrated in my app, so I need to
> inject a Spring bean, I tried this:
>
> public class LocalePicker extends DefaultLocalePicker {
> MyBean myBean;
>
> @SpringBean("myBean")
> protected void setMyBean(MyBean mybean) {
> this.myBean = myBean;
> }
>
>
> It's not working, the "myBean" bean is properly created by Spring but I
> cannot inject it in my overriden default locale picker.
>
> Kindly advice, thanks.
>
> ///RGB
>
>
>
> -----------------------------------------------------------------------
> -------
>
> This SF.net email is sponsored by Windows:
>
>
>
> Build for Windows Store.
>
>
>
> [1]http://p.sf.net/sfu/windows-dev2dev
>
> _______________________________________________
>
> Stripes-users mailing list
>
> [2][hidden email]
>
> [3]https://lists.sourceforge.net/lists/listinfo/stripes-users
>
> References
>
> 1. http://p.sf.net/sfu/windows-dev2dev
> 2. mailto:[hidden email]
> 3. https://lists.sourceforge.net/lists/listinfo/stripes-users
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> _______________________________________________
> Stripes-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users