广州北大青鸟计算机职业培训学校
互联网技术培训、软件技术培训、大数据培训、云计算培训、数据分析培训信息网
当前位置:网站首页 > 软件教程 > Java技术 > 正文

惠州分享JSF ActionListener实例_北大青鸟IT软件学校

作者:邓华发布时间:2021-04-29分类:Java技术浏览:831


导读:前面惠州北大青鸟老师给大家讲过JSF ActionListener的知识,接下来老师给大家分享JSF ActionListener的实例,希望对大家学习Java有用。

前面惠州北大青鸟老师给大家讲过JSF ActionListener的知识,接下来老师给大家分享JSF ActionListener的实例,希望对大家学习Java有用。

实例

以下代码来自ActionListener.java。

package cn.w3cschool.common;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;public class MyActionListener implements ActionListener{

 @Override  public void processAction(ActionEvent event)
     throws AbortProcessingException {
   
   System.out.println("Any use case here?");
 
 }
 
}

以下代码来自result.xhtml。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
     xmlns:h="http://java.sun.com/jsf/html"
     >
   <h:body>
   #{normal.buttonId}
   </h:body>
</html>

以下代码来自demo.xhtml。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     >
   <h:body>
   <h:form id="form">
     <ui:remove>  
     <h:commandButton id="submitButton" 
       value="Submit" action="#{normal.outcome}" 
       actionListener="#{normal.printIt}" />
     </ui:remove>
     <h:commandButton id="submitButton" 
       value="Submit" action="#{normal.outcome}" >
       <f:actionListener type="cn.w3cschool.common.MyActionListener" />
     </h:commandButton>
   </h:form>
   </h:body>
</html>

下面的代码来自UserBean.java。

package cn.w3cschool.common;


import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

@ManagedBean(name="normal")
@SessionScopedpublic class UserBean implements java.io.Serializable{  public String buttonId="www.w3cschool.cn"; 
 
 public String getButtonId() {
   return buttonId;
 }  public void setButtonId(String buttonId) {
   this.buttonId = buttonId;
 }  public void printIt(ActionEvent event){
   //Get submit button id
   buttonId = event.getComponent().getClientId();
 }  
 public String outcome(){
   return "result";
 }
}

点击咨询直接了解更多相关资料,我在惠州北大青鸟新方舟等你。

java3.png

Java

标签:惠州计算机JAVA软件开发惠州计算机Java软件开发惠州计算机JAVA培训惠州计算机JAVA软件开发学校惠州计算机Java软件开发培训JAVAJava软件开发北大青鸟IT计算机学校北大青鸟IT软件学校北大青鸟IT学校


Java技术排行
标签列表
网站分类
文章归档
最近发表