You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Shenton <cs...@Outbounder.com> on 2001/07/03 20:31:43 UTC

newbie: What `controller' to use with Velocity `view'?

I'm pretty new to Java, but have been coding other languages for quite
a while.  At work, we've been using WebMacro for the `view' in our MVC
model, with a home-grown `controller' which manages session, access,
etc, under Apache+jserv.

I'd like to move into Velocity for `view' but am befuddled by what
`controller' to use.  Sounds like most Velocity developers are using
Jakarta-tomcat, which I haven't played with yet -- does it function as
a `controller', or is a controller just part of the tomcat framework?
Is it possible to use Velocity with jserv? Other suggestions?

For a Java newbie like me, some of the larger frameworks like what I
believe Struts or Turbine offer would be overkill.  Or maybe I should
just dive into them if they offer a sufficiently sophisticated
environment that I can leverage their facilities.  But at this point
I'm looking for simplicity and a less steep learning curve.
Suggestions welcome.

Thanks.


Re: Anakia and jdom

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> Hi guys,
> 
> another "should i forget programming" question.
> 
> Should not Anakia use dom4j instead of jdom ? Is not
> dom4j vastly superior to jdom, considering that we are
> working with java?

JDOM is the Bee's Knees.
 
I heart JDOM.

<fud>
JDOM is also a JSR, so you might find support in the JDK eventually.
</fud>

I actually know nothing about dom4j.

> 
> consider how to get an XPath engine running in jdom:
> 
> DOMParser parser = new DOMParser();
> parser.parse(DocName);
> Element Site =
> parser.getDocument().getDocumentElement();
> xpathSupport = new XMLParserLiaisonDefault();
> prefixResolver = new PrefixResolverDefault(Site);
> xpath = new XPath();
> XPathparser = new XPathProcessorImpl(xpathSupport);
> XPathparser.initXPath(xpath, PathName,
> prefixResolver);
> 
> and then eval an xpath expression:
> 
> XObject result = xpath.execute(xpathSupport, Site,
> prefixResolver);
> 
> NodeList foundnodes = result.nodeset();
> (...more suffering from not having a standard
> Collection...)
> 
> same thing with dom4j :
> 
> SAXReader reader = new SAXReader();
> Site =  reader.read(DocName);
> List foundnodes = Site.selectNodes(PathName);
> 
> (have a java Collection)

How does this affect you as an Anakia user?


-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: singleton Velocity engine

Posted by Jon Stevens <jo...@latchkey.com>.
One solution for this is to load each instance of Velocity in its own
classloader. That way, within the same ServletContext, you will still have a
unique instance of Velocity. The controller servlet that you use can
differentiate between the different applications within the context by
something like the domain name and you can therefore have a mapping of
something like this:

ie:

ServletContext => root
    classloader1 => app1.domain.com
    classloader2 => app2.domain.com
    classloader3 => app1.foo.com

URI's would look like this:

http://app1.domain.com/root/servlet/ControllerServlet
http://app2.domain.com/root/servlet/ControllerServlet
http://app1.foo.com/root/servlet/ControllerServlet

All of the domains can be mapped to the same Context.

It should be relatively easy to implement this and would solve the problem
right away.

-jon


Re: singleton Velocity engine

Posted by piero de salvia <pi...@yahoo.com>.
I can prepend, but...

the second app would have to be a self-contained one,
originally I thought of writing one of those monster
servlets, the ones with Apache's ECS. 

so given one of my customer's websites, I would just
plop the content manager app in a jar under root, the
rendering app in a jar under root, and voila'.

customer gone? pack her templates  + her content, send
her a CD.

I know the answer is still "you can jar and prepend",
but I suppose it comes down to speed.

Also there is another issue. The velocity engine is
extra extra nice for loading other miscellaneous
stuff, like content, sensing when it changes, getting
it from jars, Anakia-ing it etc. The basis for a
content management system.

I would also like to contribute, but I am not sure
about my Java skills.



--- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> piero de salvia wrote:
> > 
> > Hi Geir,
> > 
> > in reality I did investigate the subject and
> realized
> > I could do that, and I could also prepend/append a
> > string to every template request, indicating a
> > different "application".
> > 
> > reason why i don't want to do that is the apps are
> > really separate. my clients will go to the
> template
> > directory and do their templates directly (like
> with
> > dreamweaver etc.).
> > the other app is a content manager app that takes
> care
> > of content (I know how you guys are fond of MVC so
> I
> > MVC too). If Velocity is singleton, the second
> app's
> > templates will mix up with the customer's
> templates,
> > chances of namespace clashes and so on.
> 
> I guess I would have to see it.  I know some people
> can't work by
> partitioning the templates into different
> directories, one for each app
> for various and sundry reasons.
> 
> However, if the apps are distinct, why can't the
> controller prepend the
> client's directory name for any requests going to
> that client's app?
> 
>  
> > So I hopefully wait. what happens if I un-static
> > everything in source?
> 
> It breaks.  Everything is currently dependant upon
> this.
> 
> -- 
> Geir Magnusson Jr.                          
> geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See
> http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a
> cropper with!


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Re: singleton Velocity engine

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> Hi Geir,
> 
> in reality I did investigate the subject and realized
> I could do that, and I could also prepend/append a
> string to every template request, indicating a
> different "application".
> 
> reason why i don't want to do that is the apps are
> really separate. my clients will go to the template
> directory and do their templates directly (like with
> dreamweaver etc.).
> the other app is a content manager app that takes care
> of content (I know how you guys are fond of MVC so I
> MVC too). If Velocity is singleton, the second app's
> templates will mix up with the customer's templates,
> chances of namespace clashes and so on.

I guess I would have to see it.  I know some people can't work by
partitioning the templates into different directories, one for each app
for various and sundry reasons.

However, if the apps are distinct, why can't the controller prepend the
client's directory name for any requests going to that client's app?

 
> So I hopefully wait. what happens if I un-static
> everything in source?

It breaks.  Everything is currently dependant upon this.

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: singleton Velocity engine

Posted by piero de salvia <pi...@yahoo.com>.
Hi Geir,

in reality I did investigate the subject and realized
I could do that, and I could also prepend/append a
string to every template request, indicating a
different "application".

reason why i don't want to do that is the apps are
really separate. my clients will go to the template
directory and do their templates directly (like with
dreamweaver etc.). 
the other app is a content manager app that takes care
of content (I know how you guys are fond of MVC so I
MVC too). If Velocity is singleton, the second app's
templates will mix up with the customer's templates,
chances of namespace clashes and so on.

So I hopefully wait. what happens if I un-static
everything in source?

piero

--- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> piero de salvia wrote:
> > 
> > Hi guys,
> > 
> > I was trying to set up two controller servlets
> under
> > the same app (i.e. the same web-inf) and, because
> of
> > that, they share the file loader resource path
> (not
> > what I wanted). I understand that it would suffice
> to
> > put them under two different web-inf, but since
> the
> > site is hosted at an ISP, I, as many others, don't
> get
> > the luxury of a separate context. It would be
> really
> > convenient to have a non-singleton Velocity
> engine.
> 
> Yes - we know.  We have been talking about it a
> little as interest comes
> up and down.  I was planning to take a few days soon
> and take a good run
> at it.
> 
> I will note here that you do realize that your file
> loader resource path
> can contain multiple directories, right?  While it
> wouldn't be the
> optimal solution, you could always just have each
> controller prefix each
> template name with a directory name?
> 
> geir
> 
> -- 
> Geir Magnusson Jr.                          
> geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See
> http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a
> cropper with!


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Re: singleton Velocity engine

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> Hi guys,
> 
> I was trying to set up two controller servlets under
> the same app (i.e. the same web-inf) and, because of
> that, they share the file loader resource path (not
> what I wanted). I understand that it would suffice to
> put them under two different web-inf, but since the
> site is hosted at an ISP, I, as many others, don't get
> the luxury of a separate context. It would be really
> convenient to have a non-singleton Velocity engine.

Yes - we know.  We have been talking about it a little as interest comes
up and down.  I was planning to take a few days soon and take a good run
at it.

I will note here that you do realize that your file loader resource path
can contain multiple directories, right?  While it wouldn't be the
optimal solution, you could always just have each controller prefix each
template name with a directory name?

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

singleton Velocity engine

Posted by piero de salvia <pi...@yahoo.com>.
Hi guys,

I was trying to set up two controller servlets under
the same app (i.e. the same web-inf) and, because of
that, they share the file loader resource path (not
what I wanted). I understand that it would suffice to
put them under two different web-inf, but since the
site is hosted at an ISP, I, as many others, don't get
the luxury of a separate context. It would be really
convenient to have a non-singleton Velocity engine.

piero de salvia

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Re: Anakia and jdom

Posted by bob mcwhirter <bo...@werken.com>.
Just for the record, Anakia's use of JDOM uses my werken.xpath
implementation.  Which, incidently, wasn't the example he gave,
I don't think.  Coincidently, dom4j also uses my werken.xpath
under-the-cover.

So, as far as ease-of-use for either JDOM or dom4j, wrt xpath,
it's all about the same.

	-bob

On Tue, 3 Jul 2001, Jon Stevens wrote:

> I work with Jason Hunter and he is a friend of mine. I'm going to use JDOM.
> 
> Feel free to submit another version of Anakia which uses/does whatever the
> heck you want.
> 
> -jon
> 



Re: Anakia and jdom

Posted by Jon Stevens <jo...@latchkey.com>.
I work with Jason Hunter and he is a friend of mine. I'm going to use JDOM.

Feel free to submit another version of Anakia which uses/does whatever the
heck you want.

-jon


Anakia and jdom

Posted by piero de salvia <pi...@yahoo.com>.
Hi guys,

another "should i forget programming" question.

Should not Anakia use dom4j instead of jdom ? Is not
dom4j vastly superior to jdom, considering that we are
working with java?

consider how to get an XPath engine running in jdom:

DOMParser parser = new DOMParser();
parser.parse(DocName);
Element Site =
parser.getDocument().getDocumentElement();
xpathSupport = new XMLParserLiaisonDefault();
prefixResolver = new PrefixResolverDefault(Site);
xpath = new XPath();
XPathparser = new XPathProcessorImpl(xpathSupport);
XPathparser.initXPath(xpath, PathName,
prefixResolver);

and then eval an xpath expression:

XObject result = xpath.execute(xpathSupport, Site,
prefixResolver);

NodeList foundnodes = result.nodeset();
(...more suffering from not having a standard
Collection...)

same thing with dom4j :

SAXReader reader = new SAXReader();
Site =  reader.read(DocName);
List foundnodes = Site.selectNodes(PathName);

(have a java Collection)

bye

piero de salvia

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Re: newbie: What `controller' to use with Velocity `view'?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Chris Shenton wrote:
> 
> I'm pretty new to Java, but have been coding other languages for quite
> a while.  At work, we've been using WebMacro for the `view' in our MVC
> model, with a home-grown `controller' which manages session, access,
> etc, under Apache+jserv.
> 
> I'd like to move into Velocity for `view' but am befuddled by what
> `controller' to use.  Sounds like most Velocity developers are using
> Jakarta-tomcat, which I haven't played with yet -- does it function as
> a `controller', or is a controller just part of the tomcat framework?
> Is it possible to use Velocity with jserv? Other suggestions?

You can think of Tomcat as the follow-on to JServ.  It's the reference
implementation for the Servlet spec, and Tomcat v3.2 covers spec version
2.2.  Tomcat v4 covers the servlet spec 2.3.  Tomcat 4 isn't ready for
production yet.

You should be easily able to port your application from JServ to tomcat,
and use Velocity.

And yes, velocity should work with JServ, if you are careful, although
if you are doing a change like this, you may take advantage of the time
and make the move to Tomcat.  Highly recommended.


> 
> For a Java newbie like me, some of the larger frameworks like what I
> believe Struts or Turbine offer would be overkill.  Or maybe I should
> just dive into them if they offer a sufficiently sophisticated
> environment that I can leverage their facilities.  But at this point
> I'm looking for simplicity and a less steep learning curve.
> Suggestions welcome.

No matter what you choose, I would move forward onto tomcat.

As for frameworks?  Dive in...  take a look.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

newbie: Velocity Ultraedit wordfile sought

Posted by Asteris Masouras <on...@aix.meng.auth.gr>.
Greetings to all,
I'm new to the MVC front, and not a very old hand with Java either, although
I've had some experience with procedural (and early object oriented)
programming and scripting languages.
The consortium for which I work selected the TDK (and, by extension,
Velocity) as the default framework
for developing it's application, so I was forced to change my programming
habits overnight.
The more I apply myself to the MVC mode of thinking, the more I like it, but
it's difficult to tweak'n'test
Velocity templates the old-fashioned way.
My question is this: does anybody know where I can find an Ultraedit
wordfile for Velocity templates?
I'd take a crack at it (if I could find the time!), but wouldn't want to
reinvent the wheel, if it happens to be lying around..

TIA,
-=-
Asteris Masouras
(oneiros@NOSPAM.aix.meng.auth.gr)


Re: newbie: What `controller' to use with Velocity `view'?

Posted by Jon Stevens <jo...@latchkey.com>.
on 7/3/01 11:31 AM, "Chris Shenton" <cs...@Outbounder.com> wrote:

> I'm pretty new to Java, but have been coding other languages for quite
> a while.  At work, we've been using WebMacro for the `view' in our MVC
> model, with a home-grown `controller' which manages session, access,
> etc, under Apache+jserv.
> 
> I'd like to move into Velocity for `view' but am befuddled by what
> `controller' to use.  Sounds like most Velocity developers are using
> Jakarta-tomcat, which I haven't played with yet -- does it function as
> a `controller', or is a controller just part of the tomcat framework?
> Is it possible to use Velocity with jserv? Other suggestions?
> 
> For a Java newbie like me, some of the larger frameworks like what I
> believe Struts or Turbine offer would be overkill.  Or maybe I should
> just dive into them if they offer a sufficiently sophisticated
> environment that I can leverage their facilities.  But at this point
> I'm looking for simplicity and a less steep learning curve.
> Suggestions welcome.
> 
> Thanks.

You are confusing a servlet engine (tomcat) with the controller. The
controller would be something like VelocityServlet or if you want to get
more "advanced", use one of the 4 different (known) webapp frameworks which
are listed on our poweredby page. I'm personally biased towards Turbine, of
course.

Thanks,

-jon