Eclipse ベースの JSF プロジェクトに War と Jar プロジェクトがあります。Faces-config.xml を使用して宣言するのではなく、アノテーションを使用して FacesConverter を宣言することにしました (無数にあるものの中で)。
@FacesConverter(value="passwordFieldStringConverter")
public class PasswordFieldStringConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
try {
return arg2.getBytes("UTF-16BE");
}
catch(UnsupportedEncodingException uee) {
Assert.impossibleException(uee);
}
return(null);
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
try {
return new String((byte[]) arg2, "UTF-16BE");
}
catch(UnsupportedEncodingException uee) {
Assert.impossibleException(uee);
}
return(null);
}
}
そして、.xhtml で直接passwordFieldStringConverterを使用します。
<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:sec="http://www.springframework.org/security/facelets/tags">
<ui:composition>
<f:view>
<f:loadBundle basename="landingPage.bundle" var="bundle" />
<ui:decorate template="/WEB-INF/jsf_helpers/htmlShell.xhtml">
<ui:param name="PageTitleParam" value="#{bundle.pageTitle}" />
<h:form>
<h:dataTable var="rowVar" value="#{userListContainer.users}">
<f:facet name="header"><h:outputText value="Users you are currently managing:" /></f:facet>
<h:column>
<f:facet name="header">
<h:outputText value="Screen Name" />
</f:facet>
<h:outputText value="#{rowVar.screenName}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Password" />
</f:facet>
<h:outputText value="#{rowVar.password}">
<f:converter converterId="passwordFieldStringConverter" />
</h:outputText>
</h:column>
</h:dataTable>
</h:form>
</ui:decorate>
</f:view>
</ui:composition>
</html>
JSF は、展開時に私の戦争で jar をスキャンし、どのクラスに注釈が付けられているかを検出します (それに応じてアプリケーションを自動構成します)。私の問題は、JSF が、私が持っているどのクラスの注釈を付けているかを明らかに検出していないことです。
War プロジェクトにはすべての .xhtml ファイルとプロジェクトの faces-config.xml があり、Jar プロジェクトにはすべての顔関連の Java コード (アクション Bean、マネージド Bean、カスタム コンバータなど) があります。