Friday, February 01, 2013

JSF 2.x Tip of the Day: Great Blog Posts Explaining JSTL vs. JSF

The question comes up quite frequently on various forums, stackoverflow, etc. on JSTL and JSF. I don't want to beat a dead horse so I will leave it to the authors of these posts to explain the differences.

If you have any other good posts, please let me know and I will aggregate them here.

Thursday, January 24, 2013

JSF 2.x Tip of the Day: AJAX Redirection from @WebFilter (Filter)

I was working on an application where I needed to have it redirect to a login page when certain conditions exist in the application, e.g. session timeout, etc. A ViewExpiredException custom exception handler (available in JSF 2.0) can handle this case, but I had a need for another type of "Session" object to be monitored to determine if I should redirect based on its status. The other object was stored in the HttpSession object as an attribute so I decided to handle it with a Filter (@WebFilter).

The first thing is to determine if the request is a partial/ajax request. If it is a normal post, we can handle it with a HttpResponse.sendRedirect(String location) mechanism. If it is AJAX, we need to handle it in a completely different manner. Once I determined that the request was AJAX, I needed to be able to pass the appropriate response back to the JSF page in a format that it could understand. A great tip came from Jim Driscoll's blog: Redirecting from a JSF 2.0 Ajax Request which gave me the general syntax for what I needed to send back.

Note: This is being intercepted in a Filter so I don't have access to the FacesContext. Here is a partial code snippet of how to send the redirect. You would need to set the variable TARGET to go to the desired location.

Monday, January 14, 2013

GlassFish 3 Tip of the Day: Using JDK 7 with JSP Code

A question came up on the NetBeans J2EE Mailing List about using JDK 7 with GlassFish 3.1.2. Specifically, they were getting the error:
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6197: An error occurred at line: 4 in the jsp file: /index.jspPWC6199: Generated servlet error:strings in switch are not supported in -source 1.5  (use -source 7 or higher to enable strings in switch)

The fix is quite simple. You must include a glassfish-web.xml file in your project, and set a couple of properties. compilerSourceVM and compilerTargetVM.

Please see the example below for a complete configuration.
The project will now compile and use JDK7.

Popular Posts