As an exercise, I'm creating some custom components in jsf 2.2 by using just annotations. For now I am not interested in a taglib for completion in the ui and since that exempts me from maintaining it, initial development is quicker. This al works perfectly. In this example I have one component that, for now, extends the PrimeFaces InputText (changing that does not make a difference), a clean faces-config (correctly 2.2 namespaced) and a simple page
component:
package my.custom.xforms;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.FacesComponent;
import org.primefaces.component.inputtext.InputText;
@FacesComponent(value = "xforms.input", createTag = true,
namespace = "http://www.w3.org/2002/xforms", tagName = "input")
@ResourceDependencies({
@ResourceDependency(library="primefaces", name="primefaces.css"),
@ResourceDependency(library="primefaces", name="jquery/jquery.js"),
@ResourceDependency(library="primefaces", name="primefaces.js")}
)
public class Input extends InputText {
public Input() {
setRendererType("xforms.inputRenderer");
}
@Override
public String getFamily() {
return "my.xforms.components";
}
}
faces-config.xml
<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">
</faces-config>
page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:p="http://primefaces.org/ui">
<h:head/>
<h:body>
<xf:input />
</h:body>
</html>
This nicely shows a 'PrimeFaces' text input.
As an exercise, I added a tag that defines a model (internal to 'my' engine) that has no ui interaction. So my thought was to add a TagHandler (it does not need to manipulate the tags before it either, so maybe I should just extend UIComponentBase
, but that is not the 'issue' now). TagHandlers cannot be created via annotations from what I can see, so I created a taglib.xml and put just my TagHandler in there.
taghandler
package my.custom.xforms;
import java.io.IOException;
import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;
public class ModelTagHandler extends TagHandler {
public ModelTagHandler(TagConfig tagConfig) {
super(tagConfig);
}
public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException, FacesException, FaceletException, ELException {
if (ComponentHandler.isNew(parent)) {
System.out.println("XForms Model encountered");
}
}
}
new page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:p="http://primefaces.org/ui">
<h:head/>
<h:body>
<xf:model /> <!-- can be put in h:head to, does not make a difference -->
<xf:input />
</h:body>
</html>
taglib
<facelet-taglib version="2.2"
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-facelettaglibrary_2_2.xsd">
<namespace>http://www.w3.org/2002/xforms</namespace>
<tag>
<tag-name>model</tag-name>
<handler-class>my.custom.xforms.ModelTagHandler</handler-class>
</tag>
</facelet-taglib>
To my surprise (well only partly), my custom component created with just annotations, stopped working with the following error.
/components/page.xhtml @12,33 <xf:input> Tag Library supports namespace: http://www.w3.org/2002/xforms, but no tag was defined for name: input
It only started working again if I put the custom component in my taglib to.
<tag>
<tag-name>input</tag-name>
<component>
<component-type>xforms.input</component-type>
<renderer-type>xforms.inputRenderer</renderer-type>
</component>
</tag>
Is this expected behaviour? Or should the taghandler be declared in a different way? I tried a lot of combinations of keywords in google, but to no avail. Not finding a bug, nor any hint to do things differently, nothing.
I'm currently running all this in
- Wildfly 8.0.0-Final (Mojarra 2.2.5-jbossorg-3 20140128-1641)
- java7
- PrimeFaces 5.1
- OmniFaces 2.0.
I will try to run it on a newer WildFly tomorrow or just try to update to the latest Mojarra (maybe in a clean Tomcat or whatever).