HTML and CSS Reference
In-Depth Information
<cc:attribute name="required" type="java.lang.String" default="false" />
<cc:clientBehavior name="change" targets="date" event="change" />
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}">
<input jsf:id="date"
type="date"
jsf:value="#{cc.attrs.value}"
jsf:readonly="#{cc.attrs.readonly != 'false' ? 'true' : 'false'}"
jsf:required="#{cc.attrs.required != 'false' ? 'true' : 'false'}"
step="#{cc.attrs.step}"
list="#{cc.attrs.list}">
<f:convertDateTime pattern="yyyy-MM-dd" />
</input>
</div>
</cc:implementation>
</html>
Creating a Backing Bean for the Composite Component
A composite component backing bean must extend javax.faces.component.UINamingContainer . By convention
you can automatically map the backing bean to the composite component by naming the backing bean the same as
the composite component and by placing the backing bean in a package by the same name as the directory where
the composite component is located. Alternatively, you can annotate the backing bean with the @FacesComponent
annotation and specify the component type as the value of the annotation. The component type can then be specified
in the interface of the composite component. The benefit of manually mapping the backing bean is that you can reuse
the backing bean by other composite components and you do not have to name the backing bean the same as the
composite component.
Listing 7-15 shows a barebones example of a backing bean declared for composite components of type inputDate .
A composite component maps to the backing bean by setting the componentType attribute of the interface to the
name declared in the @FacesComponent annotation, e.g., <cc:interface componentType="inputDate"> .
Listing 7-15. Empty Backing Bean Declared for inputDate Components
package projsfhtml5;
import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;
@FacesComponent("inputDate")
public class InputDateComponent extends UINamingContainer {
}
To support the min and max attributes we need two properties on the backing bean: one for holding the string
representation of the minimum date and one for holding the string representation of the maximum date. We will
name the properties minDate and maxDate. By providing getters for the two properties, they will automatically be
available to the composite component. Then we will override the encodeBegin method where we will extract the java.
util.Dates from the interface and convert them to HTML5 formatted dates that can be used in the implementation.
 
Search WWH ::




Custom Search