次のようなカスタムコンポーネントがあります
<custom:container>
<custom:checkbox index="0"/>
<custom:checkbox index="1"/>
</custom:container>
したがって、encodeBegin が最初に呼び出されると、タグが表示<custom:container>
され、このコンポーネントのクライアント ID を保存しようとします。
private String containerClientId;
public void encodeBegin(FacesContext context, UIComponent component){
if (component instanceof ManyCheckboxContainer) {
containerClientId = component.getClientId(context);
return;
}
}
<custom:checkbox index="0"/>
だから、このように、私がヒットしたときにencodeEndが呼び出されます
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
...
if (component instanceof Checkbox) {
renderCheckbox(context, (Checkbox) component);
}
...
}
protected void renderCheckbox(FacesContext facesContext, InforRadio radio) throws IOException {
...
UIComponent uiComponent = radio.findComponent(containerClientId);
if(uiComponent == null){
//throw error
}
...
}
複合コンポーネント内にこのカスタム コンポーネントがない場合は、すべて正常に機能しますが、複合コンポーネントに配置するとradio.findComponent(containerClientId);
、null
. これはモハラのバグですか?これを 2.1.10 と 2.1.11 でテストしましたが、同じ動作です。
編集
それを元に戻します。この動作は、カスタムコンポーネントが2つのネストされた内部にある場合に発生するNamingContainer
ため、次のようなものです
<h:form id="myForm">
<f:subView id="myView">
<custom:container id="myCustom">
<custom:checkbox index="0"/>
<custom:checkbox index="1"/>
</custom:container>
</f:subView>
</h:form>
したがって、この場合、クライアントID(によって返されるcomponent.getClientId(context)
)は<custom:container>
ですがmyForm:myView:myCustom
、Mojarra内では、findComponent
メソッドにはこれがあります
public UIComponent findComponent(String expr) {
...
else if (!(base instanceof NamingContainer)) {
// Relative expressions start at the closest NamingContainer or root
while (base.getParent() != null) {
if (base instanceof NamingContainer) {
break;
}
base = base.getParent();
}
...
}
そのため、次の祖先を探します。NamingContainer
これは、私の場合は ではありf:subView
ませんh:form
。次に、クライアント ID を解析し、ID の一部を に渡すたびにループしますUIComponent findComponent(UIComponent base, String id, boolean checkId)
。したがって、初めて、このメソッドは id として取得され、現在の UIComponent は f: subViewであり、すべてのファセットと子を検索して、form3
一致するコンポーネントがあるかどうかを確認します。リターンも同様です。これは Mojarra のバグですか、それとも私が間違っているのでしょうか。クライアント ID は、NamingContainer のルートまでではなく、次の NamingContainer の祖先から相対的だと思いましたか? 私はそれについて間違っていますか?form3
form3
f:subView
null