25

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Pranjali
  • 535
  • 1
  • 8
  • 19

1 Answers1

37

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.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you for your answer ! I was not aware that jQuery selectors can be used in Primefaces update attribute. – Pranjali Sep 27 '12 at 11:58
  • would that syntax submit other forms on the page as well? – Aksel Willgert Dec 28 '12 at 21:56
  • 1
    If you want to update two elements this way PF3.5 for some reason does not allow to use ``update="@(form :not(.noupdate)),otherPanel"`` (throws exception) but allows ``update="otherPanel,@(form :not(.noupdate))"`` – wst Aug 22 '13 at 09:54
  • @BalusC I am getting 'Cannot find component with identifier "noupdate"' when i use this approach. I am using .noupdate class for dialog component. Is that allowed ? If not, is there any way to exclude dialog component from updating when its parent is updated? – hendrix Nov 15 '13 at 13:21
  • @smitalm: apparently you're not using a minimum of PrimeFaces 3.3, or the problem is caused elsewhere. Re-read the answer, it clearly states a minimum of PrimeFaces 3.3. If you still stucks, just press "Ask Question" button on right top. – BalusC Nov 15 '13 at 13:27
  • 2
    @BalusC I am using v3.5. Thank you for quick tutorial on how to ask question, it was really helpful. – hendrix Nov 15 '13 at 13:31
  • 2
    How to do the same thing with only JSF ? – emeraldhieu Dec 11 '14 at 05:47
  • @BalusC hey man im trying to use this on a remotecommand in PF 7.0, but not working I don't get if you call the :not on the styleclasses or the ids of the components? im trying update="@(form :not(.accordion:tabRecaudo:formRecaudo:selectOneMenuCuenta))" but no success, those are the ids mate, im updating formRecaudo, but I don't want it to update the selectOneMenuCuenta – BugsForBreakfast Sep 12 '19 at 17:02
  • @BugsForBreakfast: click through the "See also" links to get answers to any releated questions like the one you have right now. Your syntax indeed doesn't make sense and the abovelinked "See also" link explains how exactly it works. – BalusC Sep 13 '19 at 08:30
  • Am I right to believe that we need double backslash, eg. : `@(#form\\:myPanel :not(.noupdate))`? – ForguesR Jun 30 '21 at 13:28