我想在页面加载后执行一个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>
JavaScript函数PathFinder.findAndGo在我的master.xhtml文件中定义。