Monday, March 31, 2014

Resource Library Contracts with NetBeans 8 and PrimeFaces

It is critical to organize an application in such a way that it is easy for users to navigate and perform their work.  PrimeFaces includes a layout component that makes it easy to select the most fitting layout for your application.  Assuming that the layout should be utilized across all application views, a Facelets template should be created, and the PrimeFaces layout should be configured within the template.  

To create the template within NetBeans 8.0, add a resource library contract to the application.  To do so, right-click on the “Web Pages” application directory and then choosing “New”->”Other…”, and select “JavaServer Faces” from the category menu, and finally choose “JSF Resource Library Contract” as the file type (Figure 1). 

Figure 1:  Adding Resource Library Contract within NetBeans

On the “New JSF Resource Library Contract” dialog, enter a contract name and click on the “Create Initial Template” checkbox (Figure 2).

Figure 2: New JSF Resource Library Contract

PrimeFaces offers a number of layouts to develop a user-friendly interface.  To use the layouts, declare the PrimeFaces namespace within the template, and then specify the PrimeFaces Layout component as the first element within the body of the template.  The layout component creates a complex borderLayout model, enabling the development of sophisticated user interfaces.  To add the layout component, use the <p:layout> tag, and specify attributes to customize the layout such as style along with a number of client side callback attributes.  In this post, the fullPage="true" attribute is specified to ensure that the layout spans the entire page.

A series of layout units can be specified within the layout component, and these units are used to arrange the layout in a particular order.  There are 5 different layout units:  top, left, right, top, and bottom. Each layout unit is specified with a <p:layoutUnit> element, and the position attribute indicates where the unit should be placed within the layout.  Add <ui:insert> tags into each of the <p:layout> sections as shown in Listing 1.  The code in Listing 1 specifies a full-page layout for an application.

Listing 1:  PrimeFaces Template Layout

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns=""

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <h:outputStylesheet name="./css/default.css"/>
        <h:outputStylesheet name="./css/cssLayout.css"/>
        <ui:insert name="title">Acme Pools</ui:insert>


        <p:layout fullPage="true"> 

            <p:layoutUnit position="north" size="150" header="Acme Pools" resizable="false" closable="false" collapsible="false"> 
              <ui:insert name="top"></ui:insert>

            <p:layoutUnit position="south" size="70" style="background-color: #dddddd" resizable="false" closable="false" collapsible="false"> 
                Copyright 2014
                Author: J. Juneau

            <p:layoutUnit position="west" size="200" header="Navigation" resizable="false" closable="false" collapsible="true"> 
                <ui:insert name="left"/> 


            <p:layoutUnit position="center"> 
                <ui:insert name="content">Content</ui:insert>



After applying the template to the index view, it will resemble the layout shown in Figure 3.

Figure 3:  PrimeFaces Page Layout

The layout in the example utilizes custom animation to hide the navigation pane, and PrimeFaces provides this functionality without any additional configuration.  As you can see, PrimeFaces and NetBeans 8.0 make it easy to generate a sophisticated user layout.

Friday, March 21, 2014

GlassFish 4 - Let's Help as a Community

We know that GlassFish 4 works with JDK8, but it has not yet been officially sanctioned.  Let's help out as a community and test out GlassFish 4 using the latest nightly builds, and submit any issues that arise.  The more feedback that is provided, the more solid the next release of GlassFish will be!

Here's what you can do to help:

1)  Grab a recent nightly build of GlassFish 4 from here:

2)  Install the build, and configure it to use your installation of Java SE 8 by doing the following:

  Set the AS_JAVA property within your 
  <glassfish-path>\glassfish\config\asenv.conf configuration file equal to your Java 8 installation. 

  On OS X, this would look like the following:


3)  Test your Java EE applications under GlassFish 4 using Java 8, and submit any reproducible issues to the Issue Tracker:

  - Please include the steps to reproduce the issue(s) when submitting them to the tracker.  The more information, the better!

If we do our part as a community, we can help GlassFish to become more stable on Java 8, and then we should see a stable 4.x release sanctioned for use with Java 8 sometime in the future.

HelloType helloLambda = 
          (String text) -> {System.out.println("Hello " + text);};

helloLambda.hello("GlassFish 4 on JDK 8");

Sunday, March 16, 2014

Running GlassFish 4 on Java 8: Experiment with Java 8 Functionality in Java EE 7 Applications

Do you want to use the features of Java 8 with your Java EE 7 application?  It is possible to run GlassFish 4.0 under JDK 8.  To explicitly define which JDK GlassFish 4.0 uses, set the AS_JAVA property within your <glassfish-path>\glassfish\config\asenv.conf configuration file equal to your JDK 8 installation.  On OS X, this would look like the following:


Once you've set this property and then start the GlassFish 4.0 server, it should be running under JDK 8, allowing any of the applications to utilize new Java 8 features, such as streams or lambdas.

Note:  This is for experimental use only, as Java EE 7 has not been sanctioned for use with Java 8 at the time of this post.  

I have successfully configured GlassFish 4.0 to run under Java 8 in my environment, and tested the use of streams within a Java EE 7 application without issue.  Here are some sources demonstrating basic use of streams within a CDI bean:

public class PoolController implements Serializable {
    List pools = new ArrayList();
    public PoolController(){
        pools.add("Pool One");
        pools.add("Pool Two");
        pools.add("Pool Three");
    public String getPool(){
        System.out.println("The number of pools " +;


Friday, March 14, 2014

JavaOne 2014 Call for Proposals

The JavaOne 2014 CFP is available.  If you have an idea for a presentation that you think others will enjoy, please put in a proposal to speak at this year's JavaOne.  JavaOne is one of the world's most highly attended gatherings of Java experts.  It is the place to be if you are interested in collaborating with other Java experts...this is your chance to share your expertise!

Thursday, December 12, 2013

Five Favorite NetBeans Features

Geertjan Wielenga invited to me to share five of my favorite NetBeans features with Oracle.  Here is the article that I wrote on those features.  When using a great IDE like NetBeans, it is hard to choose just five great features.  I've been using NetBeans quite a few years now, and it just continues to get better with each release.  If you are a developer and have not yet tried NetBeans, I suggest that you give it a try...I think you'll be pleased.

Tuesday, September 24, 2013

JavaOne 2013 - Starting Off Strong

The past two days have been packed with great sessions, and I believe that this year's JavaOne is going very well so far.  After my initial visit to the Schedule Builder, I knew this conference was going to be good.  I found it nearly impossible to choose which sessions to add to my schedule, and which ones to pass up.  There are so many good sessions to choose from, that I am hard pressed to find a time slot that does not contain at least one session that peaks my interest.  

Each of the sessions that I have attended thus far have been packed with excellent information.  It is clear that JDK 8 is a very hot topic this year.  With many sessions covering new features, such as lambda and Nashorn, JDK 8 is everywhere.  Java EE 7 is also a hot topic at this year's conference.  Sessions covering features such as JSF 2.2, JAX-RS 2.0, JMS 2.0, WebSockets, and more...the benefits of using Java EE 7 are clearly being advertised.  Perhaps some of the most widely discussed buzz around EE 7 is the HTML 5 integration.  It is also nice to see some great PrimeFaces coverage at this year's JavaOne.

NetBeans is also getting a lot of coverage this year.  I have attended sessions covering EE 7 tips and tricks with NetBeans, Project Easel, and several sessions on Java EE that demonstrated how powerful the NetBeans and GlassFish combination can be.  I enjoyed the demos of NetBeans and Project Easel being used to develop apps that scale nicely on mobile devices...complete with live debugging on an iOS device.

JavaFX is looking excellent, and the FX team is doing a great job of showing off it's power.  There are many sessions on JavaFX 8, and some great coverage of FX on Raspberry Pi.  HTML5, CSS, MultiTouch...there are countless sessions demonstrating the use of JavaFX with various technologies.

Overall, the most important part of the conference is the community.  The community is stronger than ever this year.  I've met up with so many great faces in Java over the past couple of days.  The Taylor Street cafe is a great place to meet up, and the GlassFish party at the Thirsty Bear was excellent...thanks to the GlassFish team!  The Exhibition Hall and OTN Lounge are always packed...lots of great demos and discussions.

I have the next three days packed solid of excellent Java content...looking forward to many more great sessions!  Java and the community are strong, and it is a great time to be a Java developer.

Keep up with the latest by visiting OTN at

Friday, June 07, 2013

Java EE 7 Books: Java EE 7 Recipes & Introducing Java EE 7

I have been working hard for over a year now on my most recent publication entitled 'Java EE 7 Recipes: A Problem-Solution Approach', published by Apress (May 2013).  This book covers the Java EE stack from the ground-up, and it includes coverage of EE 7 specific features, such as JSF view actions, WebSocket API, and Concurrency Utilities for Java EE.  Therefore, I feel that the book will be a good read for beginner, intermediate, and advanced Java Enterprise developers.

The first chapter begins by walking readers through recipes regarding the setup of a Java Enterprise environment, including specifics on how to install and configure Glassfish v4, a fully Java EE 7 compliant application server.  It then quickly delves into the development of Java Servlets, including coverage of newer concepts such as registering servlets without WEB-XML, and non-blocking I/O.  

Chapter 2 covers JSP from the ground-up.  Although JSP is no longer the preferred option for enterprise application development, it is still a very viable and widely used technology.  Therefore, this chapter will be handy especially for beginner and intermediate level developers so that they can have a better understanding of how JSP technology works, and where it may be the most useful.

Next, the book delves into JavaServer Faces technology, with in-depth coverage that spans four chapters (Chapter 3 - Chapter 6).  Keeping with the theme of the book, readers will learn how to develop applications with JSF, including useful tips and techniques, as well as integration with third-party libraries such as PrimeFaces.  The JSF 2.2 release (which is new with the release of EE 7), includes useful features such as the ability to invoke managed bean actions on life-cycle phase events (viewActions), and better integration with HTML5.  This book will show seasoned JSF developers how to use these new features so that they can begin integrating them into new and existing applications.

No enterprise application would be complete without database access, and Chapters 7 and 8 provide coverage for JDBC and Object-Relational Mapping via the Java Persistence API (JPA).  Chapter 7 provides coverage for utilization of JDBC technology for database access.  The chapter covers everything from obtaining a connection, to handing errors, simplifying connection management, performing CRUD operations, and execution of database stored procedures.  For those developers more interested in utilizing server-side database connection pools, etc., Chapter 8 covers the Java Persistence API.  The chapter contains vital information for working with underlying data stores via JPA including data mapping and entity creation.  It also hits upon EE 7 specific updates, including schema generation support.

Chapter 9 covers EJB technology, along with its new features via the release of EJB 3.2.  Readers will learn how to utilize EntityManagers, differences between Stateless and Stateful Session beans, how to utilize EJB via JSF, and more.  The new features covered include asynchronous message-driven beans (MDB), explicit designation of remote and local interfaces, and opting out of stateful session bean passivation.  In Chapter 10, readers will learn how to query entities using the most up-to-date features in JPQL.   

If you want to work with Java EE 7, you will most likely utilize GlassFish 4 application server since it is the first EE 7 compliant server.  Chapter 11 includes content on how to get up-and running with GlassFish v4, utilizing the administration console for application and datasource management, and setting up authentication.

One of the most popular features of Java EE beginning with the release of EE 6 has been Contexts and Dependency Injection.  Chapter 12 covers CDI in full detail, including recipes on injection, using CDI beans via JSF views, and more.  It also covers new features such as the injection of bean metadata and the new @Veto annotation for marking classes as ignored by CDI.

Have you heard about the simplification of Java Message Service (JMS) in the new 2.0 release?  Readers will learn all about the new simplified JMS API in Chapter 13, along with other JMS basics such as creation of resources, creating/sending messages, and the new message delivery delay.

Chapter 14 is a bit of an extension on Chapter 11, as it covers authentication and security for Java Enterprise applications, specifically those deployed within a GlassFish container.  Almost every enterprise application requires a login form, and this chapter covers how to create one, and also how to utilize LDAP authentication for producing single-sign on solutions.

SOAP and RESTful web services have become significant technologies for the Java EE stack.  Chapter 15 covers web services, both SOAP and REST-based services using JAX-WS and JAX-RS.  Readers will learn how to create each type of web service, and utilize the new features of JAX-RS 2.0 such as the new client API.

Java is not the only language on the block any longer (or JVM, that is).  It is not uncommon to see different languages being utilized to create entire enterprise applications for the JVM, or even for integration with existing Java EE applications.  Chapter 16 includes a few short recipes showing how one may integrate Groovy or Jython into an EE application.

Since HTML5 and the new era of web applications is upon us, the new WebSockets and JSON-P APIs for EE 7 have become of major importance.  Chapter 17 covers these new APIs, demonstrating how to create and utilize WebSockets for full-duplex communication.  The chapter includes an example calling out to a WebSocket from JavaScript.  It also demonstrates how to utilize the new JSON-P API for creating and parsing JSON.

Chapter 18 covers the use of JavaFX for creation of enterprise applications.  It demonstrates how to develop JavaFX front-end applications, and bind them to EJBs for use with data.  There is also a recipe covering the use of JavaFX with RESTful web services.

Finally, both the Concurrency Utilities for Java EE and Batch Applications APIs have been added to EE 7.  These APIs provide a standard for developing concurrent and batch applications for the enterprise. Coverage includes the creation of server-side resources (ManagedExecutorService, etc.) for concurrent application development, and creation of item-oriented batch processes.

Overall, the Java EE 7 Recipes book is perfect for those that are interested in getting up-to-speed with Java EE, including the latest features.  For those who are already experts with Java EE and are only interested in the new features, stay tuned for the release of my upcoming book entitled 'Introducing Java EE 7', to be published by Apress within the next few weeks.