我想在页面加载后执行JavaScript函数.目前我有一个commandButton,一切正常.然而,如果用户不应该按下按钮会更舒服.
我试过f:event,但是我没有监听器,我只有JavaScript函数.此外,body onload对我不起作用,因为我只使用高级组件.
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:pm="http://primefaces.org/mobile" contentType="text/html">
<ui:composition template="/resources/master.xhtml">
<ui:define name="content">
<pm:content>
<h:inputHidden id="address" value="#{pathFinderBean.address}" />
<div id="map" style="width: 100%; height: 285px;"></div>
<p:commandButton type="button" value="Route" onclick="PathFinder.findAndGo()"/>
<div id="route"></div>
</pm:content>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
JavaScript函数PathFinder.findAndGo在我的master.xhtml中定义