演習として、アノテーションのみを使用して jsf 2.2 でいくつかのカスタム コンポーネントを作成しています。今のところ、UI での補完用の taglib には関心がありません。それによって保守が免除されるため、初期開発がより迅速になります。これは完全に機能します。この例では、今のところ、PrimeFaces InputText を拡張する 1 つのコンポーネント (変更しても違いはありません)、クリーンな faces-config (正しく 2.2 名前空間)、および単純なページがあります。
成分:
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";
}
}
顔-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>
ページ
<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>
これは、「PrimeFaces」テキスト入力をうまく示しています。
演習として、UI インタラクションを持たないモデル (「my」エンジンの内部) を定義するタグを追加しました。だから私の考えは、TagHandler を追加することでした (その前にタグを操作する必要もないので、単に拡張する必要があるかもしれませんUIComponentBase
が、それは今の「問題」ではありません)。TagHandlers は、私が見ることができる注釈を介して作成できないため、taglib.xml を作成し、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");
}
}
}
新しいページ
<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>
タグライブラリ
<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>
驚いたことに (一部だけですが)、注釈だけで作成したカスタム コンポーネントが次のエラーで動作を停止しました。
/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
カスタムコンポーネントをtaglibに配置した場合にのみ、再び機能し始めました。
<tag>
<tag-name>input</tag-name>
<component>
<component-type>xforms.input</component-type>
<renderer-type>xforms.inputRenderer</renderer-type>
</component>
</tag>
これは予想される動作ですか?または、タグハンドラを別の方法で宣言する必要がありますか? Googleでキーワードの組み合わせをたくさん試しましたが、役に立ちませんでした。バグも、やり方を変えるためのヒントも見つかりません。
私は現在、これらすべてを実行しています
- Wildfly 8.0.0-Final (Mojarra 2.2.5-jbossorg-3 20140128-1641)
- java7
- プライムフェイス5.1
- オムニフェイス2.0。
明日、新しいWildFlyで実行するか、最新のMojarraに更新しようとします(おそらく、クリーンなTomcatなどで)。