Showing posts with label PrimeFaces. Show all posts
Showing posts with label PrimeFaces. Show all posts

Monday, 16 November 2015

PrimeFaces Theme Development

I have been recently been involved in a book project in collaboration with Packt Publishing and co-authored by Sudheer Jonna, a PrimeFaces developer.

I am proud to be able to announce that the book as now been published: PrimeFaces Theme Development


About This Book

  • Build PrimeFaces themes that meet the industry standards
  • Customize your themes for mobile web applications with PrimeFaces Mobile
  • A precise, example-oriented guide to help you create interesting themes using the PrimeFaces tools

Who This Book Is For

If you are a Web Designer who wants to create and modify PrimeFaces themes then this book is for you. Basic knowledge of JSF, CSS, and HTML is assumed.

What You Will Learn

  • Use Maven to create JSF Projects
  • Create a custom theme using JQuery UI tools
  • Package your theme for distribution and use your PrimeFaces-based web applications as drop in libraries
  • Develop additional dynamic look and feel elements that themes do not already supply
  • Apply look and feel elements dynamically to views without causing page refreshes
  • Reduce code repetition by applying page templates to your JSF project

Wednesday, 23 January 2013

PrimeFaces Cookbook

PrimeFaces Cookbook published today.


I am an active forum contributor for the PrimeFaces community and was involved in the publication of this book as a Reviewer. I am proud to be a part of the project and would like to thank Oleg Varaksin and Mert Çalışkan for this excellent book and for their work in the PrimeFaces community.

You can order it here  and if you are either using PrimeFaces or are considering it seriously for your projects then I can only recommend getting a copy.

What you will learn from this book


  • Learn basic concepts to be able to work with PrimeFaces.
  • Delve deep into 100+ rich UI components with all the required details
  • Get solutions to typical and advanced use cases
  • Use the best practices, avoid pitfalls, and get performance tips when working with the component suite
  • Gain know-how of writing custom components on basis of the PrimeFaces' core functionality
  • Meet additional components from the PrimeFaces Extensions


For all things PrimeFaces follow this link.

Wednesday, 14 November 2012

PrimeFaces PUSH

On Monday this week I was going through my blogs round when I spotted this from Geertjan Wielenga,
some of you may know Geertjan as a Principal Product Manager for Oracle and NetBeans guru whose regular blog posts are well worth reading if you are a Java Dev and/or NetBeans user.

In essence what Geertjan is looking for is a way of publishing information to browsers where this information may come from hardware devices perhaps based on TinkerForge.

If you read his post you can see more about what exactly he wants to do.

I decided I would see if I could slap something together which could be used for something like this.

Requirements

  • Data to be supplied asynchronously to the web app and browsers
  • Wide browser support
  • As a Proof of Concept simulation is allowed.
My Technology Choices

I use PrimeFaces for most if not all of my JSF based WebApps and this has some very handy support for PUSH (WebSockets) which uses Atmosphere. I have never used this before so this is the perfect opportunity to try it out.

Because I wanted to do a little more than simply push the current vehicle direction and update a few p tags I also added a page which uses Raphael to provide SVG support. Basically my vehicle is a simple triangle that gets transformed into a direction supplied by data pushed to the client.

I had already suggested using a Singleton Session Bean using Timers as a way of supplying data and decided this would be the easiest way to simulate hardware being spun around and reporting its current direction to any interested clients.

I have created a Project for this on GitHub should you wish to try the code out for yourself.
Edit:

  • I have since found that Glassfish and WebSockets don't mix very well (at least with PrimeFaces).
    I created a version of the same project which runs well under Tomcat 7 where WebSocket support seems to work off the bat!
  • The AsynchDirectionChangeSimulator bean is no longer active but the same function is provided by a Servlet.

Here is the code for the Session Timer Bean that simulates the "hardware".

package org.andy.pf.tfsim.simulator;

import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.primefaces.push.PushContext;
import org.primefaces.push.PushContextFactory;

/**
 *
 * @author a.bailey
 */
@Singleton
@Startup
public class AsynchDirectionChangeSimulator {

    final static String[] DIRS = {
        "North",
        "Northeast",
        "East",
        "Southeast",
        "South",
        "Southwest",
        "West",
        "Northwest"
    };
    
    
    @Schedule(minute = "*", second = "*/1", hour = "*")
    public void pushDirection() {
        String nextDirection = DIRS[(int)(Math.random()*DIRS.length)];
        PushContext ctx = PushContextFactory.getDefault().getPushContext();
        if( ctx != null ) {
            ctx.push("/tfSim", nextDirection);
        }
    }
}


Please note that this looks breathlessly simple and it is because all the magic is wrapped up in the libraries being used.

Here is the page used to display my little triangle animated on push.
The code is meant to be readable by the way not perfect.


<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html" encoding="utf-8">
        <h:head>
            <title>TinkerForge RT Sim with SVG</title>
            <h:outputScript library="js" name="raphael-min.js"/>
            <f:facet name="last">
                <script type="text/javascript">
                    var dirTransforms = {
                       'North':"R0",
                       'Northeast':"R45",
                       'East':"R90",
                       'Southeast':"R135",
                       'South':"R180",
                       'Southwest':"R225",
                       'West':"R270",
                       'Northwest':"R315"
                    };
                    var canvas = null;
                    var tf = null;
                    $(document).ready(function() {
                       canvas = Raphael(document.getElementById("raphaelPanel"), 300, 300);
                       // tf = canvas.rect(50, 20, 40, 100);
                       tf = canvas.path("M120 180H180L150 40L120 180");
                       tf.attr("stroke", "#000");
                    });
                    function setDirection(data) {
                        tf.transform(dirTransforms[data]);
                    }
                </script>
            </f:facet>
        </h:head>
        <h:body>
            <p:panel id="raphaelPanel">
            </p:panel>
            <p:socket onMessage="setDirection" channel="/tfSim"/>
        </h:body>
    </f:view>
</html>