Wednesday, April 10, 2013

JSF 2.x Tip of the Day: Post Exception Back Button

Introduction

This is hopefully one simple example of how to make a "back" button when an exception occurs, and sends you to an exception page. The question becomes "How do I get back to the page where the exception occurred?" The navigation back to the offending page is possible, but you want to make sure that you handle the exception, or you may get into a cycle.

A solution was suggested to me by my friend Markus Eisele using an ExceptionHandler in JSF. I had used exception handlers in the past, and thought that it was a simple and elegant idea. The code I am providing below DOES NOT handle the exception. This is specific to your implementation. This is just a handler that sits on top of your exception hierarchy, and provides a convenient mechanism to navigate back.

Code

The example code for the NetBeans Maven project can be downloaded from BitBucket here: exception-handler-navigation-button

You will need to register the factory below in the faces-config.xml file.

GeneralExceptionHandlerFactory.java


GeneralExceptionHandler.java


Usage

Here is an example of how to use it from an exception page.

Tuesday, April 09, 2013

JSF 2.x Tip of the Day: PrimeFaces Chart Coding Exam

PrimeFaces Pie Chart

Background

I have been asked to interview a number of engineers over the last couple of years. We were interested in hiring an engineer with a background in JSF specifically PrimeFaces, Java EE 6, and NetBeans.

Basically I wanted someone...like me.

I came into work one day, and I was told that I needed to interview someone in about an hour about a position. The person claimed experience in all of the aforementioned technologies. I needed to come up with a coding exam idea for them. Tick tock tick tock.

I decided to create a NetBeans project using the sample Java DB database, JPA, EJB facades, and a JSF front end using PrimeFaces with a pie chart. The whole process took about 7 minutes to create. When the engineer arrived, I showed him the result and said "I want to see the same results", and explained that I used the sample database from NetBeans.

The engineer was successful and created something similar in about 30 minutes, and additionally showed me up by adding percentage tags to the chart. We hired him after the interview. I am glad to say he is an integral part of our team today.

Coding Exam

What do I want?

Please create a JSF application using PrimeFaces that displays a pie chart using data provided. The application must be developed using NetBeans and Java EE 6 technologies. The example data is provided using the sample Java DB database in NetBeans  We would like to have a pie chart that shows sales totals by customer as a percentage of all sales. You have 1 hour to complete the code, and will be required to explain your design decisions, and results.

Note: I just showed them the pie chart that was generated in the browser and not the actual code. I don't want to sway the candidates decision making, or give them hints on how to solve the problem.

Here is the code for the project: PrimeFacesCodingExam

Conclusion

Even if you don't use this in a coding exam, it is a good example of combining Java EE technologies using NetBeans  and PrimeFaces.

Saturday, April 06, 2013

Java EE @WebFilter Filters

I got an email from a developer a couple of days ago that was complaining that the filters he implemented were not executing on the url patterns he had set. The email was not explicit enough for me to determine if the ordering was an issue too. I created a simple project that shows how to use @WebFilter (Servlet Filters). I was going to dispose of the code, but I thought it might have some redeeming qualities for those who may need a working example.

I have commented out the @WebFilter annotations so that the web.xml controls the ordering. If you uncomment the @WebFilter annotations, you will need to comment the lines in the web.xml. Doing so will produce the same issues reported to me about execution and ordering.

Here is the NetBeans project using Apache Maven: zsolt-filter-example. I didn't want to put in a repo since it was not really a planned project.

Popular Posts