How to find out ID for ajax render using two composite?

138 views Asked by At

I have two composites and I need to render the field in the second composite when I change the name of the car, but shows this error:

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

Follow the code: 1ª composite 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ª composite 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>

The 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}" />

And BeanController.java

private Car car;
private Client client;

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

//getters and setters

If I change the

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

to

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

doesn't work too.

I can't call to render @all or @form because there are others fields that I want to render.

Edited: Resolution

@BalusC I appreciated your comment, but your answer in other question didn't work to me. It was necessary to implement my code dynamically. Look at bellow.

In my car.xhtml composite I take off the render of ajax

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

And in my BeanController.java I implemented the clear method like this.

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;
}
0

There are 0 answers