2

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

BugsForBreakfast
  • 712
  • 10
  • 30
  • Did you check client side what the ID is of this component?. Did you try removing the update all together? Application still working? – Kukeltje Oct 17 '19 at 15:56
  • @Kukeltje I will try removing the update all together, its the id of a whole form that contains panels, I will check what happens – BugsForBreakfast Oct 17 '19 at 15:59
  • @Kukeltje If I remove the updates, menu won't display and also "amount of cash" of the user won't be displayed and constantly updated on the top of the menu, I need them =/, but look down at my discussion with tandraschko, think I will have to wait for 7.1 release, meanwhile I will use the solution of my question :) – BugsForBreakfast Oct 18 '19 at 16:14

1 Answers1

6

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.

tandraschko
  • 2,291
  • 13
  • 13
  • But the problem is this update is called inside methods, that are executed in the postconstruct of a class, and this methods are executed again depending of what user does after postconstruct, but I can't evaluate if they are rendered via binding because it always returns true, but the update still throws the warning, what about this other solution? https://forum.primefaces.org/viewtopic.php?t=32040 – BugsForBreakfast Oct 17 '19 at 14:12
  • I just want to ignore the warning but the stacktrace is really big =/ – BugsForBreakfast Oct 17 '19 at 14:15
  • There is no solution in a "framework level". You likely render your `pnlEstado` based on a condition (rendered=#{myBean.something}). Based on the same condition you can call `PrimeFaces.current().ajax().update()` or not. – tandraschko Oct 17 '19 at 14:15
  • Not really, the thing is like this: I have a menu which is the "main" menu, it is pnlEstado, this pnlEstado is visible right, but then when you click a button on main Menu, it hides, it used display:none. And then another Menu called pnlEstadoSimple displays, and I update both of them, but then the warning is throw wherever pnlEstado is not displayed or pnlEstadoSimple isn't, thats why mate (I didn't do this, it is made like that lol) – BugsForBreakfast Oct 17 '19 at 14:17
  • 1
    I can't follow for 100% but if you hide them via css, the component is still in the ViewRoot available and should not log a warning. We could also introduce something like: `PrimeFaces.current().ajax().tryUpdate()`, which just ignores such warnings and don't log it. – tandraschko Oct 17 '19 at 14:20
  • Yes mate it is hided via css, that why it always says rendered true right? But still throws the warning =/, it would be cool for the tryUpdate() method, so right now best option is to ignore the warning, what about the link I posted above? updating via widgetVars, I can add widgetvars to the panel menus and try that – BugsForBreakfast Oct 17 '19 at 14:28
  • If the update works via widgetVar, then you just have the wrong selector/id as both should resolve to a existing component ;) There is no problem with the our update method then. Thats related to: https://stackoverflow.com/questions/8634156/how-to-find-out-client-id-of-component-for-ajax-update-render-cannot-find-compo – tandraschko Oct 17 '19 at 18:11
  • The client id is well referenced, I know because when I find it I use the methods to getClientId and also getContainerClientId(context), and they both print the id im using mate. I was working in another things, tomorrow I will try javascript update and tell you how it goes, the tryUpdate will be helpful to not show that warning hehe – BugsForBreakfast Oct 17 '19 at 21:25
  • 2
    https://github.com/primefaces/primefaces/issues/5251 i now reduced the warning to ProjectStage==Development and removed the stacktrace. – tandraschko Oct 18 '19 at 07:49
  • Thanks man, to see this enhancement I have to update from 7.0 to 7.1 PrimeFaces version right? – BugsForBreakfast Oct 18 '19 at 13:19
  • Okay hope it happens soon :), meanwhile I will sacrifice some performance for it – BugsForBreakfast Oct 18 '19 at 13:43