Wednesday, April 23, 2014

Testing PrimeFaces 5.0RC1 with a Maven-Based Web Project in NetBeans 8.0 IDE

The new PrimeFaces 5.0RC1 has been released!  Now it is time to begin testing the new release with your existing applications.  If you are using a Maven-based web project within NetBeans, it is easy to configure your PrimeFaces 4.x application to test using the new release candidate.  Here's what you need to do:

1)  Ensure that the project is not configured to make use of the "PrimeFaces" framework within the Properties -> Frameworks configuration.  If "PrimeFaces" is selected within the "Components" tab, be sure to de-select it.  You may be unable to deploy the application successfully if you forget this step!



2)  Add a new maven dependency for PrimeFaces 5.0RC1 to your POM.

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.0.RC1</version>
        </dependency>

** You may need to add the PrimeFaces repository to your POM

        <repository>
            <url>http://repository.primefaces.org/</url>
            <id>PrimeFaces-maven-lib</id>
            <layout>default</layout>
            <name>Repository for library PrimeFaces-maven-lib</name>
        </repository>

You should now be able to successfully build and run your project under PrimeFaces 5.0RC1.  This configuration is not difficult, but be sure that you do not get stumped by forgetting to follow Step 1 above, as you will be unable to deploy your application if you do.

To go back to using PrimeFaces 4.x for production use, simply follow these steps once again, but this time make sure you add the PrimeFaces 4.0 dependency within the POM.

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>4.0</version>
        </dependency>

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <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>
    </h:head>

    <h:body>

        <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> 

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

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

     

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

        </p:layout> 

    </h:body>

</html>
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: http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/nightly/

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:

AS_JAVA="/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home"

3)  Test your Java EE applications under GlassFish 4 using Java 8, and submit any reproducible issues to the Issue Tracker:  https://java.net/jira/browse/GLASSFISH

  - 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:

AS_JAVA="/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home"

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:

@Named
@SessionScoped
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 " + pools.stream().count());
        return  pools.stream().findFirst().toString();
    }

}

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!

http://www.oracle.com/javaone/call-for-papers/index.html

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.

http://netbeans.dzone.com/articles/5-favorite-netbeans-features-joshjuneau

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 oracle.com/technetwork/java