正确使用primefaces的process和update

process属性作用于服务端,用于指定在表单提交或Ajax请求时,哪些组件需要在JSF的生命周期中被处理。它有以下几个值:

  • @this:表示只处理当前组件。
  • @form:表示处理当前表单内的所有组件。

update属性作用于客户端,用于指定在Ajax请求完成后,HTML DOM树的哪些部分需要被更新以响应表单的提交或组件的变化。它有以下几个值:

  • @this:表示只更新当前组件。
  • @form:表示更新当前表单内的所有组件。
  • 组件ID,表示更新指定ID的HTML元素。

下面讲一个具体的示例。

XML 复制代码
<h:form id="dialogs">
    <p:dialog header="计量单位" showEffect="fade" modal="true" widgetVar="manageUnitDialog"
              closeOnEscape="true"  position="center" styleClass="s-360">               
        <p:outputPanel id="manage-unit-content">
            <p:outputPanel rendered="#{not empty unitBacking.current}">
                <div class="formgrid grid ui-fluid">
                    <div class="col-12 md:col-12 lg:col-12">
                        <div class="field">
                            <p:outputLabel for="name" >单位名称</p:outputLabel>
                            <p:inputText id="name" value="#{unitBacking.current.name}" autocomplete="off"/>
                            <h:message for="name" class="error"/>
                        </div>
                    </div>
                </div>
            </p:outputPanel>
        </p:outputPanel>
        <p:hotkey bind="ctrl+s" update="form:messages" action="#{unitBacking.save()}"/>
        <f:facet name="footer">
            <div class="dialog-header-button-bar">
                <p:commandButton value="保存" icon="pi pi-save" 
                                 actionListener="#{unitBacking.save}" 
                                 process="@form" 
                                 update="dialogs:manage-unit-content"/>
                <p:commandButton value="取消" icon="pi pi-times" onclick="PF('manageUnitDialog').hide()"
                                 styleClass="ui-button-secondary" type="button" />
            </div>
        </f:facet>
    </p:dialog>
    
    
    <p:confirmDialog widgetVar="deleteUnitDialog" showEffect="fade" closeOnEscape="true"
                     message="删除后不可恢复,请谨慎操作......" header="提示" severity="warn">                
        <p:commandButton value="删除" icon="pi pi-trash"
                         actionListener="#{unitBacking.delete(unitBacking.current.id)}"
                         process="@this"
                         oncomplete="PF('deleteUnitDialog').hide()"
                         styleClass="ui-button-danger"/>
        <p:commandButton value="取消" type="button"  icon="pi pi-times"
                         onclick="PF('deleteUnitDialog').hide()" styleClass="ui-button-secondary"/>
    </p:confirmDialog>
</h:form>

actionListener表示仅在当前页面上操作,不跳转页面;若要跳转页面则使用action。

process="@form" 表示处理事个表单,用于在修改数 据、添加数据 等操作。在保存、更新按钮用@form。

update="dialogs:manage-unit-content" 表示与表单验证结合,若没有此选项则表单验证失效。update的值是面板的ID值。

process="@this" 表示后台处理,不需要处理整个表单,通常用于删除某条记录、修改某条记录前加载它。在修改按钮删除按钮用@this。

相关推荐
多多*2 分钟前
计算机网络相关 讲一下rpc与传统http的区别
java·开发语言·网络·jvm·c#
源码获取_wx:Fegn08954 分钟前
计算机毕业设计|基于springboot + vue网上超市系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·spring·课程设计
码农水水5 分钟前
阿里Java面试被问:Online DDL的INSTANT、INPLACE、COPY算法差异
java·服务器·前端·数据库·mysql·算法·面试
小旭95276 分钟前
【Java 基础】IO 流 全面详解
java·开发语言
Coder_Boy_9 分钟前
基于SpringAI的在线考试系统-阅卷评分与错题管理模块回归测试逻辑梳理文档
java·spring boot·系统架构·ddd·tdd·全栈开发
那起舞的日子10 分钟前
Java线程池-执行顺序
java
先做个垃圾出来………10 分钟前
Linux/Unix系统下的基础文本处理命令
java·linux·unix
风若飞11 分钟前
Linux 环境下解决 Tomcat8 与 JDK8 配置问题
java·linux·运维·服务器·tomcat
ONExiaobaijs12 分钟前
Java jdk运行库合集
java·开发语言·python
Coder_Boy_23 分钟前
基于SpringAI的在线考试系统-教学管理与用户管理模块联合回归测试文档
java·前端·数据库·人工智能·spring boot