Pranjali Pranjali - 2 months ago 68
Ajax Question

How to exclude child component in ajax update of a parent component?

I am using PrimeFaces

<p:ajax>
tag in my code. How we can exclude a child component from getting updated in an ajax call that update a parent component?

Answer

If you're using at least PrimeFaces 3.3, then you can use PrimeFaces Selectors for this. This allows you using jQuery CSS selector syntax in process and update attributes of PrimeFaces ajax components.

For example:

<h:form>
    <h:inputText ... />
    <h:inputText ... />
    <h:inputText ... styleClass="noupdate" />
    <h:inputText ... />
    <h:inputText ... />
    <p:commandButton ... update="@(form :not(.noupdate))"/>
</h:form>

This example will update the entire form except for inputs having class="noupdate" in the client side.

If you want to update a all children of a certain component except one, replace 'form' by the id of the surrounding component (or a class or...)

<h:form id="form">
    <h:panel id="myPanel">
        <h:inputText ... />
        <h:inputText ... />
        <h:inputText ... styleClass="noupdate" />
    </h:panel>
    <h:inputText ... />
    <h:inputText ... />
    <p:commandButton ... update="@(form :not(.noupdate))"/>
</h:form>

<p:commandButton ... update="@(#form\:myPanel :not(.noupdate))"/>

Just make sure you use the full client-side id.

Comments