1

2 つのコンポジットがあり、車の名前を変更するときに 2 番目のコンポジットでフィールドをレンダリングする必要がありますが、次のエラーが表示されます。

<f:ajax> contains an unknown id 'nameCli' - cannot locate it in the context of the component nameCar.

コードに従ってください: 1ª コンポジット car.xhtml

<composite:interface>
    <composite:attribute name="id" required="true" type="java.lang.String" />
    <composite:attribute name="nameCar" />
    <composite:attribute name="clear" method-signature="java.lang.String action()" />
</composite:interface>

<composite:implementation>
    <label>Car:</label>
    <h:inputText id="nameCar" value="#{cc.attrs.nameCar}">
        <!-- Here is the ajax that call the method 'clear' when the inputText changed -->
        <f:ajax listener="#{cc.attrs.clear}" event="change" render="nameCli ageCli" />
    </h:inputText>
</composite:implementation>

2ª 複合 client.xhtml

<composite:interface>
    <composite:attribute name="id" required="true" type="java.lang.String" />
    <composite:attribute name="nameCli" />
    <composite:attribute name="ageCli" />
</composite:interface>  

<composite:implementation>
    <label>Client's Name:</label>
    <h:inputText id="nameCli" value="#{cc.attrs.nameCli}" />
    <label>Age:</label>
    <h:inputText id="ageCli" value="#{cc.attrs.ageCli}" />
</composite:implementation>

プリンシパル.xhtml

<proj:car id="car" nameCar="#{beanController.car.name}" clear="#{beanController.clear}" />
<proj:client id="client" nameCli="#{beanController.client.name}" ageCli="#{beanController.client.age}" />

そして BeanController.java

private Car car;
private Client client;

public String clear() {
    client.setName(null);
    client.setAge(null);
    return null;
}

//getters and setters

私が変更した場合

<f:ajax listener="#{cc.attrs.clear}" event="change" render="nameCli ageCli" />

<f:ajax listener="#{cc.attrs.clear}" event="change" render=":client:nameCli :client:ageCli" />

も機能しません。

他にもレンダリングしたいフィールドがあるため、@all または @form をレンダリングするために呼び出すことができません。

編集:解像度

@BalusCコメントに感謝しますが、他の質問でのあなたの答えはうまくいきませんでした。コードを動的に実装する必要がありました。以下を見てください。

私のcar.xhtmlコンポジットでは、ajaxのレンダリングを外します

<f:ajax listener="#{cc.attrs.clear}" event="change" />

そして、私の BeanController.java では、このような clear メソッドを実装しました。

public String clear() {
    client.setName(null);
    client.setAge(null);

    // Get the fields
    UIInput uiNameCli = (UIInput) FacesContext.getCurrentInstance().getViewRoot().findComponent("myForm:client:nameCli");
    UIInput uiAgeCli = (UIInput) FacesContext.getCurrentInstance().getViewRoot().findComponent("myForm:client:ageCli");

    FacesContext context = FacesContext.getCurrentInstance(); // Update the fields.
    context.getPartialViewContext().getRenderIds().add(uiNameCli.getClientId(context));
    context.getPartialViewContext().getRenderIds().add(uiAgeCli.getClientId(context));

    return null;
}
4

0 に答える 0