You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Charles Harvey III <ch...@alloy.com> on 2008/05/13 23:34:19 UTC

Re: upgrading

Nathan,
I of course never got around to doing any of this work.  But I checked 
Subversion
and saw that you had been making lots of changes.

So I checked out the code last night and did a build of 2.0-SNAPSHOT, 
dropped it
into my project and lo and behold, it worked!  No changes.  I had my own 
tools
ready for tools-1.4 (which meant taking out the dependency) so 
everything was
ready.

I went from
  spring-1.2.9.jar
  velocity-tools-1.4.jar

to
  spring-2.5.4.jar
  spring-web-2.5.4.jar
  spring-webmvc-2.5.4.jar  (the Spring people broke out more code in the 
new version)
  velocity-tools-2.0-SNAPSHOT.jar

And everything is great.  Great stuff.  Thanks so much for taking the 
time to work
on all of this.


Charlie



Nathan Bubna said the following on 4/17/2008 11:53 PM:
> Hey Charlie,
>
> Any luck getting this to work yet?  Just curious...
>
> thanks,
> nathan
>
> On Tue, Apr 8, 2008 at 3:15 PM, Nathan Bubna <nb...@gmail.com> wrote:
>   
>> On Tue, Apr 8, 2008 at 2:10 PM, Charles Harvey III <ch...@alloy.com> wrote:
>>  > Ok.  I tried and tried and I cannot get the ServletConfig to where I need it
>>  > so
>>  >  I can create a new VelocityView.  The best I can get is a ServletContext.
>>
>>  That is a bummer.  Thank you!  Seriously, this exposes a signficant
>>  shortcoming in the plans to make it easy to integrate Tools into other
>>  frameworks.  It also made me realize that i didn't provide proper
>>  Filter support either.  It needs to be easier to init() a VelocityView
>>  (whether with a ServletConfig, FilterConfig or neither).  I'll try to
>>  set aside some time to fix that this week.  It'll mean we need to do
>>  another beta, i'm sure, but i think it'll be well worth it.
>>
>>
>>  >  ------------------------------------------------------------------
>>  >  VelocityView velocityView = new VelocityView( getServletContext() );
>>  >  Context context = velocityView.getContext( request, response );
>>  >  ------------------------------------------------------------------
>>  >
>>  >  And, looking at the code for VelocityView, when you create a new
>>  > VelocityView
>>  >  with a ServletContext, it never calls the init(ServletConfig config)
>>  > method.
>>  >  So, the tools don't get configured.  When I do $params.get('thing') it
>>  > tells me:
>>  >
>>  >   Request is null. ParameterTool must be initialized first!
>>
>>  Actually, this means the tools did get configured.  This just means
>>  that the tool was never given access to the HttpServletRequest; the
>>  tools aren't being properly initialized.
>>
>>  You could just precede $params.thing with $params.setRequest($request)
>>  to make this work, but obviously that shouldn't be necessary and would
>>  not work for tools who use configure() instead of setters.
>>
>>
>>  >  So, I tried it the "standalone" way:
>>  >  ------------------------------------------------------------------
>>  >  ToolManager manager = new ToolManager();
>>  >  if( getToolboxConfigLocation() != null )
>>  >  {
>>  >    manager.configure( getServletContext().getRealPath(
>>  > getToolboxConfigLocation() ) );
>>  >  }
>>  >  manager.setVelocityEngine( getVelocityEngine() );
>>  >  Context context = manager.createContext();
>>  >  ------------------------------------------------------------------
>>  >
>>  >  And I get the same result.
>>
>>  As expected.  The code above has no knowledge of ServletRequests, so
>>  it would be unable to tell tools about them.
>>
>>
>>  >  One other attempt was made:
>>  >  ------------------------------------------------------------------
>>  >  ViewToolContext context = new ViewToolContext( getVelocityEngine(),
>>  >                                               request, response,
>>  > getServletContext() );
>>  >  ------------------------------------------------------------------
>>  >
>>  >  This time, no errors.  But the tools don't work.  I see a bunch of
>>  > $link.setRelative()
>>  >  all over the page.  Nothing renders.
>>
>>  That's because the ViewToolContext only knows how to find tools.  It
>>  doesn't create them at all.
>>
>>
>>  >
>>  >  Am I close?  Way off?  Any help is much appreciated.
>>  >
>>
>>  Your last example is actually headed in the right direction.
>>  Unfortunately, since you can't use VelocityView until i fix it, it's a
>>  little more complicated.  Here's the gist, though i'll have to leave
>>  you to fill in the blanks for the moment:
>>
>>  the first goal is to create a FactoryConfiguration, then configure a
>>  new ToolboxFactory instance with that config.  this may look something
>>  like this (see VelocityView.configure(ServletConfig, ToolboxFactory)
>>  for a much more involved example):
>>
>>  FactoryConfiguration config = ConfigurationUtils.getAutoLoaded(); //
>>  read javadoc on this!
>>  ToolboxFactory factory = new ToolboxFactory();
>>  factory.configure(config);
>>
>>  keep this factory around for the life of the app.  you only want the
>>  code above to happen once, not on every request!
>>
>>  this once-per-app initialization is also a good place to create your
>>  application-scoped toolbox and put that in the servlet context.  that
>>  code is ripped from VelocityView.init(ServletConfig,ToolboxFactory)
>>  and looks roughly like this:
>>
>>         Toolbox appTools = factory.createToolbox(Scope.APPLICATION);
>>         if (appTools != null &&
>>             servletContext.getAttribute(Toolbox.class.getName()) == null)
>>         {
>>             servletContext.setAttribute(Toolbox.class.getName(), appTools);
>>         }
>>
>>
>>  with that, the application level stuff should be ready to go; now we
>>  just need to prep some things before every request.  so, before you
>>  create that ViewToolContext in your last example above, use your
>>  ToolboxFactory and do the following (this code is ripped from
>>  VelocityView.prepareToolboxes()):
>>
>>         String key = Toolbox.class.getName();
>>         if (factory.hasTools(Scope.REQUEST)
>>             && request.getAttribute(key) == null)
>>         {
>>             // add request toolbox, if any
>>             Toolbox reqTools = factory.createToolbox(Scope.REQUEST);
>>             if (reqTools != null)
>>             {
>>                 request.setAttribute(key, reqTools);
>>             }
>>         }
>>
>>         if (factory.hasTools("session"))
>>         {
>>              HttpSession session = request.getSession(true);
>>               // allow only one thread at a time
>>                synchronized(factory)
>>                 {
>>                     if (session.getAttribute(key) == null)
>>                     {
>>                         Toolbox sessTools =
>>                             factory.createToolbox("session");
>>                         session.setAttribute(key, sessTools);
>>                     }
>>                 }
>>             }
>>
>>
>>  This creates the Toolbox instances for the current session and request
>>  and puts them where the ViewToolContext can find them.  Once all of
>>  the above is done, create your ViewToolContext and return that.
>>
>>  i think that should do the trick.  sorry this is more complicated that
>>  i'd hoped.  i'll try and whip the VelocityView init code into
>>  something more forgiving and get a new beta out.  Thanks for bringing
>>  attention to this deficit. :)
>>
>>
>>
>>  >  Thanks again.
>>  >
>>  >
>>  >
>>  >
>>  >  Charlie
>>  >
>>  >
>>  >  ---------------------------------------------------------------------
>>  >  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>  >  For additional commands, e-mail: user-help@velocity.apache.org
>>  >
>>  >
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>   

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


Re: upgrading

Posted by Nathan Bubna <nb...@gmail.com>.
On Wed, May 14, 2008 at 9:30 AM, Charles Harvey III <ch...@alloy.com> wrote:
> D'oh!  I spoke too soon.  I had Spring pointing at toolbox.xml and not
> tools.xml.

ah.  well, it's still good that you were able to drop in the Tools 2
jar and have things work as they used to, even if no new stuff worked.

>  When I made the change none of the tools were initiated.  I have to go back
> to
>  the classes I had created before to replace the Spring ones:
>
>
>    org.springframework.web.servlet.view.velocity.VelocityView
>     -->> org.springframework.web.servlet.view.velocity.Velocity2View
>
>  Where I replace their createContext() method with one that does not use the
> old
>  ChainedContext with one that uses the new VelocityView.
>
>  I'll let you know how it turns out.

thanks!  things should be easier using the Tools 2 snapshot you built,
since i made it possible to instantiate a VelocityView from filter.
Let me know if/when you have questions.  Obviously, i'm pretty
interested in making Tools 2/framework integration work as smoothly as
possible.

>
>
>  Charlie
>
>
>
>  Nathan Bubna said the following on 5/13/2008 6:25 PM:
>
>
>
> > That's great news!  Thanks for the update.  Hopefully i'll get my act
> > together and push out 2.0-beta2 in the next week.  No promises, of
> > course. :)
> >
> > On Tue, May 13, 2008 at 2:34 PM, Charles Harvey III <ch...@alloy.com>
> wrote:
> >
> >
> > > Nathan,
> > >  I of course never got around to doing any of this work.  But I checked
> > > Subversion
> > >  and saw that you had been making lots of changes.
> > >
> > >  So I checked out the code last night and did a build of 2.0-SNAPSHOT,
> > > dropped it
> > >  into my project and lo and behold, it worked!  No changes.  I had my
> own
> > > tools
> > >  ready for tools-1.4 (which meant taking out the dependency) so
> everything
> > > was
> > >  ready.
> > >
> > >  I went from
> > >  spring-1.2.9.jar
> > >  velocity-tools-1.4.jar
> > >
> > >  to
> > >  spring-2.5.4.jar
> > >  spring-web-2.5.4.jar
> > >  spring-webmvc-2.5.4.jar  (the Spring people broke out more code in the
> new
> > > version)
> > >  velocity-tools-2.0-SNAPSHOT.jar
> > >
> > >  And everything is great.  Great stuff.  Thanks so much for taking the
> time
> > > to work
> > >  on all of this.
> > >
> > >
> > >
> > >  Charlie
> > >
> > >
> > >
> > >  Nathan Bubna said the following on 4/17/2008 11:53 PM:
> > >
> > >
> > >
> > >
> > > > Hey Charlie,
> > > >
> > > > Any luck getting this to work yet?  Just curious...
> > > >
> > > > thanks,
> > > > nathan
> > > >
> > > > On Tue, Apr 8, 2008 at 3:15 PM, Nathan Bubna <nb...@gmail.com> wrote:
> > > >
> > > >
> > > >
> > > >
> > > > > On Tue, Apr 8, 2008 at 2:10 PM, Charles Harvey III
> <ch...@alloy.com>
> > > > >
> > > > >
> > > >
> > > wrote:
> > >
> > >
> > > >
> > > > >  > Ok.  I tried and tried and I cannot get the ServletConfig to
> where I
> > > > >
> > > > >
> > > >
> > > need it
> > >
> > >
> > > >
> > > > >  > so
> > > > >  >  I can create a new VelocityView.  The best I can get is a
> > > > >
> > > > >
> > > >
> > > ServletContext.
> > >
> > >
> > > >
> > > > >  That is a bummer.  Thank you!  Seriously, this exposes a signficant
> > > > >  shortcoming in the plans to make it easy to integrate Tools into
> other
> > > > >  frameworks.  It also made me realize that i didn't provide proper
> > > > >  Filter support either.  It needs to be easier to init() a
> VelocityView
> > > > >  (whether with a ServletConfig, FilterConfig or neither).  I'll try
> to
> > > > >  set aside some time to fix that this week.  It'll mean we need to
> do
> > > > >  another beta, i'm sure, but i think it'll be well worth it.
> > > > >
> > > > >
> > > > >  >
> ------------------------------------------------------------------
> > > > >  >  VelocityView velocityView = new VelocityView(
> getServletContext() );
> > > > >  >  Context context = velocityView.getContext( request, response );
> > > > >  >
> ------------------------------------------------------------------
> > > > >  >
> > > > >  >  And, looking at the code for VelocityView, when you create a new
> > > > >  > VelocityView
> > > > >  >  with a ServletContext, it never calls the init(ServletConfig
> config)
> > > > >  > method.
> > > > >  >  So, the tools don't get configured.  When I do
> $params.get('thing')
> > > > >
> > > > >
> > > >
> > > it
> > >
> > >
> > > >
> > > > >  > tells me:
> > > > >  >
> > > > >  >   Request is null. ParameterTool must be initialized first!
> > > > >
> > > > >  Actually, this means the tools did get configured.  This just means
> > > > >  that the tool was never given access to the HttpServletRequest; the
> > > > >  tools aren't being properly initialized.
> > > > >
> > > > >  You could just precede $params.thing with
> $params.setRequest($request)
> > > > >  to make this work, but obviously that shouldn't be necessary and
> would
> > > > >  not work for tools who use configure() instead of setters.
> > > > >
> > > > >
> > > > >  >  So, I tried it the "standalone" way:
> > > > >  >
> ------------------------------------------------------------------
> > > > >  >  ToolManager manager = new ToolManager();
> > > > >  >  if( getToolboxConfigLocation() != null )
> > > > >  >  {
> > > > >  >    manager.configure( getServletContext().getRealPath(
> > > > >  > getToolboxConfigLocation() ) );
> > > > >  >  }
> > > > >  >  manager.setVelocityEngine( getVelocityEngine() );
> > > > >  >  Context context = manager.createContext();
> > > > >  >
> ------------------------------------------------------------------
> > > > >  >
> > > > >  >  And I get the same result.
> > > > >
> > > > >  As expected.  The code above has no knowledge of ServletRequests,
> so
> > > > >  it would be unable to tell tools about them.
> > > > >
> > > > >
> > > > >  >  One other attempt was made:
> > > > >  >
> ------------------------------------------------------------------
> > > > >  >  ViewToolContext context = new ViewToolContext(
> getVelocityEngine(),
> > > > >  >                                               request, response,
> > > > >  > getServletContext() );
> > > > >  >
> ------------------------------------------------------------------
> > > > >  >
> > > > >  >  This time, no errors.  But the tools don't work.  I see a bunch
> of
> > > > >  > $link.setRelative()
> > > > >  >  all over the page.  Nothing renders.
> > > > >
> > > > >  That's because the ViewToolContext only knows how to find tools.
> It
> > > > >  doesn't create them at all.
> > > > >
> > > > >
> > > > >  >
> > > > >  >  Am I close?  Way off?  Any help is much appreciated.
> > > > >  >
> > > > >
> > > > >  Your last example is actually headed in the right direction.
> > > > >  Unfortunately, since you can't use VelocityView until i fix it,
> it's a
> > > > >  little more complicated.  Here's the gist, though i'll have to
> leave
> > > > >  you to fill in the blanks for the moment:
> > > > >
> > > > >  the first goal is to create a FactoryConfiguration, then configure
> a
> > > > >  new ToolboxFactory instance with that config.  this may look
> something
> > > > >  like this (see VelocityView.configure(ServletConfig,
> ToolboxFactory)
> > > > >  for a much more involved example):
> > > > >
> > > > >  FactoryConfiguration config = ConfigurationUtils.getAutoLoaded();
> //
> > > > >  read javadoc on this!
> > > > >  ToolboxFactory factory = new ToolboxFactory();
> > > > >  factory.configure(config);
> > > > >
> > > > >  keep this factory around for the life of the app.  you only want
> the
> > > > >  code above to happen once, not on every request!
> > > > >
> > > > >  this once-per-app initialization is also a good place to create
> your
> > > > >  application-scoped toolbox and put that in the servlet context.
> that
> > > > >  code is ripped from VelocityView.init(ServletConfig,ToolboxFactory)
> > > > >  and looks roughly like this:
> > > > >
> > > > >       Toolbox appTools = factory.createToolbox(Scope.APPLICATION);
> > > > >       if (appTools != null &&
> > > > >           servletContext.getAttribute(Toolbox.class.getName()) ==
> null)
> > > > >       {
> > > > >           servletContext.setAttribute(Toolbox.class.getName(),
> > > > >
> > > > >
> > > >
> > > appTools);
> > >
> > >
> > > >
> > > > >       }
> > > > >
> > > > >
> > > > >  with that, the application level stuff should be ready to go; now
> we
> > > > >  just need to prep some things before every request.  so, before you
> > > > >  create that ViewToolContext in your last example above, use your
> > > > >  ToolboxFactory and do the following (this code is ripped from
> > > > >  VelocityView.prepareToolboxes()):
> > > > >
> > > > >       String key = Toolbox.class.getName();
> > > > >       if (factory.hasTools(Scope.REQUEST)
> > > > >           && request.getAttribute(key) == null)
> > > > >       {
> > > > >           // add request toolbox, if any
> > > > >           Toolbox reqTools = factory.createToolbox(Scope.REQUEST);
> > > > >           if (reqTools != null)
> > > > >           {
> > > > >               request.setAttribute(key, reqTools);
> > > > >           }
> > > > >       }
> > > > >
> > > > >       if (factory.hasTools("session"))
> > > > >       {
> > > > >            HttpSession session = request.getSession(true);
> > > > >             // allow only one thread at a time
> > > > >              synchronized(factory)
> > > > >               {
> > > > >                   if (session.getAttribute(key) == null)
> > > > >                   {
> > > > >                       Toolbox sessTools =
> > > > >                           factory.createToolbox("session");
> > > > >                       session.setAttribute(key, sessTools);
> > > > >                   }
> > > > >               }
> > > > >           }
> > > > >
> > > > >
> > > > >  This creates the Toolbox instances for the current session and
> request
> > > > >  and puts them where the ViewToolContext can find them.  Once all of
> > > > >  the above is done, create your ViewToolContext and return that.
> > > > >
> > > > >  i think that should do the trick.  sorry this is more complicated
> that
> > > > >  i'd hoped.  i'll try and whip the VelocityView init code into
> > > > >  something more forgiving and get a new beta out.  Thanks for
> bringing
> > > > >  attention to this deficit. :)
> > > > >
> > > > >
> > > > >
> > > > >  >  Thanks again.
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  >  Charlie
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >
> > > > >
> > > >
> > > ---------------------------------------------------------------------
> > >
> > >
> > > >
> > > > >  >  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > > >  >  For additional commands, e-mail: user-help@velocity.apache.org
> > > > >  >
> > > > >  >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > > For additional commands, e-mail: user-help@velocity.apache.org
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >  ---------------------------------------------------------------------
> > >  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > >  For additional commands, e-mail: user-help@velocity.apache.org
> > >
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
> >
> >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>  For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: upgrading

Posted by Charles Harvey III <ch...@alloy.com>.
D'oh!  I spoke too soon.  I had Spring pointing at toolbox.xml and not 
tools.xml.
When I made the change none of the tools were initiated.  I have to go 
back to
the classes I had created before to replace the Spring ones:

    org.springframework.web.servlet.view.velocity.VelocityView
     -->> org.springframework.web.servlet.view.velocity.Velocity2View

Where I replace their createContext() method with one that does not use 
the old
ChainedContext with one that uses the new VelocityView.

I'll let you know how it turns out.


Charlie



Nathan Bubna said the following on 5/13/2008 6:25 PM:
> That's great news!  Thanks for the update.  Hopefully i'll get my act
> together and push out 2.0-beta2 in the next week.  No promises, of
> course. :)
>
> On Tue, May 13, 2008 at 2:34 PM, Charles Harvey III <ch...@alloy.com> wrote:
>   
>> Nathan,
>>  I of course never got around to doing any of this work.  But I checked
>> Subversion
>>  and saw that you had been making lots of changes.
>>
>>  So I checked out the code last night and did a build of 2.0-SNAPSHOT,
>> dropped it
>>  into my project and lo and behold, it worked!  No changes.  I had my own
>> tools
>>  ready for tools-1.4 (which meant taking out the dependency) so everything
>> was
>>  ready.
>>
>>  I went from
>>   spring-1.2.9.jar
>>   velocity-tools-1.4.jar
>>
>>  to
>>   spring-2.5.4.jar
>>   spring-web-2.5.4.jar
>>   spring-webmvc-2.5.4.jar  (the Spring people broke out more code in the new
>> version)
>>   velocity-tools-2.0-SNAPSHOT.jar
>>
>>  And everything is great.  Great stuff.  Thanks so much for taking the time
>> to work
>>  on all of this.
>>
>>
>>
>>  Charlie
>>
>>
>>
>>  Nathan Bubna said the following on 4/17/2008 11:53 PM:
>>
>>
>>     
>>> Hey Charlie,
>>>
>>> Any luck getting this to work yet?  Just curious...
>>>
>>> thanks,
>>> nathan
>>>
>>> On Tue, Apr 8, 2008 at 3:15 PM, Nathan Bubna <nb...@gmail.com> wrote:
>>>
>>>
>>>       
>>>> On Tue, Apr 8, 2008 at 2:10 PM, Charles Harvey III <ch...@alloy.com>
>>>>         
>> wrote:
>>     
>>>>  > Ok.  I tried and tried and I cannot get the ServletConfig to where I
>>>>         
>> need it
>>     
>>>>  > so
>>>>  >  I can create a new VelocityView.  The best I can get is a
>>>>         
>> ServletContext.
>>     
>>>>  That is a bummer.  Thank you!  Seriously, this exposes a signficant
>>>>  shortcoming in the plans to make it easy to integrate Tools into other
>>>>  frameworks.  It also made me realize that i didn't provide proper
>>>>  Filter support either.  It needs to be easier to init() a VelocityView
>>>>  (whether with a ServletConfig, FilterConfig or neither).  I'll try to
>>>>  set aside some time to fix that this week.  It'll mean we need to do
>>>>  another beta, i'm sure, but i think it'll be well worth it.
>>>>
>>>>
>>>>  >  ------------------------------------------------------------------
>>>>  >  VelocityView velocityView = new VelocityView( getServletContext() );
>>>>  >  Context context = velocityView.getContext( request, response );
>>>>  >  ------------------------------------------------------------------
>>>>  >
>>>>  >  And, looking at the code for VelocityView, when you create a new
>>>>  > VelocityView
>>>>  >  with a ServletContext, it never calls the init(ServletConfig config)
>>>>  > method.
>>>>  >  So, the tools don't get configured.  When I do $params.get('thing')
>>>>         
>> it
>>     
>>>>  > tells me:
>>>>  >
>>>>  >   Request is null. ParameterTool must be initialized first!
>>>>
>>>>  Actually, this means the tools did get configured.  This just means
>>>>  that the tool was never given access to the HttpServletRequest; the
>>>>  tools aren't being properly initialized.
>>>>
>>>>  You could just precede $params.thing with $params.setRequest($request)
>>>>  to make this work, but obviously that shouldn't be necessary and would
>>>>  not work for tools who use configure() instead of setters.
>>>>
>>>>
>>>>  >  So, I tried it the "standalone" way:
>>>>  >  ------------------------------------------------------------------
>>>>  >  ToolManager manager = new ToolManager();
>>>>  >  if( getToolboxConfigLocation() != null )
>>>>  >  {
>>>>  >    manager.configure( getServletContext().getRealPath(
>>>>  > getToolboxConfigLocation() ) );
>>>>  >  }
>>>>  >  manager.setVelocityEngine( getVelocityEngine() );
>>>>  >  Context context = manager.createContext();
>>>>  >  ------------------------------------------------------------------
>>>>  >
>>>>  >  And I get the same result.
>>>>
>>>>  As expected.  The code above has no knowledge of ServletRequests, so
>>>>  it would be unable to tell tools about them.
>>>>
>>>>
>>>>  >  One other attempt was made:
>>>>  >  ------------------------------------------------------------------
>>>>  >  ViewToolContext context = new ViewToolContext( getVelocityEngine(),
>>>>  >                                               request, response,
>>>>  > getServletContext() );
>>>>  >  ------------------------------------------------------------------
>>>>  >
>>>>  >  This time, no errors.  But the tools don't work.  I see a bunch of
>>>>  > $link.setRelative()
>>>>  >  all over the page.  Nothing renders.
>>>>
>>>>  That's because the ViewToolContext only knows how to find tools.  It
>>>>  doesn't create them at all.
>>>>
>>>>
>>>>  >
>>>>  >  Am I close?  Way off?  Any help is much appreciated.
>>>>  >
>>>>
>>>>  Your last example is actually headed in the right direction.
>>>>  Unfortunately, since you can't use VelocityView until i fix it, it's a
>>>>  little more complicated.  Here's the gist, though i'll have to leave
>>>>  you to fill in the blanks for the moment:
>>>>
>>>>  the first goal is to create a FactoryConfiguration, then configure a
>>>>  new ToolboxFactory instance with that config.  this may look something
>>>>  like this (see VelocityView.configure(ServletConfig, ToolboxFactory)
>>>>  for a much more involved example):
>>>>
>>>>  FactoryConfiguration config = ConfigurationUtils.getAutoLoaded(); //
>>>>  read javadoc on this!
>>>>  ToolboxFactory factory = new ToolboxFactory();
>>>>  factory.configure(config);
>>>>
>>>>  keep this factory around for the life of the app.  you only want the
>>>>  code above to happen once, not on every request!
>>>>
>>>>  this once-per-app initialization is also a good place to create your
>>>>  application-scoped toolbox and put that in the servlet context.  that
>>>>  code is ripped from VelocityView.init(ServletConfig,ToolboxFactory)
>>>>  and looks roughly like this:
>>>>
>>>>        Toolbox appTools = factory.createToolbox(Scope.APPLICATION);
>>>>        if (appTools != null &&
>>>>            servletContext.getAttribute(Toolbox.class.getName()) == null)
>>>>        {
>>>>            servletContext.setAttribute(Toolbox.class.getName(),
>>>>         
>> appTools);
>>     
>>>>        }
>>>>
>>>>
>>>>  with that, the application level stuff should be ready to go; now we
>>>>  just need to prep some things before every request.  so, before you
>>>>  create that ViewToolContext in your last example above, use your
>>>>  ToolboxFactory and do the following (this code is ripped from
>>>>  VelocityView.prepareToolboxes()):
>>>>
>>>>        String key = Toolbox.class.getName();
>>>>        if (factory.hasTools(Scope.REQUEST)
>>>>            && request.getAttribute(key) == null)
>>>>        {
>>>>            // add request toolbox, if any
>>>>            Toolbox reqTools = factory.createToolbox(Scope.REQUEST);
>>>>            if (reqTools != null)
>>>>            {
>>>>                request.setAttribute(key, reqTools);
>>>>            }
>>>>        }
>>>>
>>>>        if (factory.hasTools("session"))
>>>>        {
>>>>             HttpSession session = request.getSession(true);
>>>>              // allow only one thread at a time
>>>>               synchronized(factory)
>>>>                {
>>>>                    if (session.getAttribute(key) == null)
>>>>                    {
>>>>                        Toolbox sessTools =
>>>>                            factory.createToolbox("session");
>>>>                        session.setAttribute(key, sessTools);
>>>>                    }
>>>>                }
>>>>            }
>>>>
>>>>
>>>>  This creates the Toolbox instances for the current session and request
>>>>  and puts them where the ViewToolContext can find them.  Once all of
>>>>  the above is done, create your ViewToolContext and return that.
>>>>
>>>>  i think that should do the trick.  sorry this is more complicated that
>>>>  i'd hoped.  i'll try and whip the VelocityView init code into
>>>>  something more forgiving and get a new beta out.  Thanks for bringing
>>>>  attention to this deficit. :)
>>>>
>>>>
>>>>
>>>>  >  Thanks again.
>>>>  >
>>>>  >
>>>>  >
>>>>  >
>>>>  >  Charlie
>>>>  >
>>>>  >
>>>>  >
>>>>         
>> ---------------------------------------------------------------------
>>     
>>>>  >  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>>>  >  For additional commands, e-mail: user-help@velocity.apache.org
>>>>  >
>>>>  >
>>>>
>>>>
>>>>
>>>>         
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>>>
>>>
>>>
>>>       
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>  For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>   

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


Re: upgrading

Posted by Nathan Bubna <nb...@gmail.com>.
That's great news!  Thanks for the update.  Hopefully i'll get my act
together and push out 2.0-beta2 in the next week.  No promises, of
course. :)

On Tue, May 13, 2008 at 2:34 PM, Charles Harvey III <ch...@alloy.com> wrote:
> Nathan,
>  I of course never got around to doing any of this work.  But I checked
> Subversion
>  and saw that you had been making lots of changes.
>
>  So I checked out the code last night and did a build of 2.0-SNAPSHOT,
> dropped it
>  into my project and lo and behold, it worked!  No changes.  I had my own
> tools
>  ready for tools-1.4 (which meant taking out the dependency) so everything
> was
>  ready.
>
>  I went from
>   spring-1.2.9.jar
>   velocity-tools-1.4.jar
>
>  to
>   spring-2.5.4.jar
>   spring-web-2.5.4.jar
>   spring-webmvc-2.5.4.jar  (the Spring people broke out more code in the new
> version)
>   velocity-tools-2.0-SNAPSHOT.jar
>
>  And everything is great.  Great stuff.  Thanks so much for taking the time
> to work
>  on all of this.
>
>
>
>  Charlie
>
>
>
>  Nathan Bubna said the following on 4/17/2008 11:53 PM:
>
>
> > Hey Charlie,
> >
> > Any luck getting this to work yet?  Just curious...
> >
> > thanks,
> > nathan
> >
> > On Tue, Apr 8, 2008 at 3:15 PM, Nathan Bubna <nb...@gmail.com> wrote:
> >
> >
> > > On Tue, Apr 8, 2008 at 2:10 PM, Charles Harvey III <ch...@alloy.com>
> wrote:
> > >  > Ok.  I tried and tried and I cannot get the ServletConfig to where I
> need it
> > >  > so
> > >  >  I can create a new VelocityView.  The best I can get is a
> ServletContext.
> > >
> > >  That is a bummer.  Thank you!  Seriously, this exposes a signficant
> > >  shortcoming in the plans to make it easy to integrate Tools into other
> > >  frameworks.  It also made me realize that i didn't provide proper
> > >  Filter support either.  It needs to be easier to init() a VelocityView
> > >  (whether with a ServletConfig, FilterConfig or neither).  I'll try to
> > >  set aside some time to fix that this week.  It'll mean we need to do
> > >  another beta, i'm sure, but i think it'll be well worth it.
> > >
> > >
> > >  >  ------------------------------------------------------------------
> > >  >  VelocityView velocityView = new VelocityView( getServletContext() );
> > >  >  Context context = velocityView.getContext( request, response );
> > >  >  ------------------------------------------------------------------
> > >  >
> > >  >  And, looking at the code for VelocityView, when you create a new
> > >  > VelocityView
> > >  >  with a ServletContext, it never calls the init(ServletConfig config)
> > >  > method.
> > >  >  So, the tools don't get configured.  When I do $params.get('thing')
> it
> > >  > tells me:
> > >  >
> > >  >   Request is null. ParameterTool must be initialized first!
> > >
> > >  Actually, this means the tools did get configured.  This just means
> > >  that the tool was never given access to the HttpServletRequest; the
> > >  tools aren't being properly initialized.
> > >
> > >  You could just precede $params.thing with $params.setRequest($request)
> > >  to make this work, but obviously that shouldn't be necessary and would
> > >  not work for tools who use configure() instead of setters.
> > >
> > >
> > >  >  So, I tried it the "standalone" way:
> > >  >  ------------------------------------------------------------------
> > >  >  ToolManager manager = new ToolManager();
> > >  >  if( getToolboxConfigLocation() != null )
> > >  >  {
> > >  >    manager.configure( getServletContext().getRealPath(
> > >  > getToolboxConfigLocation() ) );
> > >  >  }
> > >  >  manager.setVelocityEngine( getVelocityEngine() );
> > >  >  Context context = manager.createContext();
> > >  >  ------------------------------------------------------------------
> > >  >
> > >  >  And I get the same result.
> > >
> > >  As expected.  The code above has no knowledge of ServletRequests, so
> > >  it would be unable to tell tools about them.
> > >
> > >
> > >  >  One other attempt was made:
> > >  >  ------------------------------------------------------------------
> > >  >  ViewToolContext context = new ViewToolContext( getVelocityEngine(),
> > >  >                                               request, response,
> > >  > getServletContext() );
> > >  >  ------------------------------------------------------------------
> > >  >
> > >  >  This time, no errors.  But the tools don't work.  I see a bunch of
> > >  > $link.setRelative()
> > >  >  all over the page.  Nothing renders.
> > >
> > >  That's because the ViewToolContext only knows how to find tools.  It
> > >  doesn't create them at all.
> > >
> > >
> > >  >
> > >  >  Am I close?  Way off?  Any help is much appreciated.
> > >  >
> > >
> > >  Your last example is actually headed in the right direction.
> > >  Unfortunately, since you can't use VelocityView until i fix it, it's a
> > >  little more complicated.  Here's the gist, though i'll have to leave
> > >  you to fill in the blanks for the moment:
> > >
> > >  the first goal is to create a FactoryConfiguration, then configure a
> > >  new ToolboxFactory instance with that config.  this may look something
> > >  like this (see VelocityView.configure(ServletConfig, ToolboxFactory)
> > >  for a much more involved example):
> > >
> > >  FactoryConfiguration config = ConfigurationUtils.getAutoLoaded(); //
> > >  read javadoc on this!
> > >  ToolboxFactory factory = new ToolboxFactory();
> > >  factory.configure(config);
> > >
> > >  keep this factory around for the life of the app.  you only want the
> > >  code above to happen once, not on every request!
> > >
> > >  this once-per-app initialization is also a good place to create your
> > >  application-scoped toolbox and put that in the servlet context.  that
> > >  code is ripped from VelocityView.init(ServletConfig,ToolboxFactory)
> > >  and looks roughly like this:
> > >
> > >        Toolbox appTools = factory.createToolbox(Scope.APPLICATION);
> > >        if (appTools != null &&
> > >            servletContext.getAttribute(Toolbox.class.getName()) == null)
> > >        {
> > >            servletContext.setAttribute(Toolbox.class.getName(),
> appTools);
> > >        }
> > >
> > >
> > >  with that, the application level stuff should be ready to go; now we
> > >  just need to prep some things before every request.  so, before you
> > >  create that ViewToolContext in your last example above, use your
> > >  ToolboxFactory and do the following (this code is ripped from
> > >  VelocityView.prepareToolboxes()):
> > >
> > >        String key = Toolbox.class.getName();
> > >        if (factory.hasTools(Scope.REQUEST)
> > >            && request.getAttribute(key) == null)
> > >        {
> > >            // add request toolbox, if any
> > >            Toolbox reqTools = factory.createToolbox(Scope.REQUEST);
> > >            if (reqTools != null)
> > >            {
> > >                request.setAttribute(key, reqTools);
> > >            }
> > >        }
> > >
> > >        if (factory.hasTools("session"))
> > >        {
> > >             HttpSession session = request.getSession(true);
> > >              // allow only one thread at a time
> > >               synchronized(factory)
> > >                {
> > >                    if (session.getAttribute(key) == null)
> > >                    {
> > >                        Toolbox sessTools =
> > >                            factory.createToolbox("session");
> > >                        session.setAttribute(key, sessTools);
> > >                    }
> > >                }
> > >            }
> > >
> > >
> > >  This creates the Toolbox instances for the current session and request
> > >  and puts them where the ViewToolContext can find them.  Once all of
> > >  the above is done, create your ViewToolContext and return that.
> > >
> > >  i think that should do the trick.  sorry this is more complicated that
> > >  i'd hoped.  i'll try and whip the VelocityView init code into
> > >  something more forgiving and get a new beta out.  Thanks for bringing
> > >  attention to this deficit. :)
> > >
> > >
> > >
> > >  >  Thanks again.
> > >  >
> > >  >
> > >  >
> > >  >
> > >  >  Charlie
> > >  >
> > >  >
> > >  >
> ---------------------------------------------------------------------
> > >  >  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > >  >  For additional commands, e-mail: user-help@velocity.apache.org
> > >  >
> > >  >
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
> >
> >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>  For additional commands, e-mail: user-help@velocity.apache.org
>
>

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