You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by nani2ratna <na...@gmail.com> on 2010/01/26 14:22:09 UTC

Struts2 Validation with Spring convention plugin

Hi,

I am using struts2, spring with spring convention plugin.
SO all my action classes has been specified in application-Context.xml.
One of my action class got Bean as a property. So I can dealt with the bean
properties in JSP.

The problem, when I am working with my validation i am getting Error
messages repeated problem.
Solution for this one is change scope to prototype.

Now I got another problem, I got a list box in jsp page. If validation fails
I am getting the following error.
could not be resolved as a collection/array/map/enumeration/iterator type

This is happening because, list in Javabean becoming null when validation
fails. 

Then i changed scope="request". And i have added cglib.jar.
Now i am getting following error. 

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'scopedTarget.pmaction': Scope 'request' is not active for the
current thread; consider defining a scoped proxy for this bean if you intend
to refer to it from a singleton; nested exception is
java.lang.IllegalStateException: No thread-bound request found: Are you
referring to request attributes outside of an actual web request, or
processing a request outside of the originally receiving thread? If you are
actually operating within a web request and still receive this message, your
code is probably running outside of DispatcherServlet/DispatcherPortlet: In
this case, use RequestContextListener or RequestContextFilter to expose the
current request.


So if you have list box in jsp page and need to do validation on that jsp
page. ANd you configured all your action classes in Spring appContext file.
You wont succeed. 

Is that correct. Or is there any solution.

Thanks and Regards
RS
-- 
View this message in context: http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27322517.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 Validation with Spring convention plugin

Posted by nani2ratna <na...@gmail.com>.
Hi,

I assume, since it doesn't call any action class if validation fails,
stack got only values from jsp which are already populated into bean
properties when we submit before valdiation.
Since bean is not in session, it should not have any values.
But we have already submitted the form so thats why we have got
non-list(text field) values.

ABove works if scope = "prototype".
If scope="singleton", it works different.
It doesnt make list null. But the error messages will be in stack. if you
submit the form again and validation fails, it will show the error messages
repeatedly.

Hope this helps.

Thanks and regards
RS




nani2ratna wrote:
> 
> Flow in my project works like this.
> When user request one web page, action method searchPm will execute.
> This calls populatePm method in service call.
> Then it will call some dao methods.
> I have JavaBean as a property in action class. This java bean get
> populated in service(dao) and return from the service class to action
> class.
> The same JavaBean got the List property which is populated in service
> class.
> 
> The above is my flow.
> 
> But I have another doubt. I think I didn't understand struts properly.
> If validation fails, does it calls the action method or just execute
> method.
> I think it shouldn't call any of those, because while editing the form
> assume you have changed some form values.
> And submit the form but validation fails and you will see the same form
> with error messages and changed values as well not the old values.
> 
> Is that right.
> Correct me if i am wrong.
> 
> Thanks and Regards
> rs.
> 
> 
> 
> Brian Thompson-5 wrote:
>> 
>> I'm guessing that you have something like
>> 
>> this.myList = populateList();
>> 
>> inside your execute() method.  When validation fails, it just sends you
>> back
>> to the jsp without redoing execute(), so of course the list will be null.
>> 
>> -Brian
>> 
>> 
>> 
>> On Tue, Jan 26, 2010 at 10:26 AM, nani2ratna <na...@gmail.com>
>> wrote:
>> 
>>>
>>> Hi Brian,
>>> I have seen that interface.
>>> If I got more than one action method in one action class.
>>> Then when ever you execute/call method(action) in that action class,
>>> this prepare method will be called and this setting of list will be
>>> executed.
>>>
>>> But My main question why the list setting to null value.
>>> Isn't it a big, can't we fix it.
>>>
>>> And in my company i fought with everybody to bring struts2 into project.
>>> And now i don't have any answer to this, untill any guys help me.
>>>
>>> Thanks
>>> RS
>>>
>>>
>>>
>>> Brian Thompson-5 wrote:
>>> >
>>> > You might look into using the Preparable interface [1].  It's useful
>>> for
>>> > these types of situations; just add the code to generate the list into
>>> a
>>> > prepare() method on your action class instead of in execute().
>>> >
>>> > Hope this helps,
>>> >
>>> > -Brian
>>> >
>>> > [1] -
>>> >
>>> http://www.opensymphony.com/xwork/api/com/opensymphony/xwork2/Preparable.html
>>> >
>>> >
>>> >
>>> > On Tue, Jan 26, 2010 at 7:22 AM, nani2ratna <na...@gmail.com>
>>> wrote:
>>> >
>>> >>
>>> >> Hi,
>>> >>
>>> >> I am using struts2, spring with spring convention plugin.
>>> >> SO all my action classes has been specified in
>>> application-Context.xml.
>>> >> One of my action class got Bean as a property. So I can dealt with
>>> the
>>> >> bean
>>> >> properties in JSP.
>>> >>
>>> >> The problem, when I am working with my validation i am getting Error
>>> >> messages repeated problem.
>>> >> Solution for this one is change scope to prototype.
>>> >>
>>> >> Now I got another problem, I got a list box in jsp page. If
>>> validation
>>> >> fails
>>> >> I am getting the following error.
>>> >> could not be resolved as a collection/array/map/enumeration/iterator
>>> type
>>> >>
>>> >> This is happening because, list in Javabean becoming null when
>>> validation
>>> >> fails.
>>> >>
>>> >> Then i changed scope="request". And i have added cglib.jar.
>>> >> Now i am getting following error.
>>> >>
>>> >> org.springframework.beans.factory.BeanCreationException: Error
>>> creating
>>> >> bean
>>> >> with name 'scopedTarget.pmaction': Scope 'request' is not active for
>>> the
>>> >> current thread; consider defining a scoped proxy for this bean if you
>>> >> intend
>>> >> to refer to it from a singleton; nested exception is
>>> >> java.lang.IllegalStateException: No thread-bound request found: Are
>>> you
>>> >> referring to request attributes outside of an actual web request, or
>>> >> processing a request outside of the originally receiving thread? If
>>> you
>>> >> are
>>> >> actually operating within a web request and still receive this
>>> message,
>>> >> your
>>> >> code is probably running outside of
>>> DispatcherServlet/DispatcherPortlet:
>>> >> In
>>> >> this case, use RequestContextListener or RequestContextFilter to
>>> expose
>>> >> the
>>> >> current request.
>>> >>
>>> >>
>>> >> So if you have list box in jsp page and need to do validation on that
>>> jsp
>>> >> page. ANd you configured all your action classes in Spring appContext
>>> >> file.
>>> >> You wont succeed.
>>> >>
>>> >> Is that correct. Or is there any solution.
>>> >>
>>> >> Thanks and Regards
>>> >> RS
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27322517.html
>>> >> Sent from the Struts - User mailing list archive at Nabble.com.
>>> >>
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> >> For additional commands, e-mail: user-help@struts.apache.org
>>> >>
>>> >>
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27325427.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27326468.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 Validation with Spring convention plugin

Posted by nani2ratna <na...@gmail.com>.
Flow in my project works like this.
When user request one web page, action method searchPm will execute.
This calls populatePm method in service call.
Then it will call some dao methods.
I have JavaBean as a property in action class. This java bean get populated
in service(dao) and return from the service class to action class.
The same JavaBean got the List property which is populated in service class.

The above is my flow.

But I have another doubt. I think I didn't understand struts properly.
If validation fails, does it calls the action method or just execute method.
I think it shouldn't call any of those, because while editing the form
assume you have changed some form values.
And submit the form but validation fails and you will see the same form with
error messages and changed values as well not the old values.

Is that right.
Correct me if i am wrong.

Thanks and Regards
rs.



Brian Thompson-5 wrote:
> 
> I'm guessing that you have something like
> 
> this.myList = populateList();
> 
> inside your execute() method.  When validation fails, it just sends you
> back
> to the jsp without redoing execute(), so of course the list will be null.
> 
> -Brian
> 
> 
> 
> On Tue, Jan 26, 2010 at 10:26 AM, nani2ratna <na...@gmail.com> wrote:
> 
>>
>> Hi Brian,
>> I have seen that interface.
>> If I got more than one action method in one action class.
>> Then when ever you execute/call method(action) in that action class,
>> this prepare method will be called and this setting of list will be
>> executed.
>>
>> But My main question why the list setting to null value.
>> Isn't it a big, can't we fix it.
>>
>> And in my company i fought with everybody to bring struts2 into project.
>> And now i don't have any answer to this, untill any guys help me.
>>
>> Thanks
>> RS
>>
>>
>>
>> Brian Thompson-5 wrote:
>> >
>> > You might look into using the Preparable interface [1].  It's useful
>> for
>> > these types of situations; just add the code to generate the list into
>> a
>> > prepare() method on your action class instead of in execute().
>> >
>> > Hope this helps,
>> >
>> > -Brian
>> >
>> > [1] -
>> >
>> http://www.opensymphony.com/xwork/api/com/opensymphony/xwork2/Preparable.html
>> >
>> >
>> >
>> > On Tue, Jan 26, 2010 at 7:22 AM, nani2ratna <na...@gmail.com>
>> wrote:
>> >
>> >>
>> >> Hi,
>> >>
>> >> I am using struts2, spring with spring convention plugin.
>> >> SO all my action classes has been specified in
>> application-Context.xml.
>> >> One of my action class got Bean as a property. So I can dealt with the
>> >> bean
>> >> properties in JSP.
>> >>
>> >> The problem, when I am working with my validation i am getting Error
>> >> messages repeated problem.
>> >> Solution for this one is change scope to prototype.
>> >>
>> >> Now I got another problem, I got a list box in jsp page. If validation
>> >> fails
>> >> I am getting the following error.
>> >> could not be resolved as a collection/array/map/enumeration/iterator
>> type
>> >>
>> >> This is happening because, list in Javabean becoming null when
>> validation
>> >> fails.
>> >>
>> >> Then i changed scope="request". And i have added cglib.jar.
>> >> Now i am getting following error.
>> >>
>> >> org.springframework.beans.factory.BeanCreationException: Error
>> creating
>> >> bean
>> >> with name 'scopedTarget.pmaction': Scope 'request' is not active for
>> the
>> >> current thread; consider defining a scoped proxy for this bean if you
>> >> intend
>> >> to refer to it from a singleton; nested exception is
>> >> java.lang.IllegalStateException: No thread-bound request found: Are
>> you
>> >> referring to request attributes outside of an actual web request, or
>> >> processing a request outside of the originally receiving thread? If
>> you
>> >> are
>> >> actually operating within a web request and still receive this
>> message,
>> >> your
>> >> code is probably running outside of
>> DispatcherServlet/DispatcherPortlet:
>> >> In
>> >> this case, use RequestContextListener or RequestContextFilter to
>> expose
>> >> the
>> >> current request.
>> >>
>> >>
>> >> So if you have list box in jsp page and need to do validation on that
>> jsp
>> >> page. ANd you configured all your action classes in Spring appContext
>> >> file.
>> >> You wont succeed.
>> >>
>> >> Is that correct. Or is there any solution.
>> >>
>> >> Thanks and Regards
>> >> RS
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27322517.html
>> >> Sent from the Struts - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27325427.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27326206.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 Validation with Spring convention plugin

Posted by Brian Thompson <el...@gmail.com>.
I'm guessing that you have something like

this.myList = populateList();

inside your execute() method.  When validation fails, it just sends you back
to the jsp without redoing execute(), so of course the list will be null.

-Brian



On Tue, Jan 26, 2010 at 10:26 AM, nani2ratna <na...@gmail.com> wrote:

>
> Hi Brian,
> I have seen that interface.
> If I got more than one action method in one action class.
> Then when ever you execute/call method(action) in that action class,
> this prepare method will be called and this setting of list will be
> executed.
>
> But My main question why the list setting to null value.
> Isn't it a big, can't we fix it.
>
> And in my company i fought with everybody to bring struts2 into project.
> And now i don't have any answer to this, untill any guys help me.
>
> Thanks
> RS
>
>
>
> Brian Thompson-5 wrote:
> >
> > You might look into using the Preparable interface [1].  It's useful for
> > these types of situations; just add the code to generate the list into a
> > prepare() method on your action class instead of in execute().
> >
> > Hope this helps,
> >
> > -Brian
> >
> > [1] -
> >
> http://www.opensymphony.com/xwork/api/com/opensymphony/xwork2/Preparable.html
> >
> >
> >
> > On Tue, Jan 26, 2010 at 7:22 AM, nani2ratna <na...@gmail.com>
> wrote:
> >
> >>
> >> Hi,
> >>
> >> I am using struts2, spring with spring convention plugin.
> >> SO all my action classes has been specified in application-Context.xml.
> >> One of my action class got Bean as a property. So I can dealt with the
> >> bean
> >> properties in JSP.
> >>
> >> The problem, when I am working with my validation i am getting Error
> >> messages repeated problem.
> >> Solution for this one is change scope to prototype.
> >>
> >> Now I got another problem, I got a list box in jsp page. If validation
> >> fails
> >> I am getting the following error.
> >> could not be resolved as a collection/array/map/enumeration/iterator
> type
> >>
> >> This is happening because, list in Javabean becoming null when
> validation
> >> fails.
> >>
> >> Then i changed scope="request". And i have added cglib.jar.
> >> Now i am getting following error.
> >>
> >> org.springframework.beans.factory.BeanCreationException: Error creating
> >> bean
> >> with name 'scopedTarget.pmaction': Scope 'request' is not active for the
> >> current thread; consider defining a scoped proxy for this bean if you
> >> intend
> >> to refer to it from a singleton; nested exception is
> >> java.lang.IllegalStateException: No thread-bound request found: Are you
> >> referring to request attributes outside of an actual web request, or
> >> processing a request outside of the originally receiving thread? If you
> >> are
> >> actually operating within a web request and still receive this message,
> >> your
> >> code is probably running outside of DispatcherServlet/DispatcherPortlet:
> >> In
> >> this case, use RequestContextListener or RequestContextFilter to expose
> >> the
> >> current request.
> >>
> >>
> >> So if you have list box in jsp page and need to do validation on that
> jsp
> >> page. ANd you configured all your action classes in Spring appContext
> >> file.
> >> You wont succeed.
> >>
> >> Is that correct. Or is there any solution.
> >>
> >> Thanks and Regards
> >> RS
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27322517.html
> >> Sent from the Struts - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27325427.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 Validation with Spring convention plugin

Posted by nani2ratna <na...@gmail.com>.
Hi Brian,
I have seen that interface.
If I got more than one action method in one action class.
Then when ever you execute/call method(action) in that action class,
this prepare method will be called and this setting of list will be
executed.

But My main question why the list setting to null value.
Isn't it a big, can't we fix it.

And in my company i fought with everybody to bring struts2 into project.
And now i don't have any answer to this, untill any guys help me.

Thanks
RS



Brian Thompson-5 wrote:
> 
> You might look into using the Preparable interface [1].  It's useful for
> these types of situations; just add the code to generate the list into a
> prepare() method on your action class instead of in execute().
> 
> Hope this helps,
> 
> -Brian
> 
> [1] -
> http://www.opensymphony.com/xwork/api/com/opensymphony/xwork2/Preparable.html
> 
> 
> 
> On Tue, Jan 26, 2010 at 7:22 AM, nani2ratna <na...@gmail.com> wrote:
> 
>>
>> Hi,
>>
>> I am using struts2, spring with spring convention plugin.
>> SO all my action classes has been specified in application-Context.xml.
>> One of my action class got Bean as a property. So I can dealt with the
>> bean
>> properties in JSP.
>>
>> The problem, when I am working with my validation i am getting Error
>> messages repeated problem.
>> Solution for this one is change scope to prototype.
>>
>> Now I got another problem, I got a list box in jsp page. If validation
>> fails
>> I am getting the following error.
>> could not be resolved as a collection/array/map/enumeration/iterator type
>>
>> This is happening because, list in Javabean becoming null when validation
>> fails.
>>
>> Then i changed scope="request". And i have added cglib.jar.
>> Now i am getting following error.
>>
>> org.springframework.beans.factory.BeanCreationException: Error creating
>> bean
>> with name 'scopedTarget.pmaction': Scope 'request' is not active for the
>> current thread; consider defining a scoped proxy for this bean if you
>> intend
>> to refer to it from a singleton; nested exception is
>> java.lang.IllegalStateException: No thread-bound request found: Are you
>> referring to request attributes outside of an actual web request, or
>> processing a request outside of the originally receiving thread? If you
>> are
>> actually operating within a web request and still receive this message,
>> your
>> code is probably running outside of DispatcherServlet/DispatcherPortlet:
>> In
>> this case, use RequestContextListener or RequestContextFilter to expose
>> the
>> current request.
>>
>>
>> So if you have list box in jsp page and need to do validation on that jsp
>> page. ANd you configured all your action classes in Spring appContext
>> file.
>> You wont succeed.
>>
>> Is that correct. Or is there any solution.
>>
>> Thanks and Regards
>> RS
>> --
>> View this message in context:
>> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27322517.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27325427.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 Validation with Spring convention plugin

Posted by Brian Thompson <el...@gmail.com>.
You might look into using the Preparable interface [1].  It's useful for
these types of situations; just add the code to generate the list into a
prepare() method on your action class instead of in execute().

Hope this helps,

-Brian

[1] -
http://www.opensymphony.com/xwork/api/com/opensymphony/xwork2/Preparable.html



On Tue, Jan 26, 2010 at 7:22 AM, nani2ratna <na...@gmail.com> wrote:

>
> Hi,
>
> I am using struts2, spring with spring convention plugin.
> SO all my action classes has been specified in application-Context.xml.
> One of my action class got Bean as a property. So I can dealt with the bean
> properties in JSP.
>
> The problem, when I am working with my validation i am getting Error
> messages repeated problem.
> Solution for this one is change scope to prototype.
>
> Now I got another problem, I got a list box in jsp page. If validation
> fails
> I am getting the following error.
> could not be resolved as a collection/array/map/enumeration/iterator type
>
> This is happening because, list in Javabean becoming null when validation
> fails.
>
> Then i changed scope="request". And i have added cglib.jar.
> Now i am getting following error.
>
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean
> with name 'scopedTarget.pmaction': Scope 'request' is not active for the
> current thread; consider defining a scoped proxy for this bean if you
> intend
> to refer to it from a singleton; nested exception is
> java.lang.IllegalStateException: No thread-bound request found: Are you
> referring to request attributes outside of an actual web request, or
> processing a request outside of the originally receiving thread? If you are
> actually operating within a web request and still receive this message,
> your
> code is probably running outside of DispatcherServlet/DispatcherPortlet: In
> this case, use RequestContextListener or RequestContextFilter to expose the
> current request.
>
>
> So if you have list box in jsp page and need to do validation on that jsp
> page. ANd you configured all your action classes in Spring appContext file.
> You wont succeed.
>
> Is that correct. Or is there any solution.
>
> Thanks and Regards
> RS
> --
> View this message in context:
> http://old.nabble.com/Struts2-Validation-with-Spring-convention-plugin-tp27322517p27322517.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>