How It Works?
Vroom Framework can manage anything related to HTML DOM, including Document, Window and Navigator objects. The framework can be used independently or it can be integrated with other Model-2, MVC frameworks. In some aspects, Vroom Framework provides better control of your website e.g. You may want to include Google Analytics JavaScript to your webpages. To do that you probably use one of the following approaches:
- Open every webpage and paste the JavaScript code Or
- Use a separate html/jsp file for JavaScript code and modify every webpage to include the include statement Or
- Use tiles approach if you're using Struts Framework
The first two approaches are quite time consuming; the second approach does not work with HTML pages and in case of third approach, not all applications are built on Struts Framework. Vroom Framework eliminates all this hassle and provides you an easy to use approach to inject such type of scripts by defining webpage element in vroom-config.xml file. Below is the sample webpage definition to accomplish the goal:
Here is the detail of the above definition:
- With webpage element, we instruct the framework to intercept all the webpages satisfying the uri /|(/||||-|_)*.(jsp|html) which is a Java specific regular expression. You can always define your own regular expression to include/exclude specific webpage.
- The script child tag instructs the framework to inject the script to all the webpages.
- The #{} is the format to access server variables. #{contextPath} is replaced with web application's context path.
The benefits of this approach are:
- You don't need to modify your webpages to include the scripts
- The approach works for any type of HTML file whether it's *.jsp or *.html
- The rule will automatically include newly added pages or exclude removed pages
Coming back to the original point, how the framework works?
It's driven by vroom-config.xml file. When a web application is deployed to the application server, the server loads the filter and controller defined in the web.xml file. As part of VroomFilter loading, the vroom-config.xml file is loaded and becomes available to the framework as a configuration object. Every time when the filter intercepts a request, it consults the configuration object to provide rules (defined as webpage elements) for the request. If no rule is found, the filter ignores the request and processing continues as normal, otherwise, based on the rules, the filter injects the required scripts, stylesheets and meta-tags to the final response of the request and delivers the modified response to the client. User interacts with the webpage as usual and if in execution of any HTML DOM event, which was bound to a server side Java method as per definition in the configuration file, an AJAX request is initiated. The response of the AJAX request is always JSON string. In the vroom-config.xml file, it can be define what to do in response of the event. E.g. to update HTML content or to invoke any JavaScript code. This is explained in detail in the following section.
Read more about this topic: Vroom Framework