You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Slava Zimine <sl...@japgod.mine.nu> on 2002/03/21 19:03:24 UTC

VelocityContext quick question

Hi, 

I have a probably naive question, and general servlet related  but just to make sure. 


velo VelocityContext javadoc
<<
  This context implementation cannot be shared between threads
  without those threads synchronizing access between them,
>>

In the ControllerServlet.class & action/commands*.class  can I put
objects in the Context and share them between  all action commands? 

Real need: in processing a given form's parameters, i wish to put possible
error messages in the context  and if necessary  recall a command which
generates that form with error messages pulled from a context and print
them at the top of the form. 


Or should I put those error messages in the HttpSession object ? 


One webuser request  cannot  access the VelocityContext from another
webuser request   because  those are in different threads. 
Correct ? 


Thank you.
slava
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: VelocityContext quick question

Posted by Anthony Eden <ae...@signaturedomains.com>.
If you are interested in a form validation solution alone then you might
be interested in FormProc (http://www.formproc.org/).  It provides
server-side form validation using regular expressions, BSF-supported
scripting languages, Java classes, etc.  It also provides features like
auto-population of target objects and data type conversion.  Finally, it
already works with JPublish, an open source web application framework,
and I believe that someone is working on supporting it in WebWork.

Sincerely,
Anthony Eden

> -----Original Message-----
> From: Slava Zimine [mailto:slava@japgod.mine.nu] 
> Sent: Friday, March 22, 2002 11:36 AM
> To: Velocity Users List
> Subject: Re: VelocityContext quick question
> 
> 
> Geir, thanx for the response and your general willingness to 
> reply just on every question on velocity-user mailing list. 
> 
> I asked the previous question  faced with the problem of a 
> form data validation & thinking how to do it. 
> 
> May I ask if you are aware of  form data validation solutions 
> examples using purely the velocity code, 
> 
> or would you suggest to use other velocity-friendly  
> frameworks  like WebWork  advirtized on this mailing list? 
> 
> I've looked throught the documentation of webwork. 
> looks nice, but its again new learning.  Yet i'm faced with 
> deadlines to develop a working website.. 
> 
> 
> Regards  & many thanx 
> 
> Slava
>  
> 
> 
> On Thu, Mar 21, 2002 at 01:49:00PM -0500, Geir Magnusson Jr. wrote:
> > On 3/21/02 1:03 PM, "Slava Zimine" <sl...@japgod.mine.nu> wrote:
> > 
> > > Hi,
> > > 
> > > I have a probably naive question, and general servlet 
> related  but 
> > > just to make sure.
> > > 
> > > 
> > > velo VelocityContext javadoc
> > > <<
> > > This context implementation cannot be shared between 
> threads without 
> > > those threads synchronizing access between them,
> > >>> 
> > > 
> > > In the ControllerServlet.class & action/commands*.class  
> can I put 
> > > objects in the Context and share them between  all action 
> commands?
> > 
> > Only of those objects are threadsafe - multiple requests 
> will result 
> > in simultaneous threads executing the servlet code, so you 
> have to be 
> > careful.
> > 
> > So if you have some objects that you share between all commands, if 
> > they are not threadsafe (for example, if they have state associated 
> > with them...) then you have to either pool them and reuse for each 
> > request, or just make a new one for each.
> > 
> > If it is something that is just read-only resources that don't have 
> > state, you should be fine.
> > 
> > > 
> > > Real need: in processing a given form's parameters, i wish to put 
> > > possible error messages in the context  and if necessary  
> recall a 
> > > command which generates that form with error messages 
> pulled from a 
> > > context and print them at the top of the form.
> > > 
> > > 
> > > Or should I put those error messages in the HttpSession object ?
> > 
> > If they are just the library of error messages to read and 
> render into 
> > the output, you should be fine.
> > > 
> > > One webuser request  cannot  access the VelocityContext 
> from another
> > > webuser request   because  those are in different threads.
> > > Correct ?
> > 
> > I have to be careful on how this is answered.  If you are asking if 
> > you should allow access :
> > 
> > You cannot safely share a VelocityContext across threads.
> > 
> > 
> > Is it possible? Yes, but would be a mistake.
> > 
> > However - you can take a set of objects (read only data or static 
> > objects) and put them in multiple Velocity contexts, and 
> that will be 
> > fine, as long as you don't modify those objects.
> > 
> > I hope this is clear.  If not, ask again.
> > 
> > geir
> > 
> > > 
> > > 
> > > Thank you.
> > > slava
> > > 
> > > 
> > > --
> > > To unsubscribe, e-mail: 
> > > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail: 
> > > <ma...@jakarta.apache.org>
> > > 
> > 
> > -- 
> > Geir Magnusson Jr.                                     
> geirm@optonline.net
> > System and Software Consulting
> > "We will be judged not by the monuments we build, but by 
> the monuments 
> > we destroy" - Ada Louise Huxtable
> > 
> > 
> > --
> > To unsubscribe, e-mail:   
> <mailto:velocity-user-> unsubscribe@jakarta.apache.org>
> > For 
> additional commands, 
> e-mail: 
> > <ma...@jakarta.apache.org>
> > 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:velocity-user-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: VelocityContext quick question

Posted by Slava Zimine <sl...@japgod.mine.nu>.
Geir, thanx for the response and your general willingness to reply just
on every question on velocity-user mailing list. 

I asked the previous question  faced with the problem of a form data
validation & thinking how to do it. 

May I ask if you are aware of  form data validation solutions examples using
purely the velocity code, 

or would you suggest to use other velocity-friendly  frameworks  like
WebWork  advirtized on this mailing list? 

I've looked throught the documentation of webwork. 
looks nice, but its again new learning.  Yet i'm faced with deadlines
to develop a working website.. 


Regards  & many thanx 

Slava
 


On Thu, Mar 21, 2002 at 01:49:00PM -0500, Geir Magnusson Jr. wrote:
> On 3/21/02 1:03 PM, "Slava Zimine" <sl...@japgod.mine.nu> wrote:
> 
> > Hi, 
> > 
> > I have a probably naive question, and general servlet related  but just to
> > make sure. 
> > 
> > 
> > velo VelocityContext javadoc
> > <<
> > This context implementation cannot be shared between threads
> > without those threads synchronizing access between them,
> >>> 
> > 
> > In the ControllerServlet.class & action/commands*.class  can I put
> > objects in the Context and share them between  all action commands?
> 
> Only of those objects are threadsafe - multiple requests will result in
> simultaneous threads executing the servlet code, so you have to be careful.
> 
> So if you have some objects that you share between all commands, if they are
> not threadsafe (for example, if they have state associated with them...)
> then you have to either pool them and reuse for each request, or just make a
> new one for each.
> 
> If it is something that is just read-only resources that don't have state,
> you should be fine.
> 
> > 
> > Real need: in processing a given form's parameters, i wish to put possible
> > error messages in the context  and if necessary  recall a command which
> > generates that form with error messages pulled from a context and print
> > them at the top of the form.
> > 
> > 
> > Or should I put those error messages in the HttpSession object ?
> 
> If they are just the library of error messages to read and render into the
> output, you should be fine.
> > 
> > One webuser request  cannot  access the VelocityContext from another
> > webuser request   because  those are in different threads.
> > Correct ? 
> 
> I have to be careful on how this is answered.  If you are asking if you
> should allow access :
> 
> You cannot safely share a VelocityContext across threads.
> 
> 
> Is it possible? Yes, but would be a mistake.
> 
> However - you can take a set of objects (read only data or static objects)
> and put them in multiple Velocity contexts, and that will be fine, as long
> as you don't modify those objects.
> 
> I hope this is clear.  If not, ask again.
> 
> geir
> 
> > 
> > 
> > Thank you.
> > slava
> > 
> > 
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > 
> 
> -- 
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> "We will be judged not by the monuments we build, but by the monuments we
> destroy" - Ada Louise Huxtable
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: VelocityContext quick question

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 3/21/02 1:03 PM, "Slava Zimine" <sl...@japgod.mine.nu> wrote:

> Hi, 
> 
> I have a probably naive question, and general servlet related  but just to
> make sure. 
> 
> 
> velo VelocityContext javadoc
> <<
> This context implementation cannot be shared between threads
> without those threads synchronizing access between them,
>>> 
> 
> In the ControllerServlet.class & action/commands*.class  can I put
> objects in the Context and share them between  all action commands?

Only of those objects are threadsafe - multiple requests will result in
simultaneous threads executing the servlet code, so you have to be careful.

So if you have some objects that you share between all commands, if they are
not threadsafe (for example, if they have state associated with them...)
then you have to either pool them and reuse for each request, or just make a
new one for each.

If it is something that is just read-only resources that don't have state,
you should be fine.

> 
> Real need: in processing a given form's parameters, i wish to put possible
> error messages in the context  and if necessary  recall a command which
> generates that form with error messages pulled from a context and print
> them at the top of the form.
> 
> 
> Or should I put those error messages in the HttpSession object ?

If they are just the library of error messages to read and render into the
output, you should be fine.
> 
> One webuser request  cannot  access the VelocityContext from another
> webuser request   because  those are in different threads.
> Correct ? 

I have to be careful on how this is answered.  If you are asking if you
should allow access :

You cannot safely share a VelocityContext across threads.


Is it possible? Yes, but would be a mistake.

However - you can take a set of objects (read only data or static objects)
and put them in multiple Velocity contexts, and that will be fine, as long
as you don't modify those objects.

I hope this is clear.  If not, ask again.

geir

> 
> 
> Thank you.
> slava
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"We will be judged not by the monuments we build, but by the monuments we
destroy" - Ada Louise Huxtable


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>