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

相关推荐
亓才孓4 分钟前
[JDBC]PreparedStatement替代Statement
java·数据库
_F_y26 分钟前
C++重点知识总结
java·jvm·c++
打工的小王27 分钟前
Spring Boot(三)Spring Boot整合SpringMVC
java·spring boot·后端
毕设源码-赖学姐29 分钟前
【开题答辩全过程】以 高校体育场馆管理系统为例,包含答辩的问题和答案
java·spring boot
我真会写代码30 分钟前
SSM(指南一)---Maven项目管理从入门到精通|高质量实操指南
java·spring·tomcat·maven·ssm
vx_Biye_Design31 分钟前
【关注可免费领取源码】房屋出租系统的设计与实现--毕设附源码40805
java·spring boot·spring·spring cloud·servlet·eclipse·课程设计
DN金猿36 分钟前
接口路径正确,请求接口却提示404
java·tomcat
Maynor9961 小时前
OpenClaw 玩家必备:用 AI 自动追踪社区最新动态
java·服务器·人工智能
堕2741 小时前
java数据结构当中的《排序》(一 )
java·数据结构·排序算法
亓才孓2 小时前
[Class的应用]获取类的信息
java·开发语言