Java PureFaces – Clean & Simple HTML Output

by Matt Pickell for JavaPureFaces

What does the HTML from Java PureFaces look like?  In this post I going to show exactly what mark-up is created.  I’ve cut and pasted a couple of examples from the previous Guess-A-Number demo to show some examples. I’ll start by using a single JSP page for the project:

JSF page for the demo

This is all that is needed in the simplest app JSP page. Here is the code of the createGuessComponent from the demo:

createGuessComponent Java Code

which creates this simple view:

Guess Demo Screen Shot

Guess Demo Screen Shot

and this HTML:

Table Based HTML Java PureFaces output

Or, with the simple swapping of the PurePanelGroup into the code where a PurePanelGrid is currently used, you can get the more updated, non-table based layout (much more CSS-friendly) in the body of the page:

Cleaner HTML output

There is still a table in there. That is configured to allow for an error message next to the input box through JSF messaging. Want to get rid that all tables? That, too, can be easily changed by chaining another option off of the PureInput Component, leaving even smaller, cleaner HTML:

Cleanest HTML output

Although now there is no message for the required input field if the user leaves it blank. This example is shows that when comparing this to the java code that created it, you can now see it is almost line for line (there is no error message, so it is not rendered).

You can use table-based layouts, or work with more current semantic layouts. Either way, it is very easy to create a view.

It is also very easy to manipulate the attributes of the HTML elements, like the style classes in the HTML shown here (class=””). The framework model can support any element attribute, such as DOM “Level 0” Events (onclick, onkeypress, etc.) and inline styles (style=””), to name a few of the more used attributes, by just chaining them onto the component you are adding.

Demo Java PureFaces

by Matt Pickell for JavaPureFaces

Demo it for yourself!

Let’s take a quick walk through Java PureFaces by implementing the JSF guessing number game.
Built in the  Java PureFaces framework, it takes only two classes:

  • GuessNumber — will know how to create a random number to guess and will check it the user number matches the guessing number.
  • GuessNumberView — is responsible to create the GUI and response to the button clicks.

Notice that the code to create the simple GUI, as well as the code that handles the button clicks, is cleanly packaged together.  Very simple!  Compare this to the JSF Version.

Download the demo now! (RAR), (ZIP), (TGZ)

Also, check out the demo applications on the Solutions page.  Both of these major applications were created using  Java PureFaces!

Introducing Java PureFaces!

by Matt Pickell for JavaPureFaces

Introduction to Java PureFaces!

Developing the Web Tier is a big part of designing and developing a web application. Many frameworks exist that attempt to improve this part of the development. These frameworks simplify the process, providing ready tools and improving code reuse.

Most frameworks are developed around a web designer/java developer job split, providing a simple API to the web designers, and an XML/HTML file and a java API for the developers. Examples are Struts and JSF.

Other frameworks are aimed only at java developers and provide a Swing-like API, allowing the developers to develop a web application with only the java language. The developer code can be very object oriented and does not need to be concerned about interacting with HTTP/ JSP/Tags etc. An example of this type of framework is GWT.

Building off of both of these, B6 Systems has created a new framework for Java developers! We call it Java PureFaces. Java PureFaces is built on the very popular JSF framework, but allows the web tier to be designed completely in Java — no massive library of JSP/JSF pages or configuration files necessary.

New framework

Java PureFaces provides a pure Java framework for building the web tier. Java developers can use good object oriented solutions, increase code reuse, speed up development, and simplify code maintenance without worrying about many of the web/http concepts like HTTP, JSP, XML, Tags, HTTP sessions, etc. The API is very simple and easy to learn and use.

Like JSF, Java PureFaces binds object attributes into the GUI, and binds commands and link buttons to object methods. Also, JSF components are used to render the HTML. Unlike JSF, Pure Java Faces attributes and commands can be bound to any POJO object, not only to a backing bean. An advantage of this method is that the bindings themselves can be tested with JUnit.

Because the framework uses JSF, it is very extensible. In order to create a new component, just extend the UIComponent JSF class. Also, only a single HTML page and backing bean are necessary as the container for the web application (this simplicity does mean that, like some other frameworks, you cannot refresh the page or use the browser back button).

Check back, I’m going to be adding more information soon!