You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jake Vang <va...@googlemail.com> on 2010/11/01 08:37:54 UTC

how to access spring beans from inside a custom validator

i have a custom field validator that extends FieldValidatorSupport.
inside this class, i need to access some beans as defined in
applicationContext.xml by Spring. how do i access the spring managed
beans? any help is appreciated.

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


Re: how to access spring beans from inside a custom validator

Posted by Eduard Neuwirt <ed...@googlemail.com>.
Jake,

does your struts.xml contain the both entries?

<constant name="struts.objectFactory" value="spring" />
<constant name="struts.objectFactory.spring.autoWire" value="type" />

Eduard

Am 01.11.2010 10:50, schrieb Jake Vang:
> Eduard,
>
> I tried that. I thought spring would inject the field, but I keep
> getting a NullPointer (after I get the field and try to use it). Are
> there any other configurations that I need in web.xml? Right now,
> among other things, I have the listener
> org.springframework.web.context.ContextLoaderListener  defined in
> web.xml.
>
> Thanks,
>
> On Mon, Nov 1, 2010 at 4:17 AM, Eduard Neuwirt
> <ed...@googlemail.com>  wrote:
>> Hello Jake,
>>
>> It is simple.
>> Use struts/spring plug in.
>> Declare your bean within your validator and let spring inject your
>> validator.
>>
>> That's all
>>
>> Regards
>> Eduard
>> P.S.: Do not forget to define the corresponding setter method for injection
>>
>> Am 01.11.2010 08:37, schrieb Jake Vang:
>>> i have a custom field validator that extends FieldValidatorSupport.
>>> inside this class, i need to access some beans as defined in
>>> applicationContext.xml by Spring. how do i access the spring managed
>>> beans? any help is appreciated.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

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


Re: how to access spring beans from inside a custom validator

Posted by Jake Vang <va...@googlemail.com>.
Eduard,

I tried that. I thought spring would inject the field, but I keep
getting a NullPointer (after I get the field and try to use it). Are
there any other configurations that I need in web.xml? Right now,
among other things, I have the listener
org.springframework.web.context.ContextLoaderListener  defined in
web.xml.

Thanks,

On Mon, Nov 1, 2010 at 4:17 AM, Eduard Neuwirt
<ed...@googlemail.com> wrote:
> Hello Jake,
>
> It is simple.
> Use struts/spring plug in.
> Declare your bean within your validator and let spring inject your
> validator.
>
> That's all
>
> Regards
> Eduard
> P.S.: Do not forget to define the corresponding setter method for injection
>
> Am 01.11.2010 08:37, schrieb Jake Vang:
>>
>> i have a custom field validator that extends FieldValidatorSupport.
>> inside this class, i need to access some beans as defined in
>> applicationContext.xml by Spring. how do i access the spring managed
>> beans? any help is appreciated.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: how to access spring beans from inside a custom validator

Posted by Eduard Neuwirt <ed...@googlemail.com>.
Hello Jake,

It is simple.
Use struts/spring plug in.
Declare your bean within your validator and let spring inject your 
validator.

That's all

Regards
Eduard
P.S.: Do not forget to define the corresponding setter method for injection

Am 01.11.2010 08:37, schrieb Jake Vang:
> i have a custom field validator that extends FieldValidatorSupport.
> inside this class, i need to access some beans as defined in
> applicationContext.xml by Spring. how do i access the spring managed
> beans? any help is appreciated.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

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