




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
使用JSF導航2JSF應用程序的用戶界面由頁面設計人員設計。模型對象是由應用程序開發(fā)人員實現(xiàn)的開發(fā)一個JSF應用的步驟包括:開發(fā)模型對象、開發(fā)基于JSF用戶界面、編寫時間監(jiān)聽器或者導航規(guī)則
JBulider提供的JSF開發(fā)工具包括:JSF創(chuàng)建向導、FacesConfig編輯器和JSP編輯器JSF通過從屬性文件中提供特定于語言環(huán)境的數(shù)據(jù)來實現(xiàn)國際化回顧3目標靜態(tài)導航動態(tài)導航4主頁index.jsp
<ahref="/j2se/index.jsp">J2SE(Core/Desktop)</a><ahref="/downloads/ea/index.html#j2se">EarlyAccess</a>導航概念2-15下一個頁面取決于:當前顯示頁由UICommand組件action屬性調用的操作導航規(guī)則中指出的結果字符串導航概念2-2
…….……………網頁…….………………….………………….……………網頁Web應用程序導航規(guī)則在應用程序配置文件中定義各種導航規(guī)則,并將結果字符串與每個規(guī)則關聯(lián)。將結果字符串用作JSF頁面按鈕或超鏈接的action屬性值。6導航規(guī)則<navigation-rule><from-view-id>/default.jsp</from-view-id><navigation-case><from-outcome>index</from-outcome><to-view-id>/index.jsp</to-view-id></navigation-case></navigation-rule>標識初始頁標識一個導航塊from-outcome元素是navigation-rule中from-view-id子元素處理的結果to-view-id元素為這個導航塊指定目標頁<h:commandLink…….action="index"/>7
靜態(tài)導航2-1用戶download.jsp請求導航處理程序應用程序…….……………Web頁面…….………………….……………固定的jsp頁面響應Index.jspdownload.jspearlyaccess.jspdownload.jsp8靜態(tài)導航2-2通過按鈕的action屬性與導航規(guī)則中的from-outcome元素值匹配<h:commandButtonid="login"action="welcome"value="登錄"/><navigation-rule><from-view-id>/login.jsp</from-view-id><navigation-case><from-outcome>welcome</from-outcome><to-view-id>/results.jsp</to-view-id></navigation-case></navigation-rule>9靜態(tài)導航示例zhangsan10后臺BeanpublicclassUser{privateStringname;publicvoidsetName(Stringname){=name;}publicStringgetName(){returnname;}}11視圖頁<%@tagliburi="/jsf/core"prefix="f"%><%@tagliburi="/jsf/html"prefix="h"%><%@pagecontentType="text/html;charset=gb2312"%><html><head><title>歡迎</title></head><body><f:view><h:form><tr><td>請輸入您的用戶名:</td></tr><h:inputTextvalue="#{U}"/><br><br><h:commandButtonaction="success"value="提交"/></h:form></f:view></body></html>Welcome.jsp<%@tagliburi="/jsf/core"prefix="f"%><%@tagliburi="/jsf/html"prefix="h"%><%@pagecontentType="text/html;charset=gb2312"%><html><head><title>再見</title></head><body><f:view><h:form>您的用戶名是<h:outputTextvalue="#{U}"/>,歡迎下次訪問!<br><br><h:commandLinkaction="welcome"value="返回"/></h:form></f:view></body></html>Goodbye.jsp12導航規(guī)則配置……<navigation-rule><from-view-id>/Welcome.jsp</from-view-id><navigation-case><from-outcome>success</from-outcome><to-view-id>/Goodbye.jsp</to-view-id></navigation-case></navigation-rule><navigation-rule><from-view-id>/Goodbye.jsp</from-view-id><navigation-case><from-outcome>welcome</from-outcome><to-view-id>/Welcome.jsp</to-view-id></navigation-case></navigation-rule>……faces-config.xml演示:示例113xinfei1983**********xinfei1983*********動態(tài)導航2-114動態(tài)導航2-2將登錄按鈕與后臺Bean的用戶驗證方法相關聯(lián)<h:commandButtonid="login"action="#{loginController.verifyUser}"
value="登錄"/>StringverifyUser(StringuserName,Stringpassword){if(userName.equals("Tomcat")&&password.equals("Tomcat")){return"success";}else{return"failure";}}<navigation-rule><from-view-id>/login.jsp</from-view-id><navigation-case> <from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id></navigation-case><navigation-case><from-outcome>failure</from-outcome><to-view-id>/failure.jsp</to-view-id></navigation-case></navigation-rule>用戶驗證方法導航規(guī)則15動態(tài)導航示例顯示給用戶一系列數(shù)學推理測試問題80113當回答完最后一個題目時,公布最后得分,并邀請用戶重新開始16Problem類描述了一個題目的問題和答案,以及檢查特定答案是否正確的方法后臺Bean2-1publicclassProblem{privateStringquestion;privateStringanswer;publicProblem(Stringquestion,Stringanswer){this.question=question;this.answer=answer;}publicStringgetQuestion(){returnquestion;}publicStringgetAnswer(){returnanswer;}publicbooleanisCorrect(Stringresponse){returnresponse.trim().equalsIgnoreCase(answer);}}題目的問題題目的答案驗證特定的答案是否正確17后臺Bean2-2QiuzBean類描述了包含很多題目的測驗,還跟蹤當前問題和用戶的總得分publicclassQuizBean{privateintcurrentProblem;privateintscore;privateStringresponse;privateStringcorrectAnswer;//在實際的應用程序中,可以從數(shù)據(jù)庫中提取所有的問題privateProblem[]problems={newProblem("8,10,14,22,38","70"),newProblem("8,15,29,57","113"),newProblem("4/17,7/13,10/9","13/5"),newProblem("99,110,122,135","149"),newProblem("1,3,4,1,5","9")};
publicQuizBean(){startOver();}publicStringgetQuestion(){returnproblems[currentProblem].getQuestion();}publicStringgetAnswer(){returncorrectAnswer;}publicintgetScore(){returnscore;}publicStringgetResponse(){returnresponse;}publicvoidsetResponse(StringnewValue){response=newValue;}
publicStringanswerAction(){if(problems[currentProblem].isCorrect(response)){score++;nextProblem();if(currentProblem==problems.length){return"done";}else{return"success";}}else{nextProblem();if(currentProblem==problems.length){return"done";}else{return"failure";}}}
publicStringstartOverAction(){startOver();return"startOver";}
privatevoidstartOver(){currentProblem=0;score=0;response="";}
privatevoidnextProblem(){correctAnswer=problems[currentProblem].getAnswer();currentProblem++;response="";}}18視圖頁index.jsp<html><head><title>數(shù)學推理小測驗</title></head><body><f:view><h:form><p><h:outputLabelvalue="有以下數(shù)字序列:"/><h:outputTextvalue="#{quiz.question}"/></p><p><h:outputLabelvalue="根據(jù)前面數(shù)字的規(guī)律,推斷下一個數(shù)字:"/><h:inputTextvalue="#{quiz.response}"/></p><p><h:commandButtonvalue="檢查答案"action="#{quiz.answerAction}"/></p></h:form></f:view></body></html>主測試頁面19視圖頁failure.jsp……<html><head><title>答錯了</title></head><bodybgcolor="#ffffff"><f:view><h:form><h:outputTextvalue="很遺憾,你答錯了!"/><br><br><h:outputTextvalue="正確答案是:"/><h:outputTextvalue="#{quiz.answer}"/><p><h:commandLinkvalue="下一個題目"action="next"/></p></h:form></f:view></body></html>答案錯誤頁面20視圖頁success.jsp<html><head><title>數(shù)學推理小測驗</title></head><body><f:view><h:form><p><h:outputTextvalue="恭喜你,你答對了!"/><h:outputTextvalue="你現(xiàn)在的得分是:"/><h:outputTextvalue="#{quiz.score}"/></p><p><h:outputTextvalue="下一個題目是:"/></p><p><h:outputLabelvalue="有以下數(shù)字序列:"/><h:outputTextvalue="#{quiz.question}"/></p><p><h:outputLabelvalue="根據(jù)前面數(shù)字的規(guī)律,推斷下一個數(shù)字:"/><h:inputTextvalue="#{quiz.response}"/></p><p><h:commandButtonvalue="檢查答案"action="#{quiz.answerAction}"/></h:form></f:view></body></html>答案正確顯示下一個測試題目頁面21視圖頁done.jsp<html><head><title>數(shù)學推理小測驗</title></head><body><f:view><h:form><p><h:outputTextvalue="感謝你參加這次測驗"/><h:outputTextvalue="你的最后得分是:"/><h:outputTextvalue="#{quiz.score}"/></p><p><h:commandButtonvalue="重新開始"action="#{quiz.startOverAction}"/></p></h:form></f:view></body></html>顯示最后得分,并要求用戶再玩一次頁面22導航規(guī)則配置……<navigation-rule><navigation-case><from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id>
<redirect/></navigation-case>
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 四川宜賓縣橫江片區(qū)重點名校2025年初三下第二階段性考試物理試題理試題含解析
- 2025年英語口語水平測試試題及答案
- 沈陽市重點中學2024-2025學年高三下學期期中練習歷史試題文試卷含解析
- 山東省濟南市外國語學校2025年高三下學期學習能力診斷卷物理試題含解析
- 2025年心理健康教育考試試題及答案
- 2025年項目管理專業(yè)考試試題及答案
- 南京郵電大學《鋼琴教學法》2023-2024學年第一學期期末試卷
- 天津理工大學中環(huán)信息學院《英語閱讀與寫作》2023-2024學年第一學期期末試卷
- 山東師范大學《翻譯概論》2023-2024學年第一學期期末試卷
- 內蒙古警察職業(yè)學院《工筆花鳥畫鑒賞與臨摹》2023-2024學年第二學期期末試卷
- 藥店客戶畫像與消費者分析
- 脊柱損傷搬運健康宣教
- 【海瀾之家公司盈利能力探析11000字】
- pc板冷折彎工藝
- 高考英語單詞3500記憶短文40篇
- 幼兒園區(qū)域材料采購清單
- 廠內運輸車輛專項安全檢查表
- 企業(yè)商學院的組織架構和培訓體系架構
- 鐵道機車-機車檢修運用
- 安全操作規(guī)程培訓課件
- DL∕T 547-2020 電力系統(tǒng)光纖通信運行管理規(guī)程
評論
0/150
提交評論