How to save state when extending UIComponentBase

Use StateHelper. It’s available by UIComponent#getStateHelper(). private enum PropertyKeys { currentPageNumber; } public void setCurrentPageNumber(int currentPageNumber) { getStateHelper().put(PropertyKeys.currentPageNumber, currentPageNumber); } public int getCurrentPageNumber() { return (int) getStateHelper().eval(PropertyKeys.currentPageNumber, 0); } Note that I’m returning a default value of 0 in the getter. You might want to change int to Integer and remove the default value so … Read more

Integrate JavaScript in JSF composite component, the clean way

I’d say that what you’ve there is the best you can get, provided that you’re absolutely positive that the HTML element’s nature is so unique that you absolutely need to select it by an ID, every time again. If the HTML representation is not that unique (I can imagine that a Facelets template or include … Read more

How to create a composite component for a datatable column?

The <my:mycolumn> element must be an instance of UIColumn as that’s the only valid child of a UIData component during the render response phase. All other UIComponent types will be ignored, thus not rendered. A composite component is implicitly a UINamingContaner component, which isn’t a UIColumn and therefore ignored. A PrimeFaces <p:dataTable> with a backing … Read more

How to implement a dynamic list with a JSF 2.0 Composite Component?

I’d use a <h:dataTable> in a composite component with a backing UIComponent which you can bind by componentType attribute of the <composite:interface>. In the backing UIComponent you can then maintain the DataModel and define the actions. dynamicFieldList.xhtml <ui:composition xmlns:f=”http://java.sun.com/jsf/core” xmlns:h=”http://java.sun.com/jsf/html” xmlns:ui=”http://java.sun.com/jsf/facelets” xmlns:cc=”http://java.sun.com/jsf/composite” > <cc:interface componentType=”dynamicFieldList”> <cc:attribute name=”value” type=”java.util.List” required=”true” /> </cc:interface> <cc:implementation> <h:dataTable id=”table” binding=”#{cc.table}” … Read more

How to make a grid of JSF composite component?

A composite component gets indeed rendered as a single component. You want to use a Facelet tag file instead. It gets rendered exactly as whatever its output renders. Here’s a kickoff example assuming that you want a 3-column form with a message field in the third column. Create tag file in /WEB-INF/tags/input.xhtml (or in /META-INF … Read more

When to use , tag files, composite components and/or custom components?

What is the difference between those approaches? Facelet templates Use Facelet templates (as in <ui:composition>, <ui:include> and <ui:decorate>) if you want to split main page layout fragments into reuseable templates. E.g. header, menu, content, footer, etc. Examples: How to include another XHTML in XHTML using JSF 2.0 Facelets? What is the real conceptual difference between … Read more