jsf刷新页面

When the user requests for a page, the lifecycle of JSF begins. JavaServer faces builds the current view from the previously saved state which is infact from the state of the submission of the previous page. The framework performs certain tasks like validating the inputs fields of the page, generating response and so on.

当用户请求页面时,JSF的生命周期开始。 JavaServer faces从先前保存的状态构建当前视图,而先前保存的状态实际上是从上一页提交的状态开始的。 该框架执行某些任务,例如验证页面的输入字段,生成响应等。

JSF Life cycle involves six phases namely

JSF生命周期涉及六个阶段,即

  1. Restore view phase恢复视图阶段
  2. Apply request values phase应用请求值阶段
  3. Process validations phase流程验证阶段
  4. Update model values phase更新模型值阶段
  5. Invoke application phase调用应用程序阶段
  6. Render response phase渲染响应阶段

Lets look in detail to each of these phases.

让我们详细查看每个阶段。

  1. Restore view phase: Whenever a request arrives, this is the first phase that gets initiated. When the request arrives – that is, when a button or a link is clicked, jsf builds the view, prepares the event handlers, validates the ui components and saves the view in a faces context. This faces context will have all the previous request’s information to process the current request. If the request is an initial one, the JSF creates an empty view and displays it to the user during a postback. If the postback view already exists, the information is popped out from the saved state.恢复视图阶段 :每当请求到达时,这就是启动的第一个阶段。 当请求到达时-即单击按钮或链接时,jsf生成视图,准备事件处理程序,验证ui组件并将视图保存在faces上下文中。 该面Kong上下文将具有所有先前请求的信息来处理当前请求。 如果请求是最初的请求,那么JSF将创建一个空视图并在回发期间将其显示给用户。 如果回发视图已经存在,则该信息将从已保存状态弹出。
  2. Apply request values: Once the components are restored from in the first phase, each component extracts its new value which might have been changed from the previous state through a decode method. The extracted value is then stored locally(native data type) along with the component. If the process of decoding fails, an error message is generated and stored in faces context for further action. If the components have their immediate JSF attributes set to true in the page then the events, validation and conversion related to the page will be processed. If any decode method calls the render response phase then the the control is redirected to render response phase itself.
    If the application needs to redirect to a different application it can call FacesContext.responseComplete. By the end of this phase the new values will be set and messages, events will be queued.应用请求值 :在第一阶段从组件还原后,每个组件都会提取其新值,该新值可能已通过解码方法从先前状态更改了。 然后将提取的值与组件一起存储在本地(本机数据类型)。 如果解码过程失败,则会生成错误消息并将其存储在face上下文中,以采取进一步的措施。 如果组件在页面中将其直接JSF属性设置为true,则将处理与页面相关的事件,验证和转换。 如果有任何解码方法调用渲染响应阶段,则控件将重定向到渲染响应阶段本身。
    如果应用程序需要重定向到其他应用程序,则可以调用FacesContext.responseComplete。 在此阶段结束时,将设置新值,并将消息,事件排队。
  3. Process validations phase: During this phase all the field related validations are processed and added to the component tree. Each and every rule is examined and compared with the values stored on the local component. If the values on the local component is invalid, error messages are registered in faces context and the same page is rendered again with the error message there by navigating to the render response phase.流程验证阶段 :在此阶段中,将处理所有与字段相关的验证,并将其添加到组件树中。 将检查每条规则,并将其与本地组件上存储的值进行比较。 如果本地组件上的值无效,则会在faces上下文中注册错误消息,并通过导航到渲染响应阶段,再次在该页面上显示该错误消息。
  4. Update model values phase: Since the Data validations are done in the validation phase now the corresponding server object properties are set and stored in the local components. The bean properties are updated to the corresponding input component attributes.更新模型值阶段 :由于数据验证是在验证阶段完成的,因此现在已设置了相应的服务器对象属性并将其存储在本地组件中。 Bean属性将更新为相应的输入组件属性。
  5. Invoke application phase: The events like submitting a form, click of a link are handled in this phase. If the processed views are reconstructed based on state information of previous request and if the event is fired it will be broadcasted to interested listeners. If redirection to different web application is invoked again the transition to response render phase takes place.调用应用程序阶段 :在此阶段处理诸如提交表单,单击链接之类的事件。 如果基于先前请求的状态信息重构了处理后的视图,并且如果触发了事件,则将其广播给感兴趣的侦听器。 如果再次调用重定向到另一个Web应用程序,则将过渡到响应呈现阶段。
  6. Render response phase: The Java Server Faces first checks whether it is a jsp page and if yes, the control is transferred to JSP Container. If the request is an initial one, the page is added to the component tree first and stored. If it is not an initial request, the component will already be stored and hence it just gets rendered. In either case the components will render themselves as the JSP container traverses the tags in the page. If any errors are encountered during this process the relevant messages are displayed. After the view is rendered the content will be stored so that when the same request arrives, it can be accessed and also be available for restore view phase.渲染响应阶段 :Java Server Faces首先检查它是否为jsp页面,如果是,则将控件转移到JSP容器。 如果该请求是初始请求,则该页面将首先添加到组件树并进行存储。 如果不是初始请求,则该组件将已经存储,因此将被渲染。 无论哪种情况,组件都将在JSP容器遍历页面中的标记时呈现。 如果在此过程中遇到任何错误,则会显示相关消息。 呈现视图后,将存储内容,以便在同一请求到达时可以对其进行访问,并且还可以用于还原视图阶段。

Lets consider an example to understand each phase.

让我们考虑一个例子来理解每个阶段。

A page is rendered where user can enter the car details like car id, name, color, model etc and then the entered details will be displayed in the browser.

呈现页面,用户可以在其中输入汽车详细信息,例如汽车ID,名称,颜色,型号等,然后输入的详细信息将显示在浏览器中。

The addDetailsPage.xhtml contains all the fields of the car into which the user can enter the details. The code for addDetailsPage is as follows.

addDetailsPage.xhtml包含用户可在其中输入详细信息的汽车的所有字段。 addDetailsPage的代码如下。

addDetailsPage.xhtml

addDetailsPage.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml"xmlns:h="https://xmlns.jcp.org/jsf/html"><h:head><title>Facelet Title</title></h:head><h:body><h:form><h:panelGrid columns="3"><h:outputLabel>Car Id:</h:outputLabel><h:inputText id="cid" value="#{car.id}"></h:inputText><br /> <br /><h:outputLabel>Car Name:</h:outputLabel><h:inputText id="cname" value="#{car.cname}"></h:inputText><br /> <br /><h:outputLabel for="color">Car color:</h:outputLabel><h:inputText id="color" value="#{car.color}"></h:inputText><br /> <br /><h:commandButton value="Reset"  action="#{car.clearAll}"></h:commandButton></h:panelGrid></h:form></h:body>
</html>

Create a Managed Bean Car.java as shown below.

如下所示创建一个Managed Bean Car.java。

package com.journaldev.jsf.beans;import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;@ManagedBean
@SessionScoped
public class Car {private String cname;private String Id;private String color;public String getColor() {return color;}public void setColor(String color) {this.color = color;}public String getCname() {return cname;}public void setCname(String cname) {this.cname = cname;}public String getId() {return Id;}public void setId(String Id) {this.Id = Id;}public void clearAll(){this.Id = "";this.cname = "";this.color="";}
}

Assume that the user enters https://localhost:8080/HelloWorld/faces/addDetailsPage.xhtml in the browser. Below are the execution steps.

假设用户在浏览器中输入https:// localhost:8080 / HelloWorld / faces / addDetailsPage.xhtml 。 以下是执行步骤。

Step 1: Since it is a initial request there is nothing to restore hence an empty view is created which is posted back.

步骤1 :由于这是初始请求,因此无法还原,因此创建了一个空视图并将其发回。

Step 2: The values entered by the user for car details are set here like car id=3, name=”Alto” and color=”blue”.

步骤2 :在此设置用户输入的汽车详细信息值,例如汽车ID = 3,名称=“ Alto”​​和颜色=“ blue”。

Step 3: Here the validations related to car id, name and color are checked. Since there are no validations set no processing is done here. Suppose, we make car id as mandatory and submit the page with the car id as null, the validator generates error messages and proceeds to the last step which is the render response.

步骤3 :此处检查与汽车ID,名称和颜色有关的验证。 由于没有设置验证,因此此处不进行任何处理。 假设我们将car id设为必选,并提交car id为null的页面,验证器将生成错误消息,并继续执行最后一步,即渲染响应。

Step 4: In the model phase the values from the page are extracted and inserted into the corresponding variables in the car bean. Clear all method is mapped and functionality of clear all is accomplished here if requested.

步骤4 :在模型阶段,将提取页面中的值并将其插入到car bean中的相应变量中。 清除全部方法已映射,如果需要,清除全部功能在此处完成。

Step 5: Here the click of reset button is handled. The view to be rendered is constructed here. This is the result of triggering a functionality in step 4. For example, when we clear the fields, the bean method is executed and the new view is constructed with all the field values set to null.

第5步 :此处处理了重置按钮的单击。 在此处构造要渲染的视图。 这是在步骤4中触发功能的结果。例如,当我们清除字段时,将执行bean方法,并使用所有字段值都设置为null的新视图。

Step 6: The view page addDetailsPage.xhtml with the final result and field values is rendered. In this example it is a page with all the fields set to blank values.

步骤6 :呈现具有最终结果和字段值的视图页面addDetailsPage.xhtml。 在此示例中,它是一个页面,其中所有字段都设置为空白值。

That’s all for the JSF Page Lifecycle Management, we will look into more of JSF features in coming posts.

这就是JSF Page Lifecycle Management的全部内容,我们将在以后的文章中探讨更多JSF功能。

翻译自: https://www.journaldev.com/6888/jsf-page-lifecycle-management

jsf刷新页面

jsf刷新页面_JSF页面生命周期管理相关推荐

  1. Android按键响应的几种方式、安卓页面的跳转、页面跳转传参、页面自动跳转、Activity(页面)的生命周期

    按键响应的第一种方式: 在XML文件里面设置按键的onClick绑定函数.就像下面的代码,给Button设置onClick属性,在按键被按下的时候,会调用java文件里面的onClickbtton1这 ...

  2. 索引生命周期管理ILM看完不懂你锤我

    阅读完本文你可以学到什么是索引生命周期管理,各个阶段可以做的操作以及如何使用索引模版使用索引生命周期策略,下面就跟我一起来吧 基础理论篇 索引生命周期管理(ILM)是一种可以让我们随着时间推移自动化的 ...

  3. 组件生命周期管理和通信方案

    随着移动互联网的快速发展,项目的迭代速度越来越快,需求改变越来越频繁,传统开发方式的工程所面临的一些,如代码耦合严重.维护效率低.开发不够敏捷等问题就凸现了出来.于是越来越多的公司开始推行" ...

  4. Android 插件化原理解析——Activity生命周期管理

    之前的 Android插件化原理解析 系列文章揭开了Hook机制的神秘面纱,现在我们手握倚天屠龙,那么如何通过这种技术完成插件化方案呢?具体来说,插件中的Activity,Service等组件如何在A ...

  5. Android apk动态加载机制的研究(二):资源加载和activity生命周期管理

    转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/23387079 (来自singwhatiwanna的csdn博客) 前言 为了 ...

  6. ASP.NET Core中的依赖注入(4): 构造函数的选择与服务生命周期管理

    ServiceProvider最终提供的服务实例都是根据对应的ServiceDescriptor创建的,对于一个具体的ServiceDescriptor对象来说,如果它的ImplementationI ...

  7. 谈AK管理之基础篇 - 如何进行访问密钥的全生命周期管理?

    简介: 我们也常有听说例如AK被外部攻击者恶意获取,或者员工无心从github泄露的案例,最终导致安全事故或生产事故的发生.AK的应用场景极为广泛,因此做好AK的管理和治理就尤为重要了.本文将通过两种 ...

  8. SPASVO 软件生命周期管理 ALM V2.1 正式发布!

    ALM是面向软件研发生命周期管理的工具,实现了从产品概念设计.需求分析.历经项目计划.项目进度.配置管理.工时管理.测试管理等阶段,直至项目完成的全过程管理. ALM V2.1新增功能模块如下: 1. ...

  9. 谈业务流程全生命周期管理支撑业务流程再造(3)

    5.如何使用业务流程全生命周期管理能力平台 在使用能力平台时,需要先了解流程能力平台生态环境. 生态环境说明如下: 生产环境:是按设计要求为全体用户提供生产支撑的信息系统环境,系统上所以业务应用都是经 ...

  10. Android RxJava生命周期管理解决方案整理

    一.为什么要做生命周期管理? Observable.create(new ObservableOnSubscribe<String>() {@Overridepublic void sub ...

最新文章

  1. 几个比较冷门的prototype扩展方法:去掉html标签、去掉a标签、去掉style样式,以及判断是否为html代码的代码片段
  2. 几种xml读取方法比较
  3. mysql中查询一个字段属于哪一个数据库中的哪一个表的方式
  4. CSS节选——选择器
  5. 629. K个逆序对数组
  6. linux shell 执行目录,bash shell脚本执行的几种方法
  7. 【华为云技术分享】如何度量前端项目研发效率与质量(上)
  8. nginx react vue location history 配置
  9. java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/Str
  10. Leetcode 刷题笔记(二十二) ——贪心算法篇之进阶题目
  11. 织梦采集侠自动采集伪原创发布设置
  12. 免费直播系统源码,可控的跑马灯,无需焦点
  13. ehvierwer登录与不登录_自媒体账号管理神器,多个平台同时登录,给你不一样的感觉...
  14. Chinese NER Using Lattice LSTM 论文解读
  15. [URL ]pixiv.net p站用户账号注销网页网址(电脑web版)
  16. 动图文件太大怎么办?一招教你在线压缩GIF图片
  17. Salesforce WhatsApp 集成
  18. 【Demo】银行主数据的修改
  19. win11右键如何直接打开所有选项
  20. 10年工作经验的程序猿年薪10万 多吗?

热门文章

  1. POJ 1050 To the Max (最大子矩阵和)
  2. Deploy Oracle 10.2.0.5 on Red Hat Enterprise Linux 6.4
  3. JQ简单二级导航,加子导航栏
  4. [转载] Python开发系列课程(16) - 进程和线程
  5. 高速收发器之8B/10B编码
  6. 避免使用PHP保留字作为常量、类名和方法名,以及命名空间的命名
  7. BootStrap--CSS组件
  8. [OpenGL]自己写的加载位图并转换成纹理的两个函数
  9. 那一次,我们属于彼此
  10. Linux常见问题三则:Executable Path Is Not Absolute