Why Facelets is preferred over JSP as the view definition language from JSF 2.0 onwards?

True, JSP has some templating capabilities, but the biggest disadvantage of using JSP in JSF is that JSP writes to the response as soon as it encounters template text content, while JSF would like to do some pre/post processing with it. In JSF 1.0/1.1 the following JSF code <h:outputText value=”first”/> second <h:outputText value=”third”/> fourth would … Read more

List of events

You might want to look at “JavaScript HTML DOM Events” for a general overview of events: http://www.w3schools.com/jsref/dom_obj_event.asp PrimeFaces is built on jQuery, so here’s jQuery’s “Events” documentation: http://api.jquery.com/category/events/ http://api.jquery.com/category/events/form-events/ http://api.jquery.com/category/events/keyboard-events/ http://api.jquery.com/category/events/mouse-events/ http://api.jquery.com/category/events/browser-events/ Below, I’ve listed some of the more common events, with comments about where they can be used (taken from jQuery documentation). Mouse Events … Read more

Dynamically generate h:column based on list of hashmaps

Is it possible to bind a List of HashMaps to the jsf component h:dataTable? That’s only possible if you generate the necessary <h:column> tags with a view build time tag such as JSTL <c:forEach>. Here’s a concrete kickoff example, assuming that your environment supports EL 2.2: <h:dataTable value=”#{bean.listOfMaps}” var=”map”> <c:forEach items=”#{bean.listOfMaps[0].keySet().toArray()}” var=”key”> <h:column> #{map[key]} </h:column> … Read more

c:forEach inside primefaces(e.g. p:panelgrid) inside ui:repeat

The transition from the XHTML source code to the generated HTML output is a two-step process. First, during view build time, the XHTML source code is parsed and turned in a tree of Java UIComponent instances representing the JSF UI component tree, as available by FacesContext#getViewRoot(). Then, during view render time, the JSF UI component … Read more

JSF 2 Global exception handling, navigation to error page not happening

It’s most likely because the current request is an ajax (asynchronous) request. The exception handler which you’ve there is designed for regular (synchronous) requests. The proper way to change the view in case of an ajax exception is as follows: String viewId = “/error.xhtml”; ViewHandler viewHandler = context.getApplication().getViewHandler(); context.setViewRoot(viewHandler.createView(context, viewId)); context.getPartialViewContext().setRenderAll(true); context.renderResponse(); This is however … Read more

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

How to use to iterate over a nested list?

What you need is to nest another <ui:repeat> tag in your outer iteration: <ui:repeat value=”#{bean.listOfA}” var=”a”> … <ui:repeat value=”#{a.listOfB}” var=”b”> … </ui:repeat> </ui:repeat> The only thing left that is worth noting is that nested <ui:repeat> tags used to have problems with state management until Mojarra 2.1.15 version (details in jsf listener not called inside nested … Read more