I have this simple SSCCE:
<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test</title>
</h:head>
<h:body>
<p:panel id="button_panel" widgetVar="testPanel" closable="true" toggleable="true">
<h1>Testing</h1>
</p:panel>
<p:commandButton onclick="PF('testPanel').show()" value="Show Panel" type="button"/>
<p:commandButton onclick="PF('testPanel').hide()" value="Hide Panel" type="button"/>
</h:body>
</html>
But when I browse to it and click the hide button I receive "TypeError: PF(...).hide is not a function" in my browsers Javascript console. I am using Primefaces 6.2 and the HTML generated by JSF above is:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<link type="text/css" rel="stylesheet"
href="/AnnotateImages/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo" />
<link type="text/css" rel="stylesheet"
href="/AnnotateImages/javax.faces.resource/fa/font-awesome.css.xhtml?ln=primefaces&v=6.2" />
<link type="text/css" rel="stylesheet"
href="/AnnotateImages/javax.faces.resource/components.css.xhtml?ln=primefaces&v=6.2" />
<script type="text/javascript"
src="/AnnotateImages/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.2">
</script>
<script type="text/javascript"
src="/AnnotateImages/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=6.2">
</script>
<script type="text/javascript"
src="/AnnotateImages/javax.faces.resource/core.js.xhtml?ln=primefaces&v=6.2">
</script>
<script type="text/javascript"
src="/AnnotateImages/javax.faces.resource/components.js.xhtml?ln=primefaces&v=6.2">
</script>
<script type="text/javascript">
if(window.PrimeFaces){PrimeFaces.settings.locale='en_GB';}</script>
<title>Test</title>
</head>
<body>
<div id="button_panel"
class="ui-panel ui-widget ui-widget-content ui-corner-all"
data-widget="testPanel">
<div id="button_panel_content"
class="ui-panel-content ui-widget-content">
<h1>Testing</h1>
</div>
<input type="hidden" id="button_panel_collapsed"
name="button_panel_collapsed" value="false" />
<input type="hidden" id="button_panel_visible"
name="button_panel_visible" value="true" />
</div>
<script id="button_panel_s" type="text/javascript">
PrimeFaces.cw("Panel","testPanel",{id:"button_panel",toggleable:true,toggleSpeed:500,collapsed:false,toggleOrientation:"vertical",toggleableHeader:false,closable:true,closeSpeed:500});</script>
<button id="j_idt6" name="j_idt6"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
onclick="PF('testPanel').show()" type="button">
<span class="ui-button-text ui-c">Show Panel</span>
</button>
<script id="j_idt6_s" type="text/javascript">
PrimeFaces.cw("CommandButton","widget_j_idt6",{id:"j_idt6"});</script>
<button id="j_idt7" name="j_idt7"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
onclick="PF('testPanel').hide();" type="button">
<span class="ui-button-text ui-c">Hide Panel</span>
</button>
<script id="j_idt7_s" type="text/javascript">
PrimeFaces.cw("CommandButton","widget_j_idt7",{id:"j_idt7"});</script>
</body>
</html>
I have also checked the slightly similar SO question PrimeFaces TypeError: PF(...) is undefined but none of the answers seem to apply. Therefore I am posting this here under the assumption that it has a different cause.
If I type PF('testPanel') in my JS console I get:
Object { _super: undefined, cfg: {…}, id: "button_panel", jqId: "#button_panel",
jq: Object(1), widgetVar: "testPanel", header: {…}, title: {…},
content: Object(1), toggler: {}, …
}