PrimeFaces As An API

Chi sono

Francesco Strazzullo

http://www.francescostrazzullo.info/

Chi sono

http://www.e-xtrategy.net/

Chi sono

http://www.cosenonjaviste.it/

http://www.blogzinga.it/

Chi sono

https://www.facebook.com/groups/developermarche/

Chi sono

Java Server Faces

https://www.facebook.com/groups/650004995073683/

Java Server Faces

JSF it's a component-based framework that tries to hide the complexity of modern web application.

Java Server Faces

<h:commandButton value="Test"/>
<input type="submit" name="j_idt37:j_idt39" value="Test">

Server (*.jsf / *.xhtml)

Client (*.html)

Components

JSF it's a component-based framework. Everything should be a component: from the basic input field, to a complete CRUD form. 

Why Components?

Reusable

Why Components?

Isolated Scope

Why Components?

Injectable

What Is a Component?

What Is a Component?

Component : the object that holds the business logic of our component. (value,events, etc.)

What Is a Component?

Renderer : the object that render our component to HTML markup and grab value from the user.

PrimeFaces is a JSF component-library. It's a  de facto standard in the JSF world.

Source: PrimeFaces blog :)

PrimeFaces is awesome but...

In real life projects you will need to create custom components

My Life With PrimeFaces

My Life With PrimeFaces

My Life With PrimeFaces

PrimeFaces Framework

Widget

 

CoreRenderer

 

Events

 

Utils

Widget

You will build complex components

Widget

Widget

A complex Javascript component it's called  widget . Every PrimeFaces widget extends a  BaseWidget

Widget

Every component that we will create will extend  BaseWidget too.

Widget

MaterialPrime.widget.Checkbox = PrimeFaces.widget.BaseWidget.extend({
	init : function(cfg) {
		this._super(cfg);
		this.input = jQuery(this.jqId+"_input");
		var that = this;
		
		this.input.on("change",function(){
			if(that.cfg.behaviors && that.cfg.behaviors.valueChange) {
				that.cfg.behaviors.valueChange.call(that.input);
			}
		});
	}
});

CoreRenderer

Every PrimeFaces renderer extends  CoreRenderer . This class grant access to utility methods to create a widget in a very simple way.

CoreRenderer

private void encodeScript(FacesContext context, Checkbox checkbox) throws IOException {
    
    String clientId = checkbox.getClientId();
    String widgetVar = checkbox.resolveWidgetVar();
		 
    WidgetBuilder wb = getWidgetBuilder(context);
		 
    wb.initWithDomReady("Checkbox", widgetVar, clientId);
    wb.attr("disabled",checkbox.isDisabled());
    encodeClientBehaviors(context, checkbox);
    wb.finish();

}

Workflow

To create new component you can follow this workflow:

  • Create a frontend stub
  • Wrap everything in a PrimeFaces widget
  • Create a JSF Component that holds the server business logic
  • Create the renderer that binds the server component to the widget
  • Iterate! :)

Drawbacks

This "Framework" is an internal one, so there's no public documentation.

 

( Now you have this! :) )

Drawbacks

Breaking Changes

References

http://www.mastertheboss.com/jboss-web/primefaces/extending-primefaces-components

 

http://www.francescostrazzullo.info/blog/2014/08/extending-primefaces-input-components/

 

http://www.mastertheboss.com/jboss-web/primefaces/extending-primefaces-ajax

Feedback

http://goo.gl/forms/t73T4a4CrO

That's It!

f.strazzullo@e-xtrategy.net

@TheStrazz86

https://github.com/primefaces-extensions/core

https://github.com/MaterialPrime/material-prime

Thanks!

PrimeFaces as an API - JUG Milano 2015

By Francesco Strazzullo

PrimeFaces as an API - JUG Milano 2015

  • 2,837