技术开发 频道

JSF事件处理


IT168技术文档】 
    与所有值变化监听器一样,上述监听器将传递一个值变化事件,该监听器使用该事件来访问组件的新值。ValueChangeEventl类扩展了FacesEvent,两个类都位于javax.faces.event包中。下面列出了这些类中的常用方法: 
    javax.faces.event.ValueChangeEvent 

    UIConponent getComponent() 
    返回触发事件的输入组件 
    Object getNewValue() 
    当转换和验证新值后,返回组件的新值 
    Object getOldValue() 
    返回组件的以前值 

    Javax.faces.event.FacesEvent 

    Void queue() 
    将传送事件放到当前生命周期阶段的末端并排队等待 
    PhaseID getPhaseId() 
    返回对应于发送事件阶段的阶段标识符 
    Void setPaseId(PhaseId) 
    设置对应于发送事件阶段的阶段标识符 

    上图的页面代码为: 

    Myjsp.jsp
<%@ page language="java" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <f:view> <head> <title>This is the first JSF example!</title> </head> <body> <h:form> <h:inputText value="#{user.input}" id="input" /> <h:selectOneMenu id="select" valueChangeListener="#{user.myEvent}" onchange="submit()" value="#{user.selectedContent}"> <f:selectItems value="#{user.countryItems}"></f:selectItems> </h:selectOneMenu> <p> <h:commandButton value="Login" action="login" id="btnSubmitAdd" actionListener="#{user.listen}" /> </p> <h:outputText value="#{user.result}" /> </h:form> </body> </f:view> </html>


0
相关文章