【发布时间】:2012-02-18 06:13:39
【问题描述】:
我想在页面加载后执行一个 JavaScript 函数。目前我有一个命令按钮,一切正常。但是,如果用户不应该点击按钮会更舒服。
我试过 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>
我的master.xhtml中定义了JavaScript函数PathFinder.findAndGo
【问题讨论】:
-
您更愿意在准备好的情况下而不是在加载状态下进行操作吗?
-
如果你的脚本在头部并且按钮在页面中,那么脚本总是会在元素出现之前被加载。但是,如果脚本要求页面中包含某些元素,并且用户可以在加载之前单击按钮,则您可能会考虑禁用按钮(或采取其他操作),直到它们可用为止。
-
将 remoteCommand 与 autorun true 一起使用。
标签: javascript jsf-2 primefaces onload