Java EE 8: How to Implement JSF 2.1 Specification in Java Class Libraries
public class MyComponent extends UIComponent {
private String text;
private int count;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
@Override
public String getFamily() {
return "my-component-family";
}
}
@Override
public Widget createWidget(FacesContext context) {
return new MyComponent();
}
<faces-config>
<application>
<component-library>
<library-name>my-component-library</library-name>
<uri>http://example.com/my-component-library</uri>
</component-library>
</application>
</faces-config>
html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>My JSF 2.1 Component Example</title>
</h:head>
<h:body>
<h:outputText value="#{myComponent.text}" />
<h:outputText value="#{myComponent.getCount()}" />
</h:body>
</html>
<auth-method>BASIC</auth-method>
<realm-class>com.sun.enterprise.security.auth.realm.file.FileRealm</realm-class>
<user-name>admin</user-name>
<password-file>/path/to/your/password/file</password-file>