PrimeFaces 7.0 Ajax Update Warning

Viewed 2131

I am getting this warning org.primefaces.PrimeFaces$Ajax.update PrimeFaces.current().ajax().update() called but component can't be resolved!Expression will just be added to the renderIds. Sometimes when using PrimeFaces.current().ajax().update I get the above warning, searching I implemented this solution https://forum.primefaces.org/viewtopic.php?t=58678

public static UIComponent findComponentById(String componentId) {
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot root = context.getViewRoot();
    return root.findComponent(componentId);
}

So to avoid getting the warning I do the following:

        if (FacesUtils.findComponentById("pnlEstado") != null) {
            PrimeFaces.current().ajax().update("pnlEstado");
        }

And it works, it does no longer throw the warning because component is always "findable" for updating.

The problem here is that my partner said he isn't sure if this is the best way to handle the warning because he thinks it will take alot of time when this is in production for it to execute, he said like this goes to client then comebacks to server then again to client, how this works he asked, and I didn't really know how to explain but the thing is I think this is the best way to handle it, want to know your opinion about it.

I also tried with binding component and checking if it is rendered but it is always true that it is rendered so it always updates and throws warning.

So I removed bindings and used this way. Also this only happens because I have 2 menus, when 1 is open the other one is not displayed, so I think thats why the update throws warning sometimes, but the solution I implemented solves it, anyways im open to your opinions.

Also this is the way he said he prefers me to solve it, im gonna try it https://forum.primefaces.org/viewtopic.php?t=32040

But I think its better with the one I want to use

1 Answers

The warning happens because the component for the given IDs can't be resolved in the current ViewRoot. For the same reason, your FacesUtils.findComponentById returns null.

In PrimeFaces we just added this warning to inform the user, that the component to be updated, is likely not there and/or wont be updated. This can of course lead to a unexpected behavior for the developer.

So your FacesUtils.findComponentById is just a hack which leads to worse performance, as 'viewRoot.findComponent' will be called twice when the component is available.

The only real solution is to only call PrimeFaces.current().ajax().update() if you know that the component is rendered. Your view bean/controller should know the current state. Otherwise just ignore the warning.

Related