JSPX is designed to serve the need of rich applications. The design of the framework is considering many targets like modularity and extendability. The framework is composed of main three parts (Engine, Web UI, Static Resources).
Jspx Engine is responsible for all core functionalities starting from receiving the HTTP request until rendering the final HTML to the browser. Jspx Engine is composed of several components
RquestHandler and ResourceHandler are the main two servlets that need to be configured in the Web.xml file in order to allow jspx to recieve HTTP requests and renders your jspx pages.
Sometimes you may need to provide a customized handling for incomming request just before jspx part (like changing the default character set of your application, handling the errors with special page and so on.). You can extend the nature of the Request Handler by creating your own class that extends the RequestHandler and then provide your own customization The live demo source code shows an example on this you can download the demo from the download section . In most of cases you will not need to do so. Simply configure both servelts in the web.xml file to serve your jspx pages.
RequestHandler is the very first component to be invoked upon HTTP request on an jspx page. It is responsible for:
The ResourceHanlder is responsible for rendering all embedded resources inside the jspx library to the end user. Jspx includes several out of the box resources that represents some of the open source projects that jspx uses inside. These resources are (Javascript, CSS, Images). There is no need at all to customize this class, however it is not final :).
Jspx does not allow java code inside the HTML. Still the need for declarative code inside the HTML is very important, for that jspx
offers the ability of using EL syntax to inject values from your controller to the HTML. Jspx is fully supporting standard EL Expression
Language, in Jspx 2.1 based on JEXL library the EL expressions are supported.
Some Examples on the EL syntax used:
public String getCustomerName() { return "Test Customer"; }
Jspx pages are written in HTML syntax, in fact XHTML syntax. It should be fully accurate XHTML syntax as these pages
are parsed using XML parser. The page parser is reading the HTML pages and convert them into an instance of Page Class
This page class is merges along with the controller the developer declares associated with the HTML Page.
The HTML controls declared in the HTML page are composed as a tree of controls that can be navigated forward and backward
, you can query for a certain control and you can inject and delete controls at runtime.
The PageModelComposer class does the following:
Jspx provides admin interface for controlling its settings and invoke some actions at runtime. The functions exposed are:
public void clearAllChachedPages(); public void removeChachedPage(String pageName); public List<String> getCachedPages(); public List<String> getCachedMasterPages(); public String getCharSet(); public void setCharSet(String charset); public String getJspxVersion(); public boolean isJEXL(); public void setUseJEXL(boolean themeTwitter); public boolean isThemeTwitter(); public void setThemeTwitter(boolean themeTwitter); public boolean isShowSQL(); public void setShowSQL(boolean showSql);
Jspx features are all served by Set of utility components. These components are including the following:
This component is responsible for modeling all HTML and Jspx Controls to provide OOP API to interact with these controls from your java controller.
The Web UI layer is split into two parts:
The pages are the main controller that the developer use to interact with his web forms. For each HTML page there must be a Controller. Developer may choose not to define a controller for a page leaving jspx to create a default controller for it. Pages are simple POJO classes and they are not Servlets, however developer still have access on HTTP Servlet Request, Response and Session. Developer can define his own Page by creating a new class that extends one of the three types of a Page
<page contoller="org.bay.jspx.demo.live.HelloJspxController" > <html> <body> <input type="button" onServerClick="doClick"></label> </body> </html> </page>
package org.bay.jspx.demo.live; import eg.java.net.web.jspx.engine.annotation.JspxWebControl; import eg.java.net.web.jspx.ui.controls.html.elements.Label; import eg.java.net.web.jspx.ui.controls.WebControl; import eg.java.net.web.jspx.ui.pages.Page; public class HelloJspxController extends Page { public void doClick(WebControl invoker, String args) { // Developer logic to be executed upon click } }
This example can be fully tested on Hello Jspx (with Java Controller) on live demo.
For many HTML Controls there are corresponding Classes to be used to interact with HTML controls through java code.
@JspxWebControl(name = "divId") GenericWebControl div= new GenericWebCotnrol("div");
Jspx is using many open source projects to provide rich functionalities. These open source projects has their own javascript and css files. These files are all merged into the jspx jar to be rendered at runtime to end user. There are other resources that are parts of the Jspx library itself.
The following is the list of the project used inside.