@JsfComponent(type = "com.example.MyComponent", family = "myFamily", renderer = @JsfRenderer(type = "com.example.MyComponentRenderer"))
public class MyComponent extends UIComponentBase {
@Attribute(defaultValue = "Default value")
public String getValue() {
return (String) getStateHelper().eval(PropertyKeys.value, "Default value");
}
public void setValue(String value) {
getStateHelper().put(PropertyKeys.value, value);
}
@Command
public void doSomething() {
}
}
public class MyComponentRenderer extends RendererBase {
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("class", "my-component", null);
writer.writeText(((MyComponent) component).getValue(), null);
}
}
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<component>
<component-type>com.example.MyComponent</component-type>
<component-class>com.example.MyComponent</component-class>
</component>
</faces-config>