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

Set decimal separator when using f:convertNumber

The default decimal separator depends on the locale used. You can set it in 2 ways: On a per-view basis by the locale attribute of the <f:view> tag: <f:view locale=”#{bean.locale}”> On a per-converter basis by the locale attribute of the <f:convertNumber> tag: <f:convertNumber locale=”#{bean.locale}” /> It’s unclear what locale you’re targeting, but the use of … 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

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

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

How to create user-friendly and seo-friendly urls in jsf?

If this is intended as an improvement of an existing application, then you basically need a Filter which detects “dirty” and “friendly” URLs. When it detects a “dirty” URL, then it should redirect the request to a “friendly” URL by HttpServletResponse#sendRedirect(). When it detects a “friendly” URL, then it should forward the request to the … Read more

java.lang.AbstractMethodError: org.apache.xerces.dom.ElementImpl.getTextContent()Ljava/lang/String

java.lang.AbstractMethodError: org.apache.xerces.dom.ElementImpl.getTextContent()Ljava/lang/String; This will happen when there are Xerces JAR files in your WAR’s /WEB-INF/lib (or even JRE’s /lib) which is of an older version than the one internally used by the servletcontainer. The older version, which apparently implements JAXP of Java 1.4.2 or older, is missing the mentioned method which was introduced in JAXP … Read more