我有两个复合材料,当我更改汽车名称时,我需要在第二个复合材料中渲染该字段,但显示此错误:
<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>
principal.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;
}