UIInputコンポジットの内部にオートコンプリートプライムフェイスコンポーネントを使用する際に問題があります。私の目標は、オートコンプリートフィールドにあらかじめ選択された値でアプリケーションを初期化し、それに応じてラベルを表示することです。私はテストコードにprimefacesを事前選択された値でコンポジットに自動補完する方法は?
ページtestPage.xhtml
<f:view id="view" locale="#{webSession.currentLanguage.locale}">
<h:head>
<title>...</title>
</h:head>
<h:body>
<h:form>
<utils:element/>
<p:autoComplete
value="#{testPage.attr}"
completeMethod="#{testPage.completeMethod}"
var="item"
itemLabel="#{item}"
itemValue="#{item}" />
</h:form>
</h:body>
</f:view>
マネージドBean TestPage.xhtml
@ManagedBean(name = "testPage")
@ViewScoped
public class TestPage {
private String attr;
@PostConstruct
public void init(){
attr = "value 1";
}
public String getAttr() {
return attr;
}
public void setAttr(String attr) {
this.attr = attr;
}
public List<String> completeMethod(String query) {
return Arrays.asList(new String[]{"1111", "2222", "3333"});
}
}
このアプローチを示して下にtestPage.xhtml上で直接オートコンプリートを使用して正常に動作します。次のコードに示したようしかし、私は
は
<ui:component xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface componentType="elementComponent">
</cc:interface>
<cc:implementation>
<p:autoComplete
value="#{cc.attr}"
completeMethod="#{cc.completeMethod}"
var="item"
itemLabel="#{item}"
itemValue="#{item}" />
</cc:implementation>
</ui:component>
ElementComponent複合バッキング
@FacesComponent("elementComponent")
@ViewScoped
public class ElementComponent extends UIInput implements NamingContainer{
private String attr;
@Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
public List<String> completeMethod(String query) {
return Arrays.asList(new String[]{"value 1", "value 2", "value 3"});
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
attr = "value 1";
}
public String getAttr() {
return attr;
}
public void setAttr(String attr) {
this.attr = attr;
}
}
複合ページelement.xhtml、要素複合で、このオートコンプリートをラップしたいですしかし、要素のコンポジットをtestPage.xhtmlに含めると、オートコンプリートはあらかじめ選択された値を表示しません(直接実装とは異なります)。これを解決する方法はありますか?たぶんFacesComponentの実装でメソッドや属性が欠落している可能性がありますか?私はこれがプライムインタフェースの実装とコンポジットの実装の間のバグだと思う傾向がありますが、わかりません。