0

I'm on the process of migrating an application from PrimeFaces 3.5 to 7.0, right now I have already make alot of things work but alot other I have no clue whats going on ;p

Currently I found out that I have a problem with this code:

<!-- <!DOCTYPE html> -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head/>

<h:body onload="actualizarSaldosCajero();" >
    <h:form>
        <p:remoteCommand name="actualizarSaldosCajero"
            onstart="PF('ajaxStatus').show();"
            action="#{plantillaGeneralMB.actualizarSaldosCajero}" />
    </h:form>

    <p:dialog widgetVar="ajaxStatus">
       Content
    </p:dialog>
</h:body>
</html>

Managed bean:

  @ManagedBean
  @SessionScoped
  public class PlantillaGeneralMB implements Serializable {

    private static final long serialVersionUID = 1L;

    public void actualizarSaldosCajero() throws Exception {
            try {
                System.out.println("Here is alot of java code but not needed to reproduce error which is just on loading or refreshing the xhtml");

            } catch (Exception e) {
                throw e;
            }
        }
   }

when I run my program with that code I get this error on navigator console:

TypeError: PF(...) is undefined

and if I open the trace it goes to onload() method, so searching I found this:

Execute managebean method from javascript onload event

which tells that if using PrimeFaces I can use autoRun="true" attribute on my remoteCommand instead of using the onload(), so thats what I did changed the remoteCommand to this:

<p:remoteCommand autoRun="true" name="actualizarSaldosCajero"
    onstart="PF('ajaxStatus').show();"
    action="#{plantillaGeneralMB.actualizarSaldosCajero}" />

but now on my navigator console I still get the same error but now I also get that warning on the title, and the stacktrace of the error

"TypeError: PF(...) is undefined"

ends on JQUERY 2.

Hope some kind of advice for solving these, I gotta add that I'm not manually adding any JQuery to my xhtmls because I read that PrimeFaces already has its own JQuery (See answer from BalusC Adding jQuery to PrimeFaces results in Uncaught TypeErrors)

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
BugsForBreakfast
  • 712
  • 10
  • 30
  • Can you post a [mcve] including `h:head`, no template etc... – Kukeltje Jul 13 '19 at 09:44
  • @Kukeltje Hmm I will post the most important part of the code which makes the error appear I think, its 2 xhtml, one calls the other. give me momentss – BugsForBreakfast Jul 13 '19 at 13:34
  • @Kukeltje added some code mate thats like summary of what I have, the error just appear when loading the page of another.xhtml, but it got fixed with the PF('') on the actualizarSaldosCajero() call, if you call it normal then the error appears – BugsForBreakfast Jul 13 '19 at 13:58
  • Hi, it is all about creating a [mcve]. Way to much code now. Creating a [mcve] is the best thing to troubleshoot/debug. only then it is 'easy' to try to reproduce. Thanks – Kukeltje Jul 13 '19 at 15:54
  • Hmmm its hard in this case mate :,v but you don't have any guess why it doesn't work without the PF()? – BugsForBreakfast Jul 14 '19 at 00:28
  • well, the code does not run on my side (I did not even try, sice know it will fail with 404 and js errors and more) So you are saying you can't remove any of the javascript and css in plantillaGeneral.xhtml? Or the dialog in it? and if you put the code from the template in the page? I'm 100% sure you can do this without a lot of efforrt – Kukeltje Jul 14 '19 at 06:10
  • @Kukeltje okay I will remove them and repost tomorrow at work station mate, ty for patience – BugsForBreakfast Jul 14 '19 at 13:50
  • @Kukeltje Hey mate, removed the javascript and css, please tell me if that works as a reproducible example if not I will add or remove more :) the error of title appears when you just load the xhtml no need to execute anything, just the onload() will bring the error. – BugsForBreakfast Jul 15 '19 at 16:46
  • I mentioned more ;-) the template, what if you don't use one? But it comes close. I'll see what I can try – Kukeltje Jul 15 '19 at 17:05
  • @Kukeltje okay bro tell me if anything :) – BugsForBreakfast Jul 15 '19 at 21:23
  • I just tried your code (you can remove the `another.xhtml` from the question now since it is not used, calling the `plantillaGeneral.xhtml` will produce the same error.) But... Effectively it is not a [mcve]. Tried changing (removing) more in the `p:remoteCommand`? Simplify the `onstart`? e.g. putting a `console.log('onload');` in there. – Kukeltje Jul 16 '19 at 07:48
  • 1
    Possible duplicate of [Access to primefaces widgetvars on document ready](https://stackoverflow.com/questions/23060768/access-to-primefaces-widgetvars-on-document-ready) – Kukeltje Jul 16 '19 at 09:07

0 Answers0