pittsburgh java user group dec 9 2009 java purefaces a jsf framework extension l.
Skip this Video
Loading SlideShow in 5 Seconds..
Java Purefaces PowerPoint Presentation
Download Presentation
Java Purefaces

Loading in 2 Seconds...

play fullscreen
1 / 25

Java Purefaces - PowerPoint PPT Presentation

  • Uploaded on

Pittsburgh Java User Group– Dec 9 2009 Java PureFaces: A JSF Framework Extension. Java Purefaces. Web development and JSF review Java PureFaces - a JSF extension Briefly discuss current state of the project Q&A. Web Development. First, static web content Written in HTML

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Java Purefaces' - mansour

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
pittsburgh java user group dec 9 2009 java purefaces a jsf framework extension
Pittsburgh Java User Group– Dec 9 2009

Java PureFaces: A JSF Framework Extension

Java Purefaces


Web development and JSF review

Java PureFaces - a JSF extension

Briefly discuss current state of the project


web development
Web Development
  • First, static web content
    • Written in HTML
    • Sent directly to the browser
  • Next, dynamic web content
    • Web containers, Java servlets, JSP
    • HTML is dynamically generated and then sent to browser
web development4
Web Development

Java is the way to go.

  • JSP - Java Server Pages
    • UI code writing in JSP and on the server
    • Difficult to maintain
    • Not a programming language
  • Attempts to solve JSP downfalls – new frameworks
    • Struts, Tapestry, WebObjects, Spring MVC, JSF, Wicket, GWT, etc.
    • Try to solve issues such as error handling, validation, code reuse, etc.
      • Use tags to bind data to the server
    • Wicket and GWT provide Java solutions
quick jsf overview
Quick JSF Overview
  • What is it?
    • A server side user interface component framework for Java™ technology-based web applications – wikipedia
    • A specification and reference implementation for a web application development framework containing components, events, validators & converters, navigation, etc. – wikipedia
    • Developed by SUN and part of the J2EE SPEC!
  • Uses static template pages (containing mix of JSF special tags and HTML tags)
  • Uses “backing-bean” on the server side for binding. Ex: #{address.city}
  • Navigation & backing-beans are defined in static files
what jsf looks like
What JSF looks like..

JSP Page

Backing Bean




It can get very big quickly.

(Each thing needs to be set up for each view)

You can see the JSF GuessNumber demo here



JSF supports UI Component creation through Java.

Ex: <h:panelGroup binding="#{root.render}"></h:panelGroup>

what is java purefaces
What is Java PureFaces?
  • An extension of JSF.
    • Uses standard JSF and RichFaces to create PureFaces components
  • All UI development is in Java
    • CSS and JavaScript are easy to plug-in
  • Can be added to an existing application
    • Add a purefaces bean in the configuration file and easily bind into existing pages using :

<h:panelGroup binding="#{root.render}"></h:panelGroup>

  • Simple API.
    • newPureOutput(“Hello World”);
java purefaces vs jsf
Java PureFaces vs. JSF

Very simple.

…and the JSP page and simple bean only need to be defined once at the beginning of the project.

Source code available at http://www.b6systems.com/javaPureFaces.html

java purefaces components
Java Purefaces components

PureFaces online component demo

The demo source is available at http://www.b6systems.com/javaPureFaces.html

To run it locally, unzip it and run “mvn tomcat:run”. Get maven here


To create a component or whole view, just implement PureComponent

  • Direct wrappers of existing JSF components
  • Encapsulation of the JSF components has advantages:
    • Simplifies the API for the developer
    • PureComponents are serializable
  • Creating Custom components is simplified
    • Components can quickly be created in PureFaces – no tags or configuration
    • Application-specific components are POJO
custom components
Custom components

public class LabelAndInputComponent<E> implements PureComponent {    private String label;            private PureEditableValue<E> editableValue;            public LabelAndInputComponent(String label, E value) {                    this.label = label;                    this.editableValue = new PureEditableValue<E>(value);            }            public PureComponent createUIComponent() {                    PurePanelGrid grid= new PurePanelGrid(2);                    grid.add(new PureOutput(label).setStyleClass("labelStyleClass"));                    grid.add(new PureInput(editableValue).setStyleClass("inputStyleClass"));                    return grid;            }            public E getValue(){                    return editableValue.getValue();            }    }

custom components15
Custom components

      private LabelAndInputComponent<String> field =           new LabelAndInputComponent<String>("A Label", "default text"); // example

/** Create a DIV element that contains a label component */      public PureComponent createUIComponent() {            PureDiv div = new PureDiv();                    div.setStyleClass("divStyleClass");                    div.add(field);          return div;      }

// ex: get the value from the field now using field.getValue();

Source code from PureFaces article on The Server Side

java purefaces features
Java PureFaces features
  • Simplified with maintenance in mind: 80% of your cost
    • Simple: Straightforward SWING-like API (without having to have a member for each UI component)
    • Single UI Location : Changing the UI can be done in one place. There is no need to keep a JSP page in-sync with its bean.
    • Easy refactoring: Everything is in Java. Use of existing, robust refactoring tools makes it easy.
    • Testing: All bindings can be tested by creating the component or view in a simple JUNIT test.
java purefaces features17
Java PureFaces features

PureFaces Demo Link

  • Ajax-enabled
    • Built-in by using RichFace
    • PureFaces API includes methods for adding Ajax
  • CSS & JavaScript
    • PureFaces makes it easy to use semantic HTML and add CSS / JS
    • RichFaces jQuery component makes it easy to target complex JSF component elements by adding scripts only where necessary (no additional JS files to load).
under the hood
Under the hood...

PureFaces Demo Link

  • Binding attributes to any object
    • Get around using backing beans by using the JSF ValueChangeListener to go back into the application and set up values when the form is submitted
    • We created a class called InputValueChangeListener to set these values like this:

PropertyUtils.setNestedProperty(obj, attribute, changeEvent.getNewValue());

    • Bindings are tested when the object is created, so they can be tested with JUNIT
under the hood19
Under the hood...

PureFaces Demo Link

  • Binding buttons and links to any objects
    • Get around backing beans by using JSF ActionListeners
    • We created an ActionListener called CommandActionListener to execute Runnables, and a Runnable named MethodCommand to execute a method in an object. MethodCommand does this using reflection:

runningClass.getDeclaredMethod(methodName, classes).invoke(obj, args);

    • Bindings are tested when the object is created, so they can be tested with JUNIT
under the hood20
Under the hood...

PureFaces Demo Link

  • Creating a new UI on Ajax event
    • We add an ActionListener to the RichFaces AjaxSupport component.
    • We then use a Runnable to update the JSF component tree with whatever is configured to be updated on a specific ajax-event.
ui design
UI design
  • UI with Java PureFaces in practice
    • Start with the interface requirements
    • Design the behavior of the implementation (standard OO design)
    • Break up the view per the application design
    • Create any new components or custom application components
    • Add basic CSS, and jQuery to target HTML only accessible after HTML is created
    • Use firebug in FireFox to tweak and get the final CSS, & test in all browsers (and most likely fix some IE compatibility issues)
  • Tools
    • Eclipse: for just about everything. In debug mode, changes are immediately available without reloading app
    • Browser tools: firebug in FireFox, developer tools in IE8 and Chrome. IETester for previous versions of IE. Also, Web Developer in FireFox has some nice features
    • AjaxLog: component included in RichFaces to help debug any ajax interactions not working as expected
to summarize
To summarize...
  • Virtually all development is in Java
    • There is a single JSP page and a simple bean to connect it to the application
    • All PureComponents are POJO.
  • Extremely dynamic
    • Views are created directly from the application and can easily be redefined on the fly (ex: panelGrid demo)
  • Direct object-model access
    • No need to worry about what is accessible only through the bean
  • Simpler maintenance, Faster development
    • Views can be tested through JUnit.
    • Everything can be done using Java tools (refactoring, etc.)
    • Simpler, documented API
  • Ajax- enabled
current state
Current state
  • Component development
    • Need to implement more components. Built on as-needed basis
  • Depends on Session to store the UI
  • Combines aspects of UI Development with Java Developer role
    • many JSF developers handle both
what s next
What’s next?
  • We are trying to raise awareness in the community so that:
    • We can get outside opinions and suggestions
    • Others can help expand and grow the framework extension.
  • There is more information available:
    • http://www.b6systems.com/blog
    • http://www.theserverside.com/tt/articles/article.tss?l=IntroducingJavaPureFaces
    • Source code at http://www.b6systems.com/javaPureFaces.html
    • Demo available at http://www.b6systems.com/pureFacesComponents/demo.jsf