![JavaEE5學(xué)習(xí)筆記12JSF集成AJAX使用經(jīng)驗總結(jié)_第1頁](http://file4.renrendoc.com/view/0e631fe570abc1b38d5e601969fa5ff1/0e631fe570abc1b38d5e601969fa5ff11.gif)
![JavaEE5學(xué)習(xí)筆記12JSF集成AJAX使用經(jīng)驗總結(jié)_第2頁](http://file4.renrendoc.com/view/0e631fe570abc1b38d5e601969fa5ff1/0e631fe570abc1b38d5e601969fa5ff12.gif)
![JavaEE5學(xué)習(xí)筆記12JSF集成AJAX使用經(jīng)驗總結(jié)_第3頁](http://file4.renrendoc.com/view/0e631fe570abc1b38d5e601969fa5ff1/0e631fe570abc1b38d5e601969fa5ff13.gif)
![JavaEE5學(xué)習(xí)筆記12JSF集成AJAX使用經(jīng)驗總結(jié)_第4頁](http://file4.renrendoc.com/view/0e631fe570abc1b38d5e601969fa5ff1/0e631fe570abc1b38d5e601969fa5ff14.gif)
![JavaEE5學(xué)習(xí)筆記12JSF集成AJAX使用經(jīng)驗總結(jié)_第5頁](http://file4.renrendoc.com/view/0e631fe570abc1b38d5e601969fa5ff1/0e631fe570abc1b38d5e601969fa5ff15.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、JavaEE5學(xué)習(xí)筆記12-JSF集成AJAX使用經(jīng)驗總結(jié)劉巖JSF也支持AJAX,ajax4jsf是專門為JSF提供的AJAX框架。他的工作原理就是在客戶端加載一個AJAX引擎,在這個引擎之上是呈現(xiàn)給用戶的JSF頁面,引擎之下就是JSF框架,也就是正常的JSF生命周期。換句話說頁面上的組件一旦配置了ajax4jsf標簽,那么該組件的JSF生命周期一直生活在ajax4jsf的陰影之下。用了ajax4jsf,開發(fā)者可以不用像以往的JSP頁面那樣,寫js腳本,頁面html組件觸發(fā)js事件后,進行ajax請求,而是像組件監(jiān)聽器一樣,對組件的事件進行一個監(jiān)聽,觸發(fā)事件后,開始ajax引擎預(yù)處理,之后再
2、走JSF生命周期。生命圖形如下首先下載,從山寨網(wǎng)站JKL/Downloadajax4jsf111jar.htm可以下載其jar包。之后再下載通用的一些jar包commons-beanutils.jarcommons-collections.jarcommons-digester.jarcommons-logging.jarweb.xml內(nèi)容加入Ajax4jsf Filterajax4jsfajax4jsfFaces ServletREQUESTFORWARDINCLUDE這里聲明一個過濾器,對servler名稱叫做Faces Servlet的請求進行過濾,F(xiàn)aces Servlet就是JSF的
3、。正是中的過濾器。使得ajax的filter將會作用于直接從客戶端過來的request,通過forward過來的request,通過include過來的request。就是這樣一個過濾器攔截了所有的JSF請求。使用AJAX功能的頁面代碼用戶登錄頁面用戶登錄頁面注意:1):使用ajax功能必須加入ajax4jsf標簽聲明2):聲明一個ajax作用域在這個作用域范圍內(nèi)的組件都可以使用AJAX功能。3):對組件進行顯示的ajax聲明,告訴引擎,這個組件需要進行ajax引擎處理,引擎過后才能交給JSF生命周期4):ajax4jsf也有相應(yīng)的組件,比如用ajax的方式輸出一個圖形容器托管Bean如下/*
4、 * ClassName: UserBean.java * created on Nov 1, 2007 * Copyrights 2007-2008 qjyong All rights reserved. * EMail: */package ajax;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import java.io.IOException;import java.io.OutputStream;import java.util.Random;import javax.faces.context.Fac
5、esContext;import javax.faces.event.ActionEvent;import javax.imageio.ImageIO;import javax.servlet.http.HttpSession;/* * author qiujy * version 1.0 * */public class UserBean private String userName;private String password;private String code; /用戶輸入的驗證碼private String validUserMsg;private String validat
6、eCodeMsg;private String myname;public String getMyname() return myname;public void setMyname(String myname) this.myname = myname;/* * return the code */public String getCode() return code;/* * param code the code to set */public void setCode(String code) this.code = code;/* * return the validUserMsg
7、 */public String getValidUserMsg() return validUserMsg;/* * param validUserMsg the validUserMsg to set */public void setValidUserMsg(String validUserMsg) this.validUserMsg = validUserMsg;/* * return the userName */public String getUserName() return userName;/* * param userName the userName to set */
8、public void setUserName(String userName) this.userName = userName;/* * return the password */public String getPassword() return password;/* * param password the password to set */public void setPassword(String password) this.password = password;/* * return the validateCodeMsg */public String getVali
9、dateCodeMsg() return validateCodeMsg;/* * param validateCodeMsg the validateCodeMsg to set */public void setValidateCodeMsg(String validateCodeMsg) this.validateCodeMsg = validateCodeMsg;public void validateUserName(ActionEvent event)System.out.println(input name= + this.userName);if(!userName.match
10、es(w6,20)this.validUserMsg = 用戶名不合法!;public void paint(OutputStream out, Object data) throws IOException if (data instanceof ImageData) ImageData imageData = (ImageData) data; / 生成一個在10009999之間的隨機數(shù) Random randomNumber = new Random(); String keyCode = randomNumber.nextInt(8999) + 1000 + ; /把產(chǎn)生的隨機數(shù)保存到
11、session中 HttpSession session = (HttpSession)FacesContext.getCurrentInstance() .getExternalContext().getSession(true); session.setAttribute(keyCode, keyCode); /生成干擾線的隨機數(shù) int outPutLine = 0; outPutLine = randomNumber.nextInt(100); BufferedImage img = new BufferedImage(imageData.getWidth(), imageData.g
12、etHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = img.createGraphics(); g.setBackground(imageData.getBackground(); g.setColor(imageData.getDrawColor(); g.setFont(imageData.getTextFont(); /畫矩形 g.clearRect(0, 0, imageData.getWidth(), imageData.getHeight(); /畫干擾線 g.drawLine(outPutLine, outPutLine
13、, imageData.getWidth() - outPutLine, imageData.getHeight() - outPutLine); /畫產(chǎn)生的隨機數(shù) g.drawString(keyCode, 10, 16); g.dispose(); ImageIO.write(img, jpeg, out); public String login()System.out.println(user-code + this.getCode();/從session中取出驗證碼HttpSession session = (HttpSession)FacesContext.getCurrentIn
14、stance().getExternalContext().getSession(true);String keyCode = (String)session.getAttribute(keyCode);if(keyCode.equals(this.getCode()return success;elsethis.validateCodeMsg = 驗證碼不正確;return null;public void isHaveName(ActionEvent event)System.out.println(input myname = + this.myname);if(liuyan.equal
15、sIgnoreCase(myname)this.validUserMsg = 用戶重復(fù)!;在此用到了一個輔助類/* * ClassName: ImageData.java * created on Nov 28, 2007 * Copyrights 2007-2008 qjyong All rights reserved. * EMail: */package ajax;import java.awt.Color;import java.awt.Font;/* * author qiujy * version 1.0 * */public class ImageData implements
16、java.io.Serializable private int width = 60;private int height = 20;private Color background = new Color(0 xDCDCDC);private Color drawColor = Color.black;private Font textFont = new Font(Times New Roman, Font.PLAIN, 18);/* * return the width */public int getWidth() return width;/* * param width the
17、width to set */public void setWidth(int width) this.width = width;/* * return the height */public int getHeight() return height;/* * param height the height to set */public void setHeight(int height) this.height = height;/* * return the background */public Color getBackground() return background;/*
18、* param background the background to set */public void setBackground(Color background) this.background = background;/* * return the drawColor */public Color getDrawColor() return drawColor;/* * param drawColor the drawColor to set */public void setDrawColor(Color drawColor) this.drawColor = drawColor;/* * return the textFont */public Font getTextFont() return textFont;/* * param textFont the textFont to set */public void setTextFont(Font textFont) this.textFont = textFont;這是用于圖形顯示的。顯示效果如下輸入不正確的信息,鼠標焦點
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年企業(yè)技術(shù)總監(jiān)短期合同范本
- 2025年展覽項目策劃委托合同
- 2025年停車場租憑協(xié)議樣本
- 2025年產(chǎn)品研發(fā)共享協(xié)議范本
- 2025年加盟聯(lián)營合同協(xié)議版
- 2025年一般性質(zhì)店面租賃合同范本
- 2025年信貸風險控制及操作協(xié)議
- 2025年建筑施工勞動力供需合同
- 2025年合同終止與解除法律實務(wù)
- 2025年中外技術(shù)培訓(xùn)合同范例
- 《海洋自然保護區(qū)》課件
- 2024年云南機場集團飛機維修服務(wù)分公司招聘筆試參考題庫含答案解析
- 外科手術(shù)及護理常規(guī)
- 北師大版五年級數(shù)學(xué)下冊教材分析解讀課件完整版
- 蘇少版小學(xué)一年級下冊綜合實踐活動單元備課
- 學(xué)校開學(xué)教師安全培訓(xùn)
- 出口潛力分析報告
- 晉升的述職報告
- 消防工程施工進度計劃橫道圖+進度網(wǎng)絡(luò)圖
- 微信視頻號運營技巧攻略詳解全套
- 2023CSCO非小細胞肺癌診療指南解讀
評論
0/150
提交評論