`javax.faces.event` 是 JavaServer Faces (JSF) 框架中的一个包,它包含了与事件处理相关的类和接口

本文详细介绍了JavaServer Faces(JSF)中的事件与监听器机制,包括各种事件如ActionEvent、ValueChangeEvent等,以及监听器如ActionListener、ValueChangeListener等。此外,还探讨了系统事件(SystemEvent)和组件系统事件(ComponentSystemEvent)的概念及其具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

javax.faces.event 是 JavaServer Faces (JSF) 框架中的一个包,它包含了与事件处理相关的类和接口。JSF 是一个用于构建基于组件的用户界面的Java规范,而事件处理是其核心功能之一。通过这个包,开发者可以创建、监听和处理各种用户交互事件,如按钮点击、表单提交等。

以下是 javax.faces.event 包中一些重要的类和接口:

  1. ActionEvent:表示一个动作事件,通常由用户操作(如按钮点击)触发。
  2. ValueChangeEvent:表示一个值改变事件,当组件的值发生变化时触发。
  3. PhaseListener:允许在 JSF 生命周期的不同阶段插入自定义逻辑。
  4. SystemEvent:表示系统级别的事件,如视图创建或销毁。
  5. ComponentSystemEvent:特定于组件的系统事件。
  6. ExceptionQueuedEvent:表示在处理过程中发生的异常事件。
  7. FacesEvent:所有事件的基类,其他所有事件都继承自此类。
  8. BehaviorEvent:表示行为事件,通常用于 Ajax 请求。

这些类和接口为开发者提供了强大的工具来处理和管理用户界面中的事件,使得应用程序能够响应用户的交互并作出相应的反应。

JSF(JavaServer Faces)生命周期是指从用户请求一个页面到服务器响应该请求并生成最终的HTML页面发送给用户的整个过程。这个过程可以分为六个主要阶段,每个阶段都有特定的任务和作用:

  1. 恢复视图(Restore View): 这个阶段主要是从客户端的请求中恢复视图的状态信息,包括组件树、事件队列等。如果视图不存在,则创建一个新的视图。

  2. 应用请求值(Apply Request Values): 在这个阶段,JSF会将请求参数转换为组件的事件,并将这些事件添加到事件队列中。同时,还会将请求参数应用到相应的组件上,例如表单输入的数据。

  3. 处理验证(Process Validations): 此阶段会对组件的值进行验证,确保它们符合预定义的规则或约束条件。如果验证失败,则会添加相应的错误消息。

  4. 更新模型值(Update Model Values): 如果前面的验证通过,那么在这一阶段,组件的值会被更新到绑定的后台bean属性中。这意味着用户输入的数据现在被保存到了模型对象中。

  5. 调用应用程序(Invoke Application): 在这个阶段,可以执行一些业务逻辑操作,比如数据库访问等。通常这是通过编写自定义的方法来实现的。

  6. 呈现响应(Render Response): 最后一步是生成HTML输出并将其发送回客户端浏览器。此时,所有的视图更新都已经完成,包括任何由于验证失败而显示的错误信息。

这六个步骤共同构成了一个完整的JSF生命周期,确保了Web应用程序能够正确地处理用户交互并返回适当的结果。

Skip navigation links

Overview
Package
Class
Use
Tree
Deprecated
Index
Help

Prev Package
Next Package

Frames
No Frames

Package javax.faces.event
Interfaces describing events and event listeners, and concrete event implementation classes.

See: Description

Interface Summary Interface 	Description
ActionListener 	
A listener interface for receiving ActionEvents.
AjaxBehaviorListener 	

By implementing this class, an object indicates that it is a listener for one or more kinds of BehaviorEvents.
BehaviorListener 	

A generic base interface for event listeners for various types of BehaviorEvents.
ComponentSystemEventListener 	

Implementors of this class do not need an isListenerForSource() method because they are only installed on specific component instances, therefore the isListenerForSource() method is implicit.
FacesListener 	
A generic base interface for event listeners for various types of FacesEvents.
PhaseListener 	
An interface implemented by objects that wish to be notified at the beginning and ending of processing for each standard phase of the request processing lifecycle.
SystemEventListener 	

By implementing this class, an object indicates that it is a listener for one or more kinds of SystemEvents.
SystemEventListenerHolder 	

Classes that implement this interface agree to maintain a list of SystemEventListener instances for each kind of SystemEvent they can generate.
ValueChangeListener 	
A listener interface for receiving ValueChangeEvents.
ViewMapListener 	

Marker interface for SystemEvents that indicate the view map has been created (PostConstructViewMapEvent, or destroyed (PreDestroyViewMapEvent).
Class Summary Class 	Description
ActionEvent 	

An ActionEvent represents the activation of a user interface component (such as a UICommand).
ActionListenerWrapper 	

Provides a simple implementation of ActionListener that can be subclassed by developers wishing to provide specialized behavior to an existing ActionListener instance.
AjaxBehaviorEvent 	
AjaxBehaviorEvent represents the component behavior specific to Ajax).
BehaviorEvent 	
BehaviorEvent is the event that can be generated from component Behavior.
ComponentSystemEvent 	
ComponentSystemEvent is the base class for SystemEvents that are specific to a UIComponent instance.
ExceptionQueuedEvent 	

The system event facility will create an instance of this class whenever Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Object) is called with ExceptionQueuedEvent.class as systemEventClass argument.
ExceptionQueuedEventContext 	

This helper class provides context to the ExceptionQueuedEvent regarding the state of the system at the point in time when the ExceptionQueuedEvent occurs and links the ExceptionQueuedEvent to the ExceptionHandler by virtue of implementing SystemEventListener.
FacesEvent 	

FacesEvent is the base class for user interface and application events that can be fired by UIComponents.
MethodExpressionActionListener 	
MethodExpressionActionListener is an ActionListener that wraps a MethodExpression.
MethodExpressionValueChangeListener 	
MethodExpressionValueChangeListener is a ValueChangeListener that wraps a MethodExpression.
PhaseEvent 	
PhaseEvent represents the beginning or ending of processing for a particular phase of the request processing lifecycle, for the request encapsulated by the specified FacesContext.
PhaseId 	
Typesafe enumeration of the legal values that may be returned by the getPhaseId() method of the FacesEvent interface.
PostAddToViewEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is a UIComponent instance and that either that instance or an ancestor of that instance was just added to the view.
PostConstructApplicationEvent 	

This event must be published by the runtime after all configuration resources have been parsed and processed.
PostConstructCustomScopeEvent 	

This class is provided to allow custom scopes to publish a "post construct" event in the same way that other scopes do to let the application become aware of the beginning of the scope.
PostConstructViewMapEvent 	

This event must be published by a call to {javax.faces.application.Application#publishEvent} when the view map is first created.
PostKeepFlashValueEvent 	

This event must be published by a call to Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Object) when a value is kept in the flash.
PostPutFlashValueEvent 	

This event must be published by a call to Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Object) when a value is stored in the flash.
PostRenderViewEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is the UIViewRoot instance that has just been rendered.
PostRestoreStateEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is in a tree that has just had its state restored.
PostValidateEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is the UIComponent instance that is that has just been validated.
PreClearFlashEvent 	

This event must be published by a call to Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Object) before the flash is cleared.
PreDestroyApplicationEvent 	

This event must be published by the runtime before the factories associated with this Application are released.
PreDestroyCustomScopeEvent 	

This class is provided to allow custom scopes to publish a "pre construct" event in the same way that other scopes do to let the application become aware of the beginning of the scope.
PreDestroyViewMapEvent 	

This event must be published by a call to Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Object) when the clear method is called on the map returned from UIViewRoot.getViewMap().
PreRemoveFlashValueEvent 	

This event must be published by a call to Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Object) when a value is removed from the flash.
PreRemoveFromViewEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is a UIComponent instance that is about to be removed from the view.
PreRenderComponentEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is the UIComponent instance that is about to be rendered and that it is safe to call UIComponent.getParent(), UIComponent.getClientId(), and other methods that depend upon the component instance being in the view.
PreRenderViewEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is the UIViewRoot instance that is about to be rendered.
PreValidateEvent 	

When an instance of this event is passed to SystemEventListener.processEvent(javax.faces.event.SystemEvent) or ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent), the listener implementation may assume that the source of this event instance is the UIComponent instance that is about to be validated.
ScopeContext 	

A structure that contains the name of the scope and the scope itself exposed as a Map<String, Object>.
SystemEvent 	
SystemEvent is the base class for non-application specific events that can be fired by arbitrary objects.
ValueChangeEvent 	

A ValueChangeEvent is a notification that the local value of the source component has been change as a result of user interface activity.
WebsocketEvent 	

This web socket event will be fired when a new <f:websocket> has been @WebsocketEvent.Opened or @WebsocketEvent.Closed.
Exception Summary Exception 	Description
AbortProcessingException 	
An exception that may be thrown by event listeners to terminate the processing of the current event.
Annotation Types Summary Annotation Type 	Description
ListenerFor 	

Classes tagged with this annotation are installed as listeners using the method Application.subscribeToEvent(java.lang.Class<? extends javax.faces.event.SystemEvent>, java.lang.Class<?>, javax.faces.event.SystemEventListener) or UIComponent.subscribeToEvent(java.lang.Class<? extends javax.faces.event.SystemEvent>, javax.faces.event.ComponentSystemEventListener) (depending on the circumstances, described below).
ListenersFor 	

Container annotation to specify multiple ListenerFor annotations on a single class.
NamedEvent 	

The presence of this annotation on a class automatically registers the class with the runtime as a ComponentSystemEvent for use with the <f:event /> tag in a page.
WebsocketEvent.Closed 	

Indicates that a <f:websocket> has closed.
WebsocketEvent.Opened 	

Indicates that a <f:websocket> has opened.

Package javax.faces.event Description

Interfaces describing events and event listeners, and concrete event implementation classes. All events extend from FacesEvent and all listeners extend from FacesListener.

For your convenience here is a UML class diagram of the classes in this package.
Skip navigation links

Overview
Package
Class
Use
Tree
Deprecated
Index
Help

Prev Package
Next Package

Frames
No Frames

Copyright © 1996-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值