Hello, Scott Farquhar wrote:
(Also available here:
http://jira.opensymphony.com/secure/ViewIssue.jspa?key=WW-111)
I have looked at changing the view tags over to velocity, and it is looking very promising. I have attached the text.vm & text.jsp files for a comparison, and it cleans the code up quite a bit.
Great!
As a first step, all the views can be duplicated in velocity, and then use the VelocityServlet to include them. This will not reduce the overhead of the rd.include() but will reduce the time for the included page to be parsed.The bigger problems is the VS isn't exposed in templates so it should be exposed in some manner. I can think of a couple of ways to do this. In WebWorkVelocityServlet just put the VS into the VelocityContext as "vs", "valuestack", "stack", etc. For example:
I have completed (&committed) this & added a corresponding '.vm' file for most ui tags. You need to change 'webwork.ui.templateSuffix' to 'vm' and you need to map the WebWorkVelocityServlet to '*.vm'. I have tested the examples, but nothing further.
However, when working through this, I came to a few problems:
- Getting the value from the top of the valueStack.
This is usually obtained with a "." or a "null" value passed to stack.findValue(). However, in velocity, all values must start with a character. Are their any other synonyms for the current value that I don't know about? Can we add one?
Index: src/main/webwork/view/velocity/WebWorkVelocityServlet.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/view/velocity/WebWorkVelocityServlet.java,v
retrieving revision 1.4
diff -u -r1.4 WebWorkVelocityServlet.java
--- src/main/webwork/view/velocity/WebWorkVelocityServlet.java 15 Sep 2002 02:02:33 -0000 1.4
+++ src/main/webwork/view/velocity/WebWorkVelocityServlet.java 28 Jan 2003 18:28:09 -0000
@@ -157,6 +157,7 @@
Context ctx = new WebWorkVelocityContext(ServletValueStack.getStack(request));
ctx.put(REQUEST, request);
ctx.put(RESPONSE, response);
+ ctx.put("stack", ServletValueStack.getStack(request));
return ctx;
}
If exposing the VS under $webwork is preferred, another option would be to make WebWorkUtil into a facade for the ValueStack class. Then you would use in your templates: $webwork.findValue(".").
Using WebWorkUtil would also allow creation of helper methods to the VS. For instance,
$webwork.current - calls a getCurrent method returning vs.findValue(".")
$webwork.parent - calls a getParent method returning vs.findValue("..")
- Getting the templates (using servletPath).You really need to check out the Velocity Tools project (http://jakarta.apache.org/velocity/toolsubproject.html). There in as enhanced VelocityViewServlet that uses a Resource Loader (WebappLoader) so templates are loaded via ServletContext.getResourceAsStream rather than relative to getRealPath. This also allows templates being pulled from a .war if the container supports it. See WebappLoader at http://cvs.apache.org/viewcvs/jakarta-velocity-tools/view/src/java/org/apache/velocity/tools/view/servlet/WebappLoader.java?rev=1.1.1.1&content-type=text/vnd.viewcvs-markup and VelocityViewServlet which calls it at http://cvs.apache.org/viewcvs/jakarta-velocity-tools/view/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java?rev=1.6&content-type=text/vnd.viewcvs-markup.
Some servlet containers have problems with getRealPath(). We can always bundle default templates in the jar (a plus), but how do we access the templates? Rickard seems to do it with his WebWorkVelocityServlet - but I'm not sure how.
In the short run, you could use the WebappLoader from within the WebWorkVelocityServlet. Longer term when the Velocity Tools project has a release, it may make sense to base WWVS on VelocityViewServlet so the toolbox stuff will be available.
-Bill
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
