当你定义 f:ajax 时,试着给出你想要执行和更新的 UI 组件。也给事件。如果要处理整个表单并更新整个页面,可以在 f:ajax 中使用 @form 和 @all。
@form 和 @all 与 f:ajax 的示例如下。
<h:form>
<p:selectOneMenu id="cmb" value="#{investigationItemController.current}" >
<f:selectItem itemLabel="Please select an item" />
<f:selectItems value="#{investigationItemController.items}" var="ii" itemLabel="#{ii.name}" itemValue="#{ii}" />
<f:ajax event="change" execute="@form" render="@all"/>
</p:selectOneMenu>
<h:outputLabel id="lbl" value="#{investigationItemController.current}" />
</h:form>
primefaces ajax 命令的示例如下。
<h:form>
<p:selectOneMenu id="cmb" value="#{investigationItemController.current}" >
<f:selectItem itemLabel="Please select an item" />
<f:selectItems value="#{investigationItemController.items}" var="ii" itemLabel="#{ii.name}" itemValue="#{ii}" />
<p:ajax event="change" process="cmb" update="lbl"/>
</p:selectOneMenu>
<h:outputLabel id="lbl" value="#{investigationItemController.current}" />
</h:form>
如果我们想要为多个事件执行逻辑,我们可以添加多个或一个 UI 组件。
从以“on”开头的 UI 组件的属性列表中删除“on”后,可以获取标准 JSF UI 组件的事件。例如,如果 JSF UI 支持 onChange 作为属性,您可以使用 event="change"。对于 primefaces UI 组件,可能的事件列在 Primefaces 文档下。正确选择事件对于成功的 ajax 响应至关重要。