You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jonathan Asbell <ja...@i-2000.com> on 2001/12/16 15:01:35 UTC

Can someone clarify a basic concept for me ??

Hello.  I am a newbie ;^)

My understanding of Velocity is that I will be creating a subclass of the Velocity servlet for each view.  Is that correct?  If it is, how do I "register" each view?  As multiple servlet mappings in "web.xml" ??  What determines which Velocity servlet I will use?

Can someone please clarify the general workflow in developing.

Thanks
Jonathan

Re: Can someone clarify a basic concept for me ??

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/16/01 10:16 AM, "Jonathan Asbell" <ja...@i-2000.com> wrote:

> can you pass me your interface so I can examine it?
> 

Yup.  Will dig out and send post breakfast...

> 
> ----- Original Message -----
> From: "Geir Magnusson Jr." <ge...@optonline.net>
> To: <ve...@jakarta.apache.org>
> Sent: Sunday, December 16, 2001 9:23 AM
> Subject: Re: Can someone clarify a basic concept for me ??
> 
> 
>> On 12/16/01 9:01 AM, "Jonathan Asbell" <ja...@i-2000.com> wrote:
>> 
>>> Hello.  I am a newbie ;^)
>> 
>> Hello, newbie!  You won't be for long.
>> 
>>> 
>>> My understanding of Velocity is that I will be creating a subclass of
> the
>>> Velocity servlet for each view.  Is that correct?  If it is, how do I
>>> "register" each view?  As multiple servlet mappings in "web.xml" ??
> What
>>> determines which Velocity servlet I will use?
>>> 
>>> Can someone please clarify the general workflow in developing.
>>> 
>> 
>> I'll tell you how I do it and I am sure others will chime in.
>> 
>> No, you generally don't make a subclass for each view, in the template
>> sense, as one servlet can easily handle figuring out which template to
>> render next, and just render it.
>> 
>> It depends on what you are doing, of course, but the model I tend to use
> is
>> a servlet that does the job of the controller - taking the request,
>> examining it, and considering the request and the current application
> state,
>> loads the context with data and renders the template.
>> 
>> Of course, how you do this varies widely.  :)  I would recommend whatever
>> obvious approach comes to mind for now.  Then once you get used to it, you
>> can get fancy.  Also, take a look at the included forum demo in the vel
>> distribution.
>> 
>> For example, I have been using an action model a lot lately, where I  have
> a
>> baseclass that does all the heavy work of managing connection pooling
> (using
>> Poolman), doing the actual render, configuring the Velocity engine, etc,
> and
>> all derived servlets are based on this.
>> 
>> What the baseclass does is decide what the value of the action verb is (I
>> either choose some format of the URI or a form variable) and then call a
>> method by that name (I use the reflection API, but you don't have to).
>> 
>> Then, the method that handles that action does the work, loads the
> context,
>> and returns a template name for the baseclass to render.
>> 
>> So when I want a new webapp, or another servlet in an existing webapp, I
>> just extend this baseclass, and write action methods.  I can always just
>> getConnection() to get a DB connection, and don¹t' have to worry about
>> configuration or other request processing mechanicals.  I just respond to
>> 'events'.
>> 
>> As for mapping in web.xml, a lot of this depends on your design.  If you
>> have some kind of action shorthand, like things like Struts or Turbine do,
>> then you map your action format to your servlet
>> 
>>   <servlet-mapping>
>>     <servlet-name>action</servlet-name>
>>     <url-pattern>*.do</url-pattern>
>>   </servlet-mapping>
>> 
>>   <servlet-mapping>
>>     <servlet-name>velocity</servlet-name>
>>     <url-pattern>*.vm</url-pattern>
>>   </servlet-mapping>
>> 
>> I have mapped *.html to velocity servlets as well, letting the user think
>> that they are working with HTML - of course it was dynamically generated
>> Velocity...
>> 
>> geir
>> 
>> 
>> --
>> Geir Magnusson Jr.                                     geirm@optonline.net
>> System and Software Consulting
>> "They that can give up essential liberty to obtain a little temporary
> safety
>> deserve neither liberty nor safety." - Benjamin Franklin
>> 
>> 
>> 
>> --
>> 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>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



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


Re: Can someone clarify a basic concept for me ??

Posted by Jonathan Asbell <ja...@i-2000.com>.
can you pass me your interface so I can examine it?


----- Original Message -----
From: "Geir Magnusson Jr." <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Sunday, December 16, 2001 9:23 AM
Subject: Re: Can someone clarify a basic concept for me ??


> On 12/16/01 9:01 AM, "Jonathan Asbell" <ja...@i-2000.com> wrote:
>
> > Hello.  I am a newbie ;^)
>
> Hello, newbie!  You won't be for long.
>
> >
> > My understanding of Velocity is that I will be creating a subclass of
the
> > Velocity servlet for each view.  Is that correct?  If it is, how do I
> > "register" each view?  As multiple servlet mappings in "web.xml" ??
What
> > determines which Velocity servlet I will use?
> >
> > Can someone please clarify the general workflow in developing.
> >
>
> I'll tell you how I do it and I am sure others will chime in.
>
> No, you generally don't make a subclass for each view, in the template
> sense, as one servlet can easily handle figuring out which template to
> render next, and just render it.
>
> It depends on what you are doing, of course, but the model I tend to use
is
> a servlet that does the job of the controller - taking the request,
> examining it, and considering the request and the current application
state,
> loads the context with data and renders the template.
>
> Of course, how you do this varies widely.  :)  I would recommend whatever
> obvious approach comes to mind for now.  Then once you get used to it, you
> can get fancy.  Also, take a look at the included forum demo in the vel
> distribution.
>
> For example, I have been using an action model a lot lately, where I  have
a
> baseclass that does all the heavy work of managing connection pooling
(using
> Poolman), doing the actual render, configuring the Velocity engine, etc,
and
> all derived servlets are based on this.
>
> What the baseclass does is decide what the value of the action verb is (I
> either choose some format of the URI or a form variable) and then call a
> method by that name (I use the reflection API, but you don't have to).
>
> Then, the method that handles that action does the work, loads the
context,
> and returns a template name for the baseclass to render.
>
> So when I want a new webapp, or another servlet in an existing webapp, I
> just extend this baseclass, and write action methods.  I can always just
> getConnection() to get a DB connection, and don¹t' have to worry about
> configuration or other request processing mechanicals.  I just respond to
> 'events'.
>
> As for mapping in web.xml, a lot of this depends on your design.  If you
> have some kind of action shorthand, like things like Struts or Turbine do,
> then you map your action format to your servlet
>
>   <servlet-mapping>
>     <servlet-name>action</servlet-name>
>     <url-pattern>*.do</url-pattern>
>   </servlet-mapping>
>
>   <servlet-mapping>
>     <servlet-name>velocity</servlet-name>
>     <url-pattern>*.vm</url-pattern>
>   </servlet-mapping>
>
> I have mapped *.html to velocity servlets as well, letting the user think
> that they are working with HTML - of course it was dynamically generated
> Velocity...
>
> geir
>
>
> --
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> "They that can give up essential liberty to obtain a little temporary
safety
> deserve neither liberty nor safety." - Benjamin Franklin
>
>
>
> --
> 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: Can someone clarify a basic concept for me ??

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/16/01 9:01 AM, "Jonathan Asbell" <ja...@i-2000.com> wrote:

> Hello.  I am a newbie ;^)

Hello, newbie!  You won't be for long.

> 
> My understanding of Velocity is that I will be creating a subclass of the
> Velocity servlet for each view.  Is that correct?  If it is, how do I
> "register" each view?  As multiple servlet mappings in "web.xml" ??  What
> determines which Velocity servlet I will use?
> 
> Can someone please clarify the general workflow in developing.
> 

I'll tell you how I do it and I am sure others will chime in.

No, you generally don't make a subclass for each view, in the template
sense, as one servlet can easily handle figuring out which template to
render next, and just render it.

It depends on what you are doing, of course, but the model I tend to use is
a servlet that does the job of the controller - taking the request,
examining it, and considering the request and the current application state,
loads the context with data and renders the template.

Of course, how you do this varies widely.  :)  I would recommend whatever
obvious approach comes to mind for now.  Then once you get used to it, you
can get fancy.  Also, take a look at the included forum demo in the vel
distribution.

For example, I have been using an action model a lot lately, where I  have a
baseclass that does all the heavy work of managing connection pooling (using
Poolman), doing the actual render, configuring the Velocity engine, etc, and
all derived servlets are based on this.
 
What the baseclass does is decide what the value of the action verb is (I
either choose some format of the URI or a form variable) and then call a
method by that name (I use the reflection API, but you don't have to).

Then, the method that handles that action does the work, loads the context,
and returns a template name for the baseclass to render.

So when I want a new webapp, or another servlet in an existing webapp, I
just extend this baseclass, and write action methods.  I can always just
getConnection() to get a DB connection, and don¹t' have to worry about
configuration or other request processing mechanicals.  I just respond to
'events'.

As for mapping in web.xml, a lot of this depends on your design.  If you
have some kind of action shorthand, like things like Struts or Turbine do,
then you map your action format to your servlet

  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>velocity</servlet-name>
    <url-pattern>*.vm</url-pattern>
  </servlet-mapping>

I have mapped *.html to velocity servlets as well, letting the user think
that they are working with HTML - of course it was dynamically generated
Velocity...

geir


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



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