Spring Boot JSF Integration

This is the way I have JSF working with Spring Boot (full sample project at Github, updated with JSF 2.3 and Spring Boot 2): 1. Dependencies In addition to the standard web starter dependency, you’ll need to include the tomcat embedded jasper marked as provided (thanks @Fencer for commenting in here). Otherwise you’ll get an … Read more

Execute JavaScript before and after the f:ajax listener is invoked

Use onevent attribute. It must point to a callback function reference (so don’t include parentheses!): <f:ajax … onevent=”functionName” /> Whereby the actual callback function look like this (JSF will provide the argument all by itself): function functionName(data) { var status = data.status; // Can be “begin”, “complete” or “success”. var source = data.source; // The … Read more

f:viewParam doesn’t pass required parameter when new xmlns.jcp.org namespace is used

The way how the new xmlns.jcp.org XML namespaces are been handled is broken in the first Mojarra releases 2.2.0 and 2.2.1. It has been fixed in Mojarra 2.2.2 (note: ticket in the link describes different problem symptom, but under the covers, it’s essentially the same cause). It’s recommended to upgrade to Mojarra 2.2.2. GlassFish 4.0 … Read more

Should be used for JSF 2.2 CSRF protection?

I am confused. I see that JSF 2.0 has implicit CSRF protection: How JSF 2.0 prevents CSRF This implicit protection is on POST requests only (i.e. pages with <h:form>). On the other side according to the article http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/JSF-CSRF-Demo/JSF2.2CsrfDemo.html we should add the following element to the faces-config.xml file with the list of JSF pages. <protected-views> … Read more

Populate p:selectOneMenu based on another p:selectOneMenu in each row of a p:dataTable

Whilst your initial solution works, it’s in fact inefficient. This approach basically requires the entire object graph of the Country and State tables (even with circular references) to be fully loaded in Java’s memory per JSF view or session even though when you simultaneously use only e.g. 5 of 150 countries (and thus theoretically 5 … Read more

Process f:viewParam only on page load

You can achieve this by creating a custom tag extending <f:viewParam> wherein you store the submitted value as an instance variable which isn’t stored in JSF view state instead of in the JSF view state as the <f:viewParam> by default does. By end of request, all UI component instances are destroyed. They are recreated in … Read more

JSF: Mojarra vs. OmniFaces @ViewScoped: @PreDestroy called but bean can’t be garbage collected

The cause of this problem seems to be due to strange behaviour JVisualVM when attached to Glassfish/Payara. The test case used for this question is still extremely useful, however the conclusions concerning Garbage Collection in the original post (and images) were based on JVisualVM, and I have since found they are not valid. Use the … Read more

javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL does not work anymore since Java EE 7 / EL 3.0

Fixed with a custom resolver: faces-config.xml: <application> <el-resolver>my.package.EmptyNullStringResolver</el-resolver> </application> EmptyNullStringResolver.java: /** * @author pg */ public class EmptyNullStringResolver extends ELResolver { @Override public Class<?> getCommonPropertyType(ELContext context, Object base) { return String.class; } @Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { return null; } @Override public Class<?> getType(ELContext context, Object base, Object property) { return null; … Read more