正确使用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。

相关推荐
染翰15 小时前
Nacos 切换 Namespace 后配置不生效、占位符报错终极复盘
java·后端·spring·nacos
terry60015 小时前
2026图形验证码服务商横向测评|口碑、接入、安全选型全指南
java·大数据·人工智能·web安全·信息与通信·数据库架构
阿坤带你走近大数据15 小时前
java中泛型不能用基础数据类型
java·开发语言
skywalker_1115 小时前
SpringBoot速通(实战教学)
java·spring boot·redis·rpc·ssm·mybatis-plus
云絮.15 小时前
增删改查操作
java·开发语言
阿坤带你走近大数据15 小时前
Linux中管道符的作用
java·linux·服务器
码不停蹄的玄黓15 小时前
Spring Boot 实现过滤器(Filter)三种常用方式
java·spring boot·后端
dualven_in_csdn15 小时前
一键起飞调用示例
android·java·javascript
TPBoreas16 小时前
AQS 是啥
java·开发语言
宋哥转AI16 小时前
@Tool写了但tools/list为空?Spring AI MCP Server注册的两种路径和四个坑
java·agent·mcp