JVC is a tool for creating Java web applications.
Most well designed web applications separate their components into models, views and controllers. JVC creates the view and controller part of your web application (you are free to use any model implementation you like).
JVC is simple and the web applications it creates are fast because the requests are processed by pre-compiled Java code. For even better performance we recommend configuring your web server so that the static content is handled by an Apache server instead of by your JVC app.
Writing a JVC web app is simple because you just write POJO's and you don't need any xml configuration files.
JVC uses standard open source tools like Tomcat, Ant and Log4j.
JVC applications share many similarities with Ruby on Rails applications, but since JVC apps are written in Java many errors can be caught while compiling instead of during runtime.
[[ ... ]] | Java-code-tag | These tags contain Java code which will be executed as part of the page generation process. This code has access to the JVCRequestContext via the variable rc and the companion Controller object via the variable controller. |
[[= ... ]] | Java-expression-tag | These tags contain Java code which evaluates to a String. They have access to the same variables as the Java-code-tags. |
[[== ... ]] | HTML escaped Java-expression-tag | These tags are exactly the same as Java-expression-tags except their output is HTML escaped. |
[[+ ... ]] | Include-tag | These tags contain a path to a file to be included. The included file's name must begin with an underscore character (ie. _myfile.jhtml) to distinguish it from a regular view template. |
[[! ... ]] | Comment-tag | Anything inside of comment-tags is ignored (including other JVC tags). |
And one meta tag pair:
[[begin_cache]] ... [[end_cache]] | Cache-block | Anything inside a cache-block will only be evaluated once, subsequent page requests will use the cached result. |
During the build process view templates get turned into page generators and controllers.
You can look at the page generator source code, but don't modify it (your changes will be overwritten the next time the project is rebuilt). The page generators for the view templates in the view directory become corresponding Java classes located in the src/<package_prefix>/generators/ directory (you specified the package_prefix when you create your project or it defaults to no package, see Hello JVC section). Note: if you build your project with the -Dline.numbers=true command line argument then the each line of the page generator code will contain a comment indicating which part of which template it came from.
All the page controllers corresponding to the view templates in a particular directory extend a 'local' base controller, and all these 'local' base controllers in turn extend a single 'global' base controller. See the Hello JVC section for an example.
The generated controller classes don't do anything other than provide access to the JVCRequestContext, but they give you a place to wire in your web application code while keeping it separate from your views. Page specific code can be added to in the page controllers and common code can be put in the 'local' or 'global' base controllers.
If you look at the source code for a PageGenerator.java class you will see that on the first line of each page generator method the corresponding page controller object is instantiated and stored in the variable controller. This is how your page view and controller can interact.
In the Tomcat server the JVC request dispatcher is a simple servlet.
The only JVC class you, as a developer, really need to know about is the JVCRequestContext. When the request dispatcher receives a request it decides if it is for static or dynamic content. If its for dynamic content then it creates a JVCRequestContext and instantiates the appropriate controller and PageGenerator and passes them the JVCRequestContext.
For more details please see the javadocs
Lets assume you installed JVC in your ~/dev/jvc/ directory then you can create a hello_jvc app by typing:
~/dev/jvc$ ant new_project -Dname=hello_jvc ~/dev/jvc$ cd ../hello_jvc ~/dev/hello_jvc$ ant test # run unit tests (optional) ~/dev/hello_jvc$ $CATALINA_HOME/bin/shutdown.sh -force ~/dev/hello_jvc$ ant install ~/dev/hello_jvc$ $CATALINA_HOME/bin/startup.sh or instead of the last 3 commands you can just type: ~/dev/hello_jvc$ ant rev
At this point you should be able to go to http://localhost:8080/hello_jvc and see
your new web app (assuming your Tomcat server is in its default configuration).
(Note: you may have to start/stop Tomcat and install your app as root if you installed Tomcat as root).
Now lets look at what was created.
hello_jvc/ build.xml conf/ ... dist/ ... docs/ ... lib/ ... src/ Application.java controllers/ BaseController.java docs/ BaseDocsController.java examples/ BaseExamplesController.java FormTestController.java RequestController.java BouncerController.java RedirectController.java TagController.java ... generators/ BaseGenerator.java docs/ examples/ BouncerGenerator.java FormTestGenerator.java RedirectGenerator.java RequestGenerator.java TagGenerator.java ... test/ ... utils/ Helpers.java view/ docs/ examples/ bouncer.jhtml formTest.jhtml redirect.jhtml _request.jhtml request.jhtml tag.jhtml ... shared/ ... static/ ... tests/ ...
Notice how, for example, the tag.jhtml view template spawns the TagGenerator.java page generator and the TagController.java, BaseExamplesController.java and BaseController.java controllers.
Use the -Dpkg.prefix option when creating your application to cause the generated code to be put into your own java package. For example: if you are creating a web app called my_app and want your code to be in the package com.acme then type: ant new_project -Dname=my_app -Dpkg.prefix=com.acme
to test type: java -version
to test type: $CATALINA_HOME/bin/startup.sh and go to http://localhost:8080/ you should see the Tomcat start page.
to test type: ant -version
to test create a 'hello jvc' web app