Hi,
To answer my own question, I modified an example from memorynotfound at
https://memorynotfound.com/jsf-custom-input-facescomponent-example/.
I found out that I cannot add an action listener to the custom component, UIInput.
Because the parent source is not an action source even thought the custom component has a command button.
@FacesComponent(value = "com.memorynotfound.jsf.CustomInput")
public class CustomInput extends UIInput {
...
@Override
public void encodeEnd(FacesContext context) throws IOException {
String clientId = getClientId(context);
char sep = UINamingContainer.getSeparatorChar(context);
encodeInputField(context, clientId + sep + "inputfield");
encodeSubmitButton(context, clientId + sep + "submit");
encodeOutputField(context);
}
private void encodeInputField(FacesContext context, String clientId) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("input", this);
writer.writeAttribute("type", "text", null);
writer.writeAttribute("name", clientId, "clientId");
writer.writeAttribute("size", "30", null);
Object value = getValue();
if (value != null) {
writer.writeAttribute("value", value.toString(), "value");
}
writer.writeAttribute("size", "6", null);
writer.endElement("input");
}
private void encodeSubmitButton(FacesContext context, String clientId) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("input", this);
writer.writeAttribute("type", "Submit", null);
writer.writeAttribute("name", clientId, "clientId");
writer.writeAttribute("value", "Click Me!", null);
writer.endElement("input");
}
...
}
I did this:
<custom:custom-input>
<f:actionListener type="com.memorynotfound.jsf.MyActionListener"/>
</custom:custom-input>
I got an error saying :<f:actionListener> Parent is not of type ActionSource, type is: com.memorynotfound.jsf.CustomInput@5b8c3387
So, that proves that custom component does not work with listener like the JEE tutorial says.