﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-BeanSoft's Java Blog-随笔分类-JSF</title><link>http://www.blogjava.net/beansoft/category/26022.html</link><description>MyEclipse 6, Java EE 5, JSPWiki, Spring, Struts, Hibernate, JPA, SWT, Swing, AJAX, JavaScript, Netbeans</description><language>zh-cn</language><lastBuildDate>Wed, 26 Mar 2008 02:38:57 GMT</lastBuildDate><pubDate>Wed, 26 Mar 2008 02:38:57 GMT</pubDate><ttl>60</ttl><item><title>MyEclipse 6 实战开发讲解视频入门 9 JSF 1.2 入门开发</title><link>http://www.blogjava.net/beansoft/archive/2007/11/30/164166.html</link><dc:creator>BeanSoft</dc:creator><author>BeanSoft</author><pubDate>Fri, 30 Nov 2007 01:19:00 GMT</pubDate><guid>http://www.blogjava.net/beansoft/archive/2007/11/30/164166.html</guid><wfw:comment>http://www.blogjava.net/beansoft/comments/164166.html</wfw:comment><comments>http://www.blogjava.net/beansoft/archive/2007/11/30/164166.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/beansoft/comments/commentRss/164166.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beansoft/services/trackbacks/164166.html</trackback:ping><description><![CDATA[<p>本视频根据自己翻译的 MyEclipse 官方教材制作了对应的视频, 视频具体内容请参考 <a href="http://www.blogjava.net/beansoft/archive/2007/09/24/147912.html">MyEclipse JSF 快速入门中文版</a>.  <p><font color="#ff0000"><strong>友情提示</strong><strong>: </strong><strong>下载微软网盘文件时关闭下载工具</strong><strong>,&nbsp; </strong><strong>否则你将得到错误的文件</strong><strong>, </strong><strong>双击</strong><strong> EXE </strong><strong>会出来</strong><strong> DOS </strong><strong>窗口</strong><strong>. </strong><strong>正确操作是点击文件名后能看到显示下载链接和文件大小等信息</strong><strong>.</strong></font>  <p>代码: <a title="http://cid-519b3f7aa2172030.skydrive.live.com/self.aspx/Public/MyEclipse6Videos/9_JSFLoginDemo.zip" href="http://cid-519b3f7aa2172030.skydrive.live.com/self.aspx/Public/MyEclipse6Videos/9_JSFLoginDemo.zip">http://cid-519b3f7aa2172030.skydrive.live.com/self.aspx/Public/MyEclipse6Videos/9_JSFLoginDemo.zip</a>&nbsp; 9 KB  <p>视频:&nbsp; <a href="http://cid-519b3f7aa2172030.skydrive.live.com/self.aspx/Public/MyEclipse6Videos/myeclipse6_9.exe">http://cid-519b3f7aa2172030.skydrive.live.com/self.aspx/Public/MyEclipse6Videos/myeclipse6_9.exe</a>&nbsp; 15分31秒 6.6 MB </p> <p>内容包括:</p> <p>1.新建 Web Project</p> <p>2. 添加 JSF 功能</p> <p>3. 创建 Message Bundle</p> <p>4. 创建 Managed Bean</p> <p>5. 创建 userLogin.jsp</p> <p>6. 创建 userLoginSuccess.jsp</p> <p>7. 创建 导航规则</p> <p>8. 发布并测试</p> <p>9. 加入中文消息包</p> <p>10. 测试</p> <p>&nbsp;</p> <p>视频截图:</p> <p><a href="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipse69JSF1.2_80B6/image_2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="739" alt="image" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipse69JSF1.2_80B6/image_thumb.png" width="1024" border="0"></a></p><img src ="http://www.blogjava.net/beansoft/aggbug/164166.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beansoft/" target="_blank">BeanSoft</a> 2007-11-30 09:19 <a href="http://www.blogjava.net/beansoft/archive/2007/11/30/164166.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MyEclipse JSF 快速入门中文版(PDF文件图片显示不全问题已修正)</title><link>http://www.blogjava.net/beansoft/archive/2007/09/24/147912.html</link><dc:creator>BeanSoft</dc:creator><author>BeanSoft</author><pubDate>Mon, 24 Sep 2007 14:07:00 GMT</pubDate><guid>http://www.blogjava.net/beansoft/archive/2007/09/24/147912.html</guid><wfw:comment>http://www.blogjava.net/beansoft/comments/147912.html</wfw:comment><comments>http://www.blogjava.net/beansoft/archive/2007/09/24/147912.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/beansoft/comments/commentRss/147912.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beansoft/services/trackbacks/147912.html</trackback:ping><description><![CDATA[<p>PDF 版本下载: <a href="http://gro.clinux.org/frs/download.php/2089/MyEclipse_JSF_quickstart_zh_CN.pdf">MyEclipse_JSF_quickstart_zh_CN.pdf</a>&nbsp;650KB 建议右键另存为<br></p> <p>相关资料: <a class="entrylistItemTitle" id="CategoryEntryList1_EntryStoryList_Entries_ctl04_TitleUrl" href="/beansoft/archive/2007/05/10/116486.html"><strong><font color="#1a8bc8">《jsf入门》简体中文版.rar 电子书下载</font></strong></a><br><br><a><b><br>MyEclipse JSF </b></a><b>快速入门中文版</b><b></b></p> <p><b>最后修订</b> <b>: 9</b> <b>月</b> <b>26</b> <b>日</b> <b>, 2005 </b><b>年</b> <b></b></p> <p><a href="http://www.myeclipseide.com/index.php"><img height="90" alt="MyEclipse Enterprise Workbench" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image001_1.jpg" width="188" border="0"> </a></p> <p>翻译: <a href="mailto:BeanSoft@126.com">BeanSoft@126.com</a></p> <p>Blog: <a href="/beansoft/">http://www.blogjava.net/beansoft/</a></p> <p>日期: 2007-9-24 </p> <p>声明: 中文文字版权归 刘长炯 (<a href="mailto:beansoft@126.com">beansoft@126.com</a>) 所有, 原文及相关的图片等资源的版权归原作者 Genuitec L.L.C公司所有. </p> <p>原文地址: <a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html">http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html</a></p> <p><b>目录</b> <a></a><b></b></p> <p><a href="#_Toc178434809"><b>JSF Quickstart </b><b>中文版</b>... 1</a> </p> <p><a href="#_Toc178434810"><b>1. </b><b>前言</b>... 1</a> </p> <p><a href="#_Toc178434811"><b>2. </b><b>介绍</b>... 1</a> </p> <p><a href="#_Toc178434812"><b>3. </b><b>系统需求</b>... 2</a> </p> <p><a href="#_Toc178434813"><b>4.&nbsp;</b> <b>设置新项目和目录结构</b>... 2</a> </p> <p><a href="#_Toc178434814"><b>5. </b><b>创建消息包</b>... 7</a> </p> <p><a href="#_Toc178434815"><b>6. </b><b>创建受管</b> <b>Bean</b>. 8</a> </p> <p><a href="#_Toc178434816"><b>7. </b><b>创建</b> <b>JSP</b> <b>页面</b>... 14</a> </p> <p><a href="#_Toc178434817"><b>8. </b><b>运行应用程序</b>... 32</a> </p> <p><a href="#_Toc178434818"><b>9. </b><b>总结</b>... 36</a> </p> <p><a href="#_Toc178434819"><b>10. </b><b>用户反馈</b>... 37</a> </p> <hr align="center" width="100%" size="2">  <p><a><b>1. </b></a><a></a><b>前言</b> <b></b></p> <p>这个文档基于下列环境编写: Sun JDK 1.5.0, Eclipse 3.1 和 MyEclipse 4.0. 如果你注意到这个文档和你正在操作的Eclipse/MyEclipse的版本不一致, 在使用这个向导时遇到困难或者无法根据向导进行操作, 请参考<a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#feedback"> 用户反馈</a> 部分来了解如何汇报这个问题. </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>2. </b></a><a></a><b>介绍</b> <b></b></p> <p>在这个教程中我们将使用MyEclipse Enterprise Workbench来开发一个小小的 JSF 示例程序. 不需要您对关于JSF 和 MyEclipse的相关知识有所了解, 不过如果有所了解的话会更好.<br>因为Struts 是一个非常流行的 web 应用框架, 所以JSF 和 Struts之间的相似点我们适当的提示您注意, 来帮助哪些有过 Struts 开发经验的读者. 然而, 如果你以前对 Struts 一无所知, 你完全可以很自在的忽略这些内容. </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>3. </b></a><a></a><b>系统需求</b> <b></b></p> <p>下面是这个指南所使用的软件的列表: </p> <ul> <li>JDK 1.4+ (Sun 或者 IBM)  <li><u><a href="http://java.sun.com/j2se/downloads/index.html">http://java.sun.com/j2se/downloads/index.html</a> </u></li></ul> <ul> <li>Eclipse 3.1 SDK  <li><a href="http://www.eclipse.org/downloads/index.php">http://www.eclipse.org/downloads/index.php</a> </li></ul> <ul> <li>MyEclipse 4.1  <li><a href="http://www.myeclipseide.com/ContentExpress-display-ceid-10.html">http://www.myeclipseide.com/ContentExpress-display-ceid-10.html</a> </li></ul> <ul> <li>Tomcat 5.x (首选5.5.9, 或者其它符合标准的 Servlet/EJB 容器)&nbsp;  <li><a href="http://jakarta.apache.org/tomcat/index.html">http://jakarta.apache.org/tomcat/index.html</a> </li></ul> <ul> <li>对这个简单的例子, <b>用户名</b> 是 "myeclipse" , <b>密码</b> 也是 "myeclipse". </li></ul> <p><b>注意</b>:&nbsp; <i>在安装过</i><i> JDK </i><i>并且重启你的计算机后</i><i>, </i><i>请确保首先安装</i><i> Eclpse </i><i>然后是</i><i> MyEclpse, </i><i>最后安装</i><i> Tomca. </i><i>所有这些软件安装完毕后</i><i>, </i><i>请确保在</i><i> MyEclipse </i><i>中设置对应的</i><i>Tomcat 5 </i><i>服务器设置</i><i>; </i><i>请使用正确的</i><i>Tomcat Home </i><i>目录和你刚刚安装好的那个可用的</i><i> JDK. </i><i>如果你不知道如何在</i><i> MyEclipse </i><i>中设置</i><i> Tomcat, </i><i>你可以参考</i><i><a href="http://www.myeclipseide.com/images/tutorials/quickstarts/appservers/">使用应用服务器 Application Servers</a></i><i>快速入门向导</i><i>.</i></p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>4.&nbsp;</b> </a><a></a><b>设置新项目和目录结构</b> <b></b></p> <p>为了组织我们的开发过程, 我们需要在 MyEclipse 中创建一个新的 Web 模块并向它添加 JSF 功能(<i>JSF Capabilities)</i>模块. 你可以通过向导来创建一个web项目, 请通过选择菜单项<b>File &gt; New &gt; Other &gt; Project &gt; J2EE &gt; Web Project </b>来打开, 如下<b>图</b><b> 4.1</b>所示. </p> <p><img height="500" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image002_1.gif" width="500" border="0"> <br><b>图</b> <b>4.1: </b><b>创建一个新的</b> <b>web</b> <b>项目</b> </p> <p><img height="500" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image003_1.gif" width="500" border="0"> <br><b>图</b> <b>4.2: Web </b><b>项目向导对话框</b> </p> <p>这个向导可以让你自定义项目的设置, 通过在对话框的输入框里输入一些值来自定义, 如<b>图</b><b>4.2</b>所示. </p> <p><b>注意</b>:&nbsp;因为开发 JSF 程序的时候流行和JSTL类库搭配<i>, </i><i>所以在项目创建时建议您选择</i><i>"JSTL Libraries".&nbsp; </i><i>然而</i><i>, </i><i>您也可以在以后再来添加</i><i> JSTL </i><i>类库</i><i>, </i><i>通过选择</i><i> MyEclipse </i><i>菜单的</i><i> "Add JSTL Libraries" </i><i>菜单项来完成</i><i>.</i></p> <p>一旦Web项目创建了, 我们需要给它添加JSF功能. 这个操作可以通过<i>Package Explorer </i><i>视图的项目根节点上右键点击</i>, 选择弹出菜单中的 <b>MyEclipse &gt; Add JSF Capabilities</b>, 如<b>图</b><b>4.3</b> 所示. </p> <p><img height="759" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image004_1.gif" width="580" border="0"> <br><b>图</b> <b>4.3: </b><b>向</b> <b>Web </b><b>项目添加</b> <b>JSF Capabilities</b> </p> <p>JSF 对话框的默认值对这个教程来说不需要修改就可以使用.&nbsp;高手们也可以通过修改对话框里面的默认值来改变配置, 如<b>图</b><b> 4.4</b> 所示. </p> <p><img height="475" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image005_1.gif" width="526" border="0"> <br><b>图</b> <b>4.4: </b><b>配置</b> <b>JSF Capabilities</b> </p> <p>这个向导结束后, 项目的目录结构将会如下<b>图</b><b> 4.5</b>所示. </p> <p><img height="386" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image006_1.gif" width="312" border="0"> <br><b>图</b> <b>4.5: </b><b>配置后的项目布局</b> </p> <p>现在项目已经创建, 我们可以开始修改并创建我们自己的应用相关的代码了. </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>5. </b></a><a></a><b>创建消息包</b> <b></b></p> <p>让我们来通过创建一个MessageBundle文件正式开始我们的应用. 这是一个简单的属性文件, 它将保存所有的消息字符串以及相关的主键.&nbsp;&nbsp;然后这个消息包可以用在我们的任何JSP文件中来让我们的应用很容易的支持国际化语言.&nbsp;作为类比, Struts 在这个领域提供了相似的支持, 通过使用ApplicationResources.properties 文件,&nbsp; 以及不同的&lt;bean /&gt; 标签, 以及bean标签所允许的消息包属性来完成这套功能.<br>在 JSF里面, 我们可以在JSP页面里加入一行代码来加载消息包:<br><i>&lt;f:loadBundle basename="com.jsfdemo.MessageBundle" var= "bundle"/&gt;<br></i><b><i>注意</i></b><i>: </i><i>这一行代码创建了一个生命周期为页面的消息包</i><i>, </i><i>这个包可以稍后在页面中通过变量名</i><i>'bundle'</i><i>来进行引用</i><i>, </i><i>可以用来查找消息主键</i><i>, </i><i>然后返回对应的消息值</i><i>.<br></i><br>在创建消息包文件的时候, 先在源代码目录创建包 <b>com.jsfdemo</b>, 通过右键点击源代码目录, 然后选择弹出的菜单中的<b>New &gt; Package</b>即可完成.&nbsp; 要创建消息包文件, 我们使用新建文件向导, 右键点击项目的’src’目录, 在弹出的菜单中选择<b>New &gt; File</b> , 如下<b>图</b><b> 5.1</b> 所示. </p> <p><img height="354" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image007_1.gif" width="543" border="0"> <br><b>图</b> <b>&nbsp;5.1: </b><b>创建消息包文件</b> </p> <p>当指定新建文件的保存位置时, 选择 Browse..., 选中目录 <b>/JSFLoginDemo/src/com/jsfdemo</b>, 将文件命名为 <b>MessageBundle.properties,</b> 然后选择 Finish.&nbsp; </p> <p>新建消息包文件成功后, 我们需要为每个在JSP里面需要显示的标签或者字符串以键值对的方式添加到属性文件中.复制<b>图</b><b>5.2</b>中的内容到你的消息包文件然后保存它: </p> <p><b><i>MessageBundle.properties</i> </b></p> <p>user_name_label=User Name:<br>user_password_label=Password:<br>login_button_label=Login </p> <p><b>图</b> <b>&nbsp;5.2: MessageBundle.properties</b> 文件内容 </p> <p>现在我们的 MessageBundle 创建完毕了, 接下来我们要创建受管Bean(ManagedBean), 它将处理我们的用户登录操作. </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>6. </b></a><a></a><b>创建受管</b> <b>Bean</b> <b></b></p> <p>在这一部分我们将会看到如何创建ManagedBean , 这个Bean将会执行登录JSP页面所提示的登录操作, 以及保存用户输入的用户名和密码. 出于演示的目的,我们的登录操作知识简单的检查用户名和密码是不是都是 "myeclipse", 然后将用户重新指引到<i>userLoginSuccess.jsp</i> 页面. &nbsp;否则它会返回到登录页面. </p> <p>首先使用<i>MyEclipse JSF Editor</i>打开文件<b>faces-config.xml</b> : </p> <p><img height="484" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image008_1.gif" width="511" border="0"> <br><b>图</b> <b>6.1: </b><b>打开并准备编辑</b> <b>faces-config.xml </b><b>文件</b> </p> <p>在 MyEclipse 4.0 中 <b>faces-config.xml</b> 编辑器已经比以前的版本有所增强, 你不仅可以创建和管理应用程序流程(浏览规则 Navigation Cases), 还可以通过大纲(Outline)视图来创建/修改并管理所有资源. 你可以点击<b>大纲视图</b>右上角的下箭头按钮来添加新的bean, 如<b>图</b><b>6.2</b>: </p> <p><img height="543" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image009_1.gif" width="295" border="0"> <br><b>图</b> <b>6.2: </b><b>通过大纲视图启动</b> <b>ManagedBean </b><b>向导</b> </p> <p>现在你会看到新建Managed Bean 向导对话框; &nbsp;请按照下面的图6.3和6.4所示来输入值: </p> <p><img height="561" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image010_1.gif" width="459" border="0"> <br><b>图</b> <b>&nbsp;6.3: </b><b>设置新</b> <b>ManagedBean </b><b>的类和属性</b> </p> <p><img height="561" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image011_1.gif" width="459" border="0"> <br><b>图</b> <b>6.4: Managed Bean </b><b>向导完成页面</b> <b></b></p> <p>你现在会注意到新的 UserBean 被添加到 <b>Outline </b><b>视图</b> , 如图 6.5 所示: </p> <p><img height="171" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image012_1.gif" width="226" border="0"> <br><b>图</b> <b>6.5: UserBean </b><b>现在显示在</b> <b>Outline </b><b>视图</b> </p> <p>同时新建的UserBean.java 源文件也在 Java 编辑器中打开了: </p> <p><img height="671" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image013_1.gif" width="724" border="0"> <br><b>图</b> <b>6.6: UserBean Java </b><b>源代码在编辑器中打开</b> </p> <p>注意我们的两个属性(username 和 password)的getters 和 setters 方法已经自动生成了, 所以对这个类唯一需要做的就是添加并实现<b>loginUser</b> 方法, 这个方法将会在用户登录时调用. </p> <p>下面的<b>图</b><b>6.7</b>显示了loginUser方法的代码片断. &nbsp;请将这个代码复制粘贴到你自己的文件里, 并添加必要的新的类的import语句: </p> <p><b><i>UserBean.java</i> </b></p> <p>&nbsp; &nbsp; public String loginUser() {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if("myeclipse".equals(getUserName()) &amp;&amp; "myeclipse".equals(getPassword()))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return "success";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FacesContext facesContext = FacesContext.getCurrentInstance();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FacesMessage facesMessage = new FacesMessage(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "You have entered an invalid user name and/or password");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; facesContext.addMessage("loginForm", facesMessage);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "failure";<br>&nbsp;&nbsp;&nbsp; } </p> <p><b>图</b> <b>6.7: </b><b>新建的</b> <b>UserBean.java</b> <b>文件中的</b> <b>loginUser </b><b>代码片断</b> </p> <p>仔细看看 bean 的代码, 我们可以注意到一些独特之处.例如, UserBean 类并没有继承或者实现绑定到 JSF 的任何类或者接口. 它仅仅是一个简单的包含了额外的逻辑来执行有用的操作的 JavaBean.&nbsp; 用 Struts 的术语来说, 它包含了Struts Form 和 Struts Action的所有功能, 方便的合并在一个类中.<br>另一个和 Struts 的不同之处是这些方法没有返回任何特殊的类, 例如ActionForward, 因为导航信息是在<i>faces-config.xml</i>部署描述符中通过配置完成的. 而且, 在 <u>第</u><u>&nbsp;8</u><u>部分</u> 我们将展示如何创建并配置这个描述. </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>7. </b></a><a></a><b>创建</b> <b>JSP</b> <b>页面</b> <b></b></p> <p>在这一小节里面将集中精力为我们的示例JSF应用来创建JSP页面, 来模拟一个简单的网站常见的登录页面. 最后的结果只需要2个JSP页面,一个用来提示用户来登录,另一个用来告诉用户登录成功. 我们把这两个页面分别命名为 <i>loginUser.jsp</i> 和 <i>loginUserSuccess.jsp</i>. 为了简单起见, 如果尝试登录的时候验证身份失败, 就将用户重定向回页面<i>loginUser.jsp</i>. &nbsp;为了避免引起混淆, 我们没有在这个例子里使用任何验证机制, 不过你可以很容易的为JSF的inputText/Secret 组件添加验证器.&nbsp;&nbsp;我们将使用这些输入框来验证用户输入的值的长度并且可以在登录失败时给用户显示错误信息. </p> <p>另一个 MyEclipse 4.0 中的新功能是我们可以为JSF应用程序创建JSP页面, 通过在 <b><i>MyEclpse JSF </i></b><b><i>编辑器</i></b>中修改文件<i>faces-config.xml</i> 来实现. 所以请确保文件依然保持打开然后我们可以开始创建我们的<i>userLogin.jsp</i> 页面. </p> <p>要创建我们的<i>userLogin.jsp</i> 页面, 首先需要先点击一下 JSP 按钮 <img height="23" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image015_1.jpg" width="23" border="0">, 然后点击到画图板上.&nbsp; 当新建 JSP 向导对话框弹出时, 根据图 7.1 的显示在 File Name (文件名) 输入框中输入 值并选择 JSF 模版: </p> <p><img height="633" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image016_1.gif" width="586" border="0"> <br><b>图</b> <b>7.1: </b><b>使用</b> <b>faces-config.xml </b><b>编辑器创建</b> <b>userLogin.jsp</b> </p> <p>现在我们也可以使用同样的方式来创建<i>userLoginSuccess.jsp</i>: </p> <p><img height="653" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image017_1.gif" width="862" border="0"> <br><b>图</b> <b>7.2: </b><b>使用</b> <b>faces-config.xml </b><b>编辑器创建</b> <b>userLoginSuccess.jsp</b> </p> <p>接着我们可以打开页面 <i>userLogin.jsp</i> 来给我们的应用加入功能: </p> <p><img height="738" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image018_1.gif" width="738" border="0"> <br><b>图</b> <b>7.3: </b><b>开始编辑</b> <b>userLogin.jsp </b><b>页面</b> </p> <p><b>图</b> <b>7.3</b> 需要注意是MyEclipse(MyEclipse JSP 设计器)编辑器底部的一些面板, 你可以自己选择来编辑这个页面在不同的模式:源代码模式, 设计模式, 设计/源码模式或者预览. 在这个示例中我们切换到设计/源码模式, 因为这样可以很容易的在编辑页面时同时看到两个视图. 显示结果如下<b>图</b><b> 7.4</b>所示: </p> <p><img height="667" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image019_1.gif" width="745" border="0"> <br><b>图</b> <b>7.4: </b><b>切换到设计</b> <b>/</b> <b>源码模式并且展开</b> <b>JSF</b> <b>组件板</b> </p> <p>现在, 我们需要对这个页面进行如下修改: </p> <ul> <li>给username添加一个h:inputText 组件  <li>给password添加一个 h:inputSecret 组件  <li>给username inputText 添加一个 h:outputLabel  <li>给 password 添加一个h:outputLabel </li></ul> <p><i>注意</i> <i>: </i><i>在</i> <i>4.0</i> <i>版里面的</i> <i>JSF </i><i>设计器不支持从</i> <i>MessageBundle</i> <i>中读取值显示在</i> <i>outputLabel, </i><i>所以为了能够在设计器中看到我们的</i> <i>outputLabels , </i><i>我们将在代码中手工修改他们来将他们的值绑定为</i> <i>MessageBundle</i> <i>中的值</i> <i>. </i><i>这个问题将在</i> <i>MyEclipse 4.1</i> <i>版本修正</i> <i>(</i> <i>译者注</i> <i>: </i><i>现在已经是</i> <i>MyEclipse 6.0</i> <i>了</i> <i>, </i><i>这个问题应该早已被修正了</i> <i>).</i> <br>要做的第一件事就是删除默认的模版文字, 然后手工键入我们的资源包的基础名字然后我们可以使用MessageBundle.&nbsp; 这个JSP最后将会如<b>图</b><b> 7.5</b>这样结束: </p> <p><img height="291" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image020_1.gif" width="664" border="0"> <br><b>图</b> <b>7.5: </b><b>删除模版文字并且向</b> <b>JSP</b> <b>页面添加我们的</b> <b>MessageBundle</b> </p> <p><img height="654" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image021_1.gif" width="776" border="0"> </p> <p><b>图</b> <b>7.5a: </b><b>创建新表单</b> </p> <p>在图 7.5a 我们创建了新的HTML表单元素来包含我们的登录控件. 现在我们将会真正的创建输入文本框! </p> <p>现在我们给username创建h:inputText组件, 参考 <b>图</b><b> 7.6 </b><b>和</b><b> 7.7</b>: </p> <p><img height="646" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image022_1.gif" width="861" border="0"> <br><b>图</b> <b>7.6: </b><b>添加新的</b> <b>inputText </b><b>组件</b> <br><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image023_1.gif" width="442" border="0"> <br><b>图</b> <b>7.7: </b><b>添加新的</b> <b>inputText </b><b>组件</b> <b>(</b> <b>续</b> <b>)</b> </p> <p>现在我们添加我们的 h:inputSecret 组件 (没有标签): </p> <p><img height="646" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image024_1.gif" width="854" border="0"> <br><b>图</b> <b>7.8 </b><b>添加新的</b> <b>inputSecret </b><b>组件</b> </p> <p><b><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image025_1.gif" width="442" border="0"> <br></b><b>图</b> <b>7.9 </b><b>添加新的</b> <b>inputSecret </b><b>组件</b> <b>(</b> <b>续</b> <b>)</b> </p> <p>现在给我们的输入组件都添加outputLabel, 首先是我们的userLabel:<a></a></p> <p><img height="601" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image026_1.gif" width="852" border="0"> <br><b>图</b> <b>7.10: </b><b>给</b> <b>userName</b> <b>添加</b> <b>outputLabel </b><b>组件</b> </p> <p>我们也可以用同样的方式给我们的h:inputSecret 组件添加一个标签. 完成之后, 像刚刚所提到的那样, 让我们手工来更改h:outputLabel 组件来使它绑定到我们的MessageBundle , 这样我们可以在设计器里面看到它, 最后看起来就像这样:<br><img height="515" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image027_1.gif" width="530" border="0"><br><b>图</b><b> 7.11: </b><b>给我们的标签添加</b><b>outputText </b><b>组件</b></p> <p>请确保userName 和 password 两个标签都做了这样的修改. </p> <p>好了, 是时候加入我们的登录按钮了, 加入这个组件的方式和加入其它组件的方式一摸一样, 如 <b>图</b><b> 7.12 </b><b>和</b><b> 7.13 </b>所示:<br><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image028_1.gif" width="441" border="0"><br><b>图</b><b> 7.12: </b><b>添加一个新的</b><b>commandButton </b><b>组件</b></p> <p><b><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image029_1.gif" width="441" border="0"> <br></b><b>图</b> <b>7.13: </b><b>添加一个新的</b> <b>commandButton </b><b>组件</b> <b>(</b> <b>续</b> <b>)</b> </p> <p>现在我们将会得到一个大致样子如下所示的页面:<br><img height="133" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image030_1.gif" width="1125" border="0"><br><b>图</b><b> 7.14:</b><b>几乎完工的</b><b>userLogin.jsp </b><b>页面</b></p> <p>你也许已经注意到全部内容都显示在一行看起来很丑, 所以让我们来添加一些空格让这些组件分布到多行里面(译者注: 用Shift+Enter输入软换行也许会更合适):<br><img height="130" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image031_1.gif" width="491" border="0"><br><b>图</b><b> 7.15: </b><b>布局完好的</b><b> userLogin.jsp </b><b>页面</b></p> <p>现在 <i>userLogin.jsp</i> 页面完事了, 让我们快速完成更简单的<i>userLoginSuccess.jsp</i> 页面. 打开文件然后修改它, 只需要简单的添加一行数据来指出已经登录的用户的名字, 如<b>图</b><b> 7.16 </b>所示: </p> <p><img height="667" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image032_1.gif" width="908" border="0"> <br><b>图</b> <b>7.16: </b><b>修改</b> <b>userLoginSuccess.jsp </b><b>页面来输出用户名</b> </p> <p>现在我们创建了两个页面, 剩下的唯一的事情就是把他们用正确的导航规则(Navigation Case)连接到一块, 这个可以通过可视化的修改 <i>faces-config.xml</i> 文件来完成, 所以先要打开这个文件. 文件打开后, 进行下列操作来创建导航规则:&nbsp; </p> <ol> <li>点击Navigation Case 工具按钮  <li>点击 <i>userLogin.jsp</i>文件  <li>然后点击到<i>userLoginSuccess.jsp</i> 文件  <li>这是将会出现一个向导来提示你创建导航规则. </li></ol> <p>下面的图 7.17 和图 7.18 用来创建 <i>成功</i><i>(success) </i>浏览的导航规则. 为了创建 <i>失败</i><i>(failure) </i>导航规则, 我们简单的重复如上的步骤,只不过点击两次文件<i>userLogin.jsp</i> , 来创建一个循环的导航规则(自己导航到自己).<a></a></p> <p><img height="323" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image033_1.gif" width="531" border="0"> <br><b>图</b> <b>7.17: </b><b>创建</b> <b>success </b><b>导航规则</b> </p> <p><b><img height="415" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image034_1.gif" width="500" border="0"> <br></b><b>图</b> <b>7.18: </b><b>创建</b> <b>success </b><b>导航规则</b> <b>(</b> <b>续</b> <b>)</b> </p> <p>当这两个导航规则创建完成后, 配置文件将会看起来如下所示: </p> <p><img height="341" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image035_1.gif" width="539" border="0"> <br><b>图</b> <b>7.19: </b><b>检查应用的导航规则</b> </p> <p>现在我们已经创建了所有的JSP页面, 并且正确的加入了导航规则, 剩下唯一要做的事情就是运行了! </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>8. </b></a><a></a><b>运行应用程序</b> <b></b></p> <p>在这一小节里将会快速的展示我们的应用运行时候是什么样子.<br>这里使用 MyEclipse 来发布我们的程序到Tomat 5然后启动服务器, 这样就可以运行我们的应用了.&nbsp; 关于如何设置应用服务器以及通过MyEclipse进行发布的完整的信息请参考 <a href="http://myeclipseide.com/images/tutorials/me_remote_doc/appservers/index.html">应用服务器快速入门</a>.&nbsp; 为了仅仅运行这个例子, 我们假定Tomcat 5已经配置完毕并且只需要发布程序到上面即可.&nbsp; 发布程序可以通过Manage Deployments(管理发布)对话框来进行, 这个对话框可以通过下列步骤来打开: 在Package Explorer视图中右键点击项目文件出现的弹出菜单中, 选择<b>MyEclipse &gt; Add / Remove Deployments(</b><b>添加</b><b>/</b><b>删除发布</b><b>)...</b>&nbsp; Manage Deployments 对话框, 如<b>图</b><b> 8.2 </b>所示, 将会启动(译者注:另一种方式是通过点击工具栏上的发布按钮<img height="23" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image037_1.jpg" width="23" border="0">).&nbsp; 要添加发布, 在New Deployment(新发布)向导中, 点击 Add(添加)按钮, 然后这时候New Deployment(新建发布)向导将会打开. </p> <p><img height="113" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image038_1.gif" width="337" border="0"> <br><b>图</b> <b>8.1: </b><b>打开管理发布对话框</b> </p> <p><b><img height="490" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image039_1.gif" width="615" border="0"> <br></b><b>图</b> <b>8.2: </b><b>为我们的项目新建部署</b> </p> <p>选择服务器 Tomcat 5, 发布类型为散包部署(exploded archive), 然后选择 Finish 按钮, 如<b>图</b><b> 8.2</b> 所示.&nbsp; 当向导执行结束后, 部署管理器将会显示发布成功.&nbsp; 如 <b>图</b><b> 8.3 </b>所描述的那<b>样</b>.&nbsp; 现在部署已经完成, 你可以选择 OK 来关闭对话框. </p> <p><img height="445" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image040_1.gif" width="506" border="0"> <br><b>图</b> <b>8.3: </b><b>部署成功</b> </p> <p>这时候Tomcat 5 服务器可以通过 Eclipse 主工具栏中的Tomcat 5 管理菜单中选择Start 来启动, 如下<b>图</b><b> 8.4</b> 所示. </p> <p><img height="140" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image041_1.gif" width="305" border="0"> <br><b>图</b> <b>8.4: </b><b>启动</b> <b>Tomcat 5</b> </p> <p>服务器的日志输出将会被重定向到 Eclipse Console(控制台)视图.&nbsp; 从图8.5中显示的日志中, 很明显的可以看到服务器启动成功了. </p> <p><img height="311" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image042_1.gif" width="616" border="0"> <br><b>图</b> <b>8.5: Tomcat 5 </b><b>启动日志</b> </p> <p>一旦 Tomcat 5 运行了, 我们就可以通过打开MyEclipse Browser(浏览器)视图来进行测试.&nbsp; 这个步骤可以通过点击如<b>图</b><b>8.6</b>所示的浏览器按钮来完成.<br><img height="114" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image043_1.gif" width="332" border="0"><br><b>图</b><b> 8.6: </b><b>打开网络浏览器视图</b></p> <p>在浏览器的地址栏里, 输入 <a href="http://localhost:8080/JSFLoginDemo/userLogin.faces">http://localhost:8080/JSFLoginDemo/userLogin.faces</a> 来激活样例应用, 如图8.7所示. </p> <p><b>注意</b> <b></b>:<i>URL </i><i>以</i><i> .faces</i><i>结尾而不是</i><i> .jsp </i><i>的原因是因为在上面</i><i>, </i><i>我们将</i><i>FacesServlet</i><i>映射到了</i><i>*.faces </i><i>扩展名</i><i>, </i><i>这意味着为了能使我们的</i><i>JSF</i><i>获得机会来处理请求并且构造组件树</i><i>, </i><i>我们必须使用</i><i> .faces </i><i>扩展名来访问真正的页面</i><i>. </i><i>如果你不这样做</i><i>,</i><i>你将获得一个异常信息</i><i>,</i><i>包含下列信息</i><i>: "FacesContext cannot be found".</i></p> <p><img height="185" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image044_1.gif" width="334" border="0"> <br><b>图</b> <b>8.7: </b><b>访问示例应用</b> </p> <p>现在在用户名和密码框都输入 <b>myeclipse</b> , 然后点击 Login 来看到程序的执行! </p> <p><img height="184" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image045_1.gif" width="328" border="0"> <br><b>图</b> <b>8.8: </b><b>正在登录</b> <b>...</b> </p> <p><img height="162" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/JSF_136F8/clip_image046_1.gif" width="319" border="0"> <br><b>图</b> <b>8.9: </b><b>登录成功</b> </p> <p>我们可以看到导航规则起了作用, 我们验证后就被定向到了<i>userLoginSuccess.jsp</i> 页面, 并显示了我们的名字. 当然这个应用非常简单, 但是它传达了使用 MyEclipse 开发JSF 应用的基本步骤. </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>9. </b></a><a></a><b>总结</b> <b></b></p> <p>在这个示例中我们了解了使用MyEclipse Enterprise Workbench 来开发简单的 JSF 应用程序的步骤. 如果你想下载压缩过的这个示例的MyEclipse项目源代码包, 请<a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/JSFLoginDemo.zip">点击这里</a>. 这个代码总结了对JSF的介绍. 更多的快速入门文档都可以访问, 包括介绍和Web项目工作,修改, 应用程序配置, 企业应用项目以及数据库开发. 要获取更多信息请访问 <a href="http://myeclipseide.com/ContentExpress-display-ceid-67.html#quickstarts">MyEclipse 快速入门知识库</a> . </p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p><a><b>10. </b></a><a></a><b>用户反馈</b> <b></b></p> <p>我们欢迎所有建设性的反馈信息. 如果你有评论或者如何改进这个文档的电子, 请访问我们的支持站点的文档论坛(Documentation Forum).&nbsp; <a href="http://www.myeclipseide.com/PNphpBB2+file-viewforum-f-6.html">MyEclipse Documentation Forum</a></p> <p><b><a href="#top">返回页首</a> </b></p> <hr align="center" width="100%" size="2">  <p>版权所有 ? 2003 - 2005 by Genuitec L.L.C</p><img src ="http://www.blogjava.net/beansoft/aggbug/147912.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beansoft/" target="_blank">BeanSoft</a> 2007-09-24 22:07 <a href="http://www.blogjava.net/beansoft/archive/2007/09/24/147912.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转: MyEclipse JSF 开发指南(图片已修正)</title><link>http://www.blogjava.net/beansoft/archive/2007/09/20/146713.html</link><dc:creator>BeanSoft</dc:creator><author>BeanSoft</author><pubDate>Thu, 20 Sep 2007 03:08:00 GMT</pubDate><guid>http://www.blogjava.net/beansoft/archive/2007/09/20/146713.html</guid><wfw:comment>http://www.blogjava.net/beansoft/comments/146713.html</wfw:comment><comments>http://www.blogjava.net/beansoft/archive/2007/09/20/146713.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/beansoft/comments/commentRss/146713.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beansoft/services/trackbacks/146713.html</trackback:ping><description><![CDATA[<p><a title="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html" href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html">http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html</a></p> <p><b>JSF Quickstart</b> <p><b>Last Revision: September 26, 2005</b><b></b> <p><a href="http://www.myeclipseide.com/index.php"><img height="90" alt="MyEclipse Enterprise Workbench" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image001.jpg" width="188" border="0"></a> <hr align="center" width="100%" size="2">  <p><a></a><b>Outline</b> <ol> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#preface">Preface</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#introduction">Introduction</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#requirements">Requirements</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#newproject">New Project Setup &amp;&nbsp;Structure</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#messagebundle">Creating the Message Bundle</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#managedbeans">Creating the Managed Bean</a></b> <li><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#creatingjsp"><b>Creating the JSP Pages</b></a> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#running">Running the Application</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#summary">Summary</a></b> <li><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#feedback">User Feedback</a></b></li></ol> <hr align="center" width="100%" size="2">  <p><b>1. <a></a>Preface</b> <p>This document was written using Sun JDK 1.5.0, Eclipse 3.1 and MyEclipse 4.0. If you notice discrepancies between this document and the version of Eclipse/MyEclipse you are using to perform the install that make it difficult or impossible to follow this guide, please see the <a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#feedback">User Feedback</a> section on how to report the issue. <p><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top">Back to Top</a></b> <hr align="center" width="100%" size="2">  <p><b>2. <a></a>Introduction</b> <p>In this tutorial we will be walking through a small JSF demo application using MyEclipse Enterprise Workbench. Previous knowledge of JSF and/or MyEclipse is not necessary, but would be helpful.<br>Since Struts is such a prevalent web application framework, similarities between JSF and Struts will be noted, where appropriate, to help the reader with previous Struts experience. However, if you have no prior experience with Struts, you may feel free to skip these sections . <p><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top">Back to Top</a></b> <hr align="center" width="100%" size="2">  <p><b>3. <a></a>Requirements</b> <p>Below is a list of software used by this guide: <ul> <li>JDK 1.4+ (Sun or IBM) <li><u><a href="http://java.sun.com/j2se/downloads/index.html">http://java.sun.com/j2se/downloads/index.html</a></u></li></ul> <ul> <li>Eclipse 3.1 SDK <li><a href="http://www.eclipse.org/downloads/index.php">http://www.eclipse.org/downloads/index.php</a></li></ul> <ul> <li>MyEclipse 4.1 <li><a href="http://www.myeclipseide.com/ContentExpress-display-ceid-10.html">http://www.myeclipseide.com/ContentExpress-display-ceid-10.html</a></li></ul> <ul> <li>Tomcat 5.x (5.5.9 Preferred, or other compliant Servlet/EJB container)&nbsp; <li><a href="http://jakarta.apache.org/tomcat/index.html">http://jakarta.apache.org/tomcat/index.html</a></li></ul> <ul> <li>For this demo the <b>User Name</b> is "myeclipse" and the <b>Password</b> is "myeclipse" as well.</li></ul> <p><b>Note</b>:&nbsp; <i>After installing the JDK and restarting your computer, be sure to install Eclipse then MyEclipse next followed by Tomcat. After all the software have been installed, be sure to setup the Tomcat 5 connector in MyEclipse accordingly; using the correct Tomcat Home directory and valid JDK that you just installed. You may refer to the <a href="http://www.myeclipseide.com/images/tutorials/quickstarts/appservers/">Using Application Servers</a> Quickstart guide if you don't know how to setup Tomcat in MyEclipse.</i> <p><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top">Back to Top</a></b> <hr align="center" width="100%" size="2">  <p><b>4.&nbsp;<a></a>New Project Setup &amp;&nbsp;Structure&nbsp;</b> <p>To organize our development artifacts, we will need to create a new <i>Web Module Project</i> in MyEclipse that has <i>JSF Capabilities</i> added to it.&nbsp; You can create a web project using the wizard located at <b>File &gt; New &gt; Other &gt; Project &gt; J2EE &gt; Web Project</b>, as shown in Figure 4.1, below. <p><img height="500" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image002.gif" width="500" border="0"><br><b>Figure 4.1: Create a new web project</b> <p><img height="500" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image003.gif" width="500" border="0"><br><b>Figure 4.2: Web Project Wizard Dialog</b> <p>The wizard will allow you to customize your project settings by entering your preferences into the dialog fields, as demonstrated in Figure 4.2. <p><b>Note</b>:&nbsp;<i>It is popular when developing JSF applications to also use the JSTL libraries, so selecting add "JSTL Libraries" during project creation is recommended.&nbsp; However, it is also possible to add the JSTL libraries later, via the "Add JSTL Libraries" item from the MyEclipse context menu.</i> <p>Once the Web Project is created, we need to add JSF Capabilities to it. This is done by right clicking on the root of our project in the <i>Package Explorer View</i>, and selecting <b>MyEclipse &gt; Add JSF Capabilities</b>, as shown in Figure 4.3. <p><img height="759" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image004.gif" width="580" border="0"><br><b>Figure 4.3: Adding JSF Capabilities to a Web Project</b> <p>The default values for the JSF dialog are fine for the purposes of this tutorial.&nbsp; Advanced users may perform additional configuration by changing the default settings in the dialog, as shown in Figure 4.4. <p><img height="475" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image005.gif" width="526" border="0"><br><b>Figure 4.4: Configuring JSF Capabilities</b> <p>After the wizard completes, the project structure will look like what is shown in Figure 4.5. <p><img height="386" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image006.gif" width="312" border="0"><br><b>Figure 4.5: Project Layout After Configuration</b> <p>Now that the project has been created, we can&nbsp;start editing and creating our application. <p><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top">Back to Top</a></b> <hr align="center" width="100%" size="2">  <p><b>5. <a></a>Creating the Message Bundle</b> <p>Let's start off our new application with the creation of the MessageBundle file. This is a simple property file that stores all our messages along with their associated keys.&nbsp;&nbsp;Then the bundle can be used in any of our JSP pages to allow our application to be easily internationalized.&nbsp; As an analogy, Struts provided similar support in this area by using the ApplicationResources.properties file,&nbsp; the various &lt;bean /&gt; tags, and the message bundle attributes that the bean tags accepted.<br>In JSF, we can load a message bundle into a page with the line:<br><i>&lt;f:loadBundle basename="com.jsfdemo.MessageBundle" var= "bundle"/&gt;<br><b>Note</b>: This line of code creates a page-scoped message bundle that we can reference later in the page via the 'bundle' variable name, use to lookup messages keys, and return the associated message value.<br></i><br>Before creating the message bundle file, create a&nbsp;<b>com.jsfdemo</b> package in the source folder by right-clicking it and selecting <b>New &gt; Package</b>.&nbsp; &nbsp;To create the message bundle file, we'll use the New File Wizard that is accessed from the context menu of the project by right-clicking on the project's 'source' folder and selecting <b>New &gt; File</b>, as shown in Figure&nbsp;5.1 below. <p><img height="354" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image007.gif" width="543" border="0"><br><b>Figure&nbsp;5.1: Creating the Message Bundle file</b> <p>When specifying the file location, select Browse..., choose the directory <b>/JSFLoginDemo/src/com/jsfdemo</b>, name the file <b>MessageBundle.properties,</b> and select Finish.&nbsp; <p>After successfully creating the new message bundle file, we need to fill the file with key/value pairs for each label or&nbsp;text string that we want to display in the JSP page. Paste the contents from Figure 5.2 into your message bundle file and save it: <p><b><i>MessageBundle.properties</i></b> <p>user_name_label=User Name:<br>user_password_label=Password:<br>login_button_label=Login <p><b>Figure&nbsp;5.2: Contents of MessageBundle.properties</b> <p>Now that we have the MessageBundle complete, in the next section we will create the ManagedBean now that will handle our user logging in. <p><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top">Back to Top</a></b> <hr align="center" width="100%" size="2">  <p><b>6. <a></a>Creating the Managed Beans</b> <p>In this section we'll see how to create the ManagedBean that will perform the login operation when prompted by the login JSP page as well as store the user name and password entered by the user. For the purpose of this demo, the login operation simply checks if the username and password are both "myeclipse"&nbsp; and then redirects the user to the <i>userLoginSuccess.jsp</i> page. &nbsp;Otherwise it sends them back to the login page. <p>First open up the <b>faces-config.xml</b> file with the <i>MyEclipse JSF Editor</i>: <p><img height="484" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image008.gif" width="511" border="0"><br><b>Figure 6.1: Opening faces-config.xml file for editing</b> <p>With MyEclipse 4.0 the <b>faces-config.xml</b> editor has been enhanced from previous releases, not only can you create and manage your application flow (Navigation Cases) you can also create/edit and manage all the resources that go into the config file from the <b>Outline View</b>. You will click the down arrow in the top right corner of the <b>Outline View</b> in order to add the new bean as shown in <b>Figure 6.2</b>: <p><img height="543" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image009.gif" width="295" border="0"><br><b>Figure 6.2: Launch the ManagedBean wizard from the Outline View</b> <p>You will then be presented with the new Managed Bean wizard; &nbsp;Fill out the values as shown in Figures 6.3 and 6.4 below: <p><img height="561" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image010.gif" width="459" border="0"><br><b>Figure&nbsp;6.3: Setup the new ManagedBean's class and properties</b> <p><img height="561" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image011.gif" width="459" border="0"><br><b>Figure 6.4: Managed Bean Wizard Final Page </b> <p>You will now notice that the new UserBean was added to the <b>Outline View</b> as shown in Figure 6.5: <p><img height="171" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image012.gif" width="226" border="0"><br><b>Figure 6.5: UserBean now shown in the Outline View</b> <p>And the new UserBean.java source file will also be opened in the java editor: <p><img height="671" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image013.gif" width="724" border="0"><br><b>Figure 6.6: UserBean Java source opened up in an editor</b> <p>Notice that the getters and setters for our two properties (username and password) were already generated for us, so the only thing we need to add to this class is the implementation of the <b>loginUser</b> method that will be called to process the user login. <p>The code snippet for the loginUser method is in <b>Figure 6.7</b> below. &nbsp;Please copy and paste it into your file, adding any new imports as necessary: <p><b><i>UserBean.java</i></b> <p>&nbsp; &nbsp; public String loginUser() {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if("myeclipse".equals(getUserName()) &amp;&amp; "myeclipse".equals(getPassword()))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return "success";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FacesContext facesContext = FacesContext.getCurrentInstance();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FacesMessage facesMessage = new FacesMessage(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "You have entered an invalid user name and/or password");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; facesContext.addMessage("loginForm", facesMessage);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "failure";<br>&nbsp;&nbsp;&nbsp; } <p><b>Figure 6.7: loginUser code for the new UserBean.java file</b> <p>Looking at the bean code, we can notice some unique properties about it. For example, the UserBean class doesn't extend or implement any classes or interfaces tied to JSF. It is simply a javabean that includes the additional logic to perform a useful operation.&nbsp; In Struts terms, it contains all the functionality of a Struts Form and a Struts Action, conveniently located in one class.<br>Another thing to note is that unlike Struts, these methods do not return special classes, like an ActionForward, because navigation is specified externally in a declarative fashion in the <i>faces-config.xml</i> deployment descriptor.&nbsp; And, in <a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#running">Section&nbsp;8</a> we will show how this descriptor is created and configured. <p><b><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top">Back to Top</a></b> <hr align="center" width="100%" size="2">  <p><b>7. <a></a>Creating the JSP Pages</b> <p>In this section we are going to focus on creating the JSP pages for our example JSF application, which will mimic a simple website login screen.&nbsp; As a result, we will only need 2 JSP pages, one to prompt the user to login and the other to indicate that login was successful.&nbsp; We will call these pages <i>loginUser.jsp</i> and <i>loginUserSuccess.jsp</i>, respectively. For simplicity, if there is an authorization error during the login attempt, we will redirect the user back to the <i>loginUser.jsp</i> page. &nbsp;To avoid confusion, we are not using any validation in this demo, but you can easily add validators to the two inputText/Secret JSF components.&nbsp;&nbsp;We will use these fields&nbsp;to validate the user's entry for length and additionally display an error message if the login was incorrect. <p>Another new feature in MyEclipse 4.0 is the ability to create the web pages for our JSF application by editing the <i>faces-config.xml</i> file in the <i>MyEclipse JSF Editor</i>. So make sure that file is still open and we can get started creating our <i>userLogin.jsp</i> page. <p>To create our <i>userLogin.jsp</i> page we are going to first click the JSP button, then click on our canvas.&nbsp; When the new JSP wizard comes up, type in the File Name and select the JSF template as shown in Figure 7.1: <p><img height="633" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image014.gif" width="586" border="0"><br><b>Figure 7.1: Creating userLogin.jsp using the faces-config.xml editor</b> <p>We can also create our <i>userLoginSuccess.jsp</i> now in the same manner: <p><img height="653" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image015.gif" width="862" border="0"><br><b>Figure 7.2: Creating userLoginSuccess.jsp using the faces-config.xml editor</b> <p>Let's start working on our application now by opening up the <i>userLogin.jsp</i> page: <p><img height="738" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image016.gif" width="738" border="0"><br><b>Figure 7.3: Begin editing the userLogin.jsp page</b> <p>Something to notice from <b>Figure 7.3</b> are the tabs that run along the bottom of the MyEclipse editor (MyEclipse JSP Designer), you have your choice to edit this page in Source mode, Design mode, Design/Source mode or just Preview. For this demo we will switch to the Design/Source as it is very handy to have both views available&nbsp;while editing a page. What you will see right away looks very similar to <b>Figure 7.4</b> below: <p><img height="667" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image017.gif" width="745" border="0"><br><b>Figure 7.4: Switched to Design/Source mode and expanded JSF palettes</b> <p>Now, what we need to do now on this page is: <ul> <li>Add an h:inputText component for the user name  <li>Add an h:inputSecret component for the password  <li>Add an h:outputLabel for the user name inputText  <li>Add an h:outputLabel for the password </li></ul> <p><i>NOTE: In version 4.0 the JSF designer does not support rendering the MessageBundle values for outputLabel, so in order to see our outputLabels in the designer, we are going to manually change them in the code to wrap outputText components that have their values bound to our MessageBundle. This will be fixed in MyEclipse 4.1 release.</i><br>First thing we need to do is remove the default template text as well as type in our bundle basename so our page can use our MessageBundle.&nbsp; We will end up with JSP that looks like <b>Figure 7.5</b>:  <p><img height="291" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image018.gif" width="664" border="0"><br><b>Figure 7.5: Remove template text and add our MessageBundle to the JSP page</b> <p><img height="654" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image019.gif" width="776" border="0"> <p><b>Figure 7.5a: Create the new form</b> <p>In Figure 7.5a we create the new HTML form element that will contain our login controls. Now we need to actually create the input text boxes! <p>Now let's create our h:inputText component for the user name, this is shown in <b>Figures 7.6 and 7.7</b>: <p><img height="646" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image020.gif" width="861" border="0"><br><b>Figure 7.6: Adding new inputText component</b><br><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image021.gif" width="442" border="0"><br><b>Figure 7.7: Adding new inputText component continued</b> <p>Now let's add our h:inputSecret component (no labels yet): <p><img height="646" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image022.gif" width="854" border="0"><br><b>Figure 7.8 Adding new inputSecret component</b> <p><b><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image023.gif" width="442" border="0"><br>Figure 7.9 Adding new inputSecret component continued</b> <p>Now let's add the outputLabel's for both of our input components, starting with our userLabel:<a></a> <p><img height="601" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image024.gif" width="852" border="0"><br><b>Figure 7.10: Adding outputLabel component to our userName component</b> <p>We will also need to add a label for our h:inputSecret component in the same manner. After we are done, as mentioned above, let's manually change our h:outputLabel components to wrap h:outputText components that are bound to our MessageBundle so we can see them in the designer, it will look something like this:<br><img height="515" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image025.gif" width="530" border="0"><br><b>Figure 7.11: Adding outputText components to our labels</b> <p>Be sure to make the modification to both the userName label and password label. <p>Now it is time to add our login button, we will do that almost identically to how we have added the other components so far, as shown in <b>Figures 7.12 and 7.13</b>:<br><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image026.gif" width="441" border="0"><br><b>Figure 7.12: Adding a new commandButton component</b> <p><b><img height="559" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image027.gif" width="441" border="0"><br>Figure 7.13: Adding a new commandButton component continued</b> <p>Now we have a page that looks something like this:<br><img height="133" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image028.gif" width="1125" border="0"><br><b>Figure 7.14: Our almost-complete userLogin.jsp page</b> <p>You might notice that everything looks pretty ugly on 1 line, so let's add some space to put things on separate lines:<br><img height="130" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image029.gif" width="491" border="0"><br><b>Figure 7.15: Nicely laid out userLogin.jsp page</b> <p>Now that our <i>userLogin.jsp</i> page is done, let's quickly do our <i>userLoginSuccess.jsp</i> page which is much simpler. Open that file up and edit it, simply adding a line to print out the name of the user that logged in as shown in <b>Figure 7.16</b>: <p><img height="667" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image030.gif" width="908" border="0"><br><b>Figure 7.16: Making userLoginSuccess.jsp page print out the user's name</b> <p>Now that we have created our two pages, the only thing left for us to do is hook them together with proper Navigation Cases, that is done by visual editing our <i>faces-config.xml</i> file, so open that file. After the file is open for editing, perform the following steps to create the navigation case:&nbsp; <ol> <li>Click the Navigation Case tool <li>Click your <i>userLogin.jsp</i> file <li>Then click on your <i>userLoginSuccess.jsp</i> file <li>You will be prompted with a wizard to create the navigation case. </li></ol> <p>Follow Figures 7.17 and 7.18 for creating the <i>success</i> navigation case. In order to create the <i>failure</i> navigation case, we simply do the same steps as before but click twice on the <i>userLogin.jsp</i> file, in order to create a circular navigation case.<a></a> <p><img height="323" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image031.gif" width="531" border="0"><br><b>Figure 7.17: Creating the success navigation case</b> <p><b><img height="415" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image032.gif" width="500" border="0"><br>Figure 7.18: Creating the success navigation case continued</b> <p>After we have created both navigation cases, our file will look something like this: <p><img height="341" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image033.gif" width="539" border="0"><br><b>Figure 7.19: Reviewing navigation cases for our app</b> <p>Now that we have created all our JSP pages and added our Navigation Cases correctly, the only thing left is to run our application! <p><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top"><b>Back to Top</b></a> <hr align="center" width="100%" size="2">  <p><b>8. <a></a>Running the Application</b> <p>In this section we will quickly show what our new application looks like when its running.<br>We will use MyEclipse to deploy our application to Tomcat 5 and then launch the server so we can run the application.&nbsp; Complete details in how to set up an application server and deploy to it within MyEclipse is available in the <a href="http://myeclipseide.com/images/tutorials/me_remote_doc/appservers/index.html">Application Server Quickstart</a>.&nbsp; For the purposes of this example, we're going to assume that Tomcat 5 has already been configured for our use and we simply need to deploy our application to it.&nbsp; Deployment is done by the Manage Deployments dialog, which can be activated from the project's context menu by right-clicking on the project in the Package Explorer View and selecting <b>MyEclipse &gt; Add / Remove Deployments...</b>&nbsp; The Manage Deployments dialog, shown in <b>Figure 8.2</b>, will be launched.&nbsp; To add a deployment, simply click the Add button and the New Deployment wizard, will be opened. <p><img height="113" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image034.gif" width="337" border="0"><br><b>Figure 8.1: Open the Manage Deployments Dialog</b> <p><b><img height="490" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image035.gif" width="615" border="0"><br>Figure 8.2: Creating the new deployment for our project</b> <p>Select Tomcat 5 as the server, exploded archive as the deployment type, and select Finish as shown in <b>Figure 8.2</b>.&nbsp; After the wizard completes execution, the Deployment Manager will show that the deployment was successful.&nbsp; This is depicted in <b>Figure 8.3</b>.&nbsp; Now that the deployment has completed, you can select OK to close the dialog. <p><img height="445" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image036.gif" width="506" border="0"><br><b>Figure 8.3: Successful Deployment</b> <p>At this point the Tomcat 5 server can be started by selecting Start from the Tomcat 5 management menu from the main Eclipse toolbar, as shown in <b>Figure 8.4</b>, below. <p><img height="140" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image037.gif" width="305" border="0"><br><b>Figure 8.4: Starting Tomcat 5</b> <p>The output from the server log will be redirected to the Eclipse Console View.&nbsp; From the log shown in Figure 8.5, it is evident that the sever started successfully. <p><img height="311" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image038.gif" width="616" border="0"><br><b>Figure 8.5: Tomcat 5 Startup Log</b> <p>Once Tomcat 5 is running,&nbsp; we can test it by opening the MyEclipse Browser View.&nbsp; This can be done by clicking the Browser button as shown in <b>Figure 8.6</b>.<br><img height="114" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image039.gif" width="332" border="0"><br><b>Figure 8.6: Opening the Web Browser View</b> <p>&nbsp;In the browser's address bar, enter <a href="http://localhost:8080/JSFLoginDemo/userLogin.faces">http://localhost:8080/JSFLoginDemo/userLogin.faces</a> to activate the example application, as shown in Figure 8.7. <p><b>NOTE </b>:<i>The reason the URL ends in .faces and not .jsp is because&nbsp;above, we mapped our FacesServlet to the *.faces extension, that means in order for JSF to be&nbsp;given a chance to process the request and build out the component tree, we must use the .faces extension to access the actual pages. If you don't, you will get&nbsp;an exception along the lines of "FacesContext cannot be found".</i> <p><img height="185" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image040.gif" width="334" border="0"><br><b>Figure 8.7: Accessing the Example Application</b> <p>Now type in <b>myeclipse</b> for the user name and password and click Login to see your app in action! <p><img height="184" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image041.gif" width="328" border="0"><br><b>Figure 8.8: Logging in...</b> <p><img height="162" src="http://www.blogjava.net/images/blogjava_net/beansoft/WindowsLiveWriter/MyEclipseJSF_9C79/clip_image042.gif" width="319" border="0"><br><b>Figure 8.9: Successful Login</b> <p>We see our navigation rules kick in as we are validated and directed to the <i>userLoginSuccess.jsp</i> page where our name is displayed. While this application is certainly simple, it does convey the basics of developing a JSF application using MyEclipse. <p><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top"><b>Back to Top</b></a> <hr align="center" width="100%" size="2">  <p><b>9. <a></a>Summary</b> <p>In this demo we took a look at developing a simple JSF application using MyEclipse Enterprise Workbench. If you would like to download a zipped up version of the MyEclipse project used to create this demo, <a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/JSFLoginDemo.zip">click here</a> . This concludes&nbsp;your&nbsp;introduction to JSF. Additional Quickstart documents are available that introduce working with Web Projects, editing, application server configuration, enterprise application projects&nbsp;and&nbsp;database development. For more information visit the <a href="http://myeclipseide.com/ContentExpress-display-ceid-67.html#quickstarts">MyEclipse Quickstart library</a> .  <p><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top"><b>Back to Top</b></a> <hr align="center" width="100%" size="2">  <p><b>10. <a></a>User Feedback</b> <p>We welcome all constructive feedback. If you have comments or ideas for how to improve this document please go to the Documentation Forum on our Support Site.&nbsp; <a href="http://www.myeclipseide.com/PNphpBB2+file-viewforum-f-6.html">MyEclipse Documentation Forum</a> <p><a href="http://myeclipseide.com/images/tutorials/me_remote_doc/jsf/index.html#top"><b>Back to Top</b></a> <hr align="center" width="100%" size="2">  <p>Copyright ? 2003 - 2005 by Genuitec L.L.C</p> <img src ="http://www.blogjava.net/beansoft/aggbug/146713.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beansoft/" target="_blank">BeanSoft</a> 2007-09-20 11:08 <a href="http://www.blogjava.net/beansoft/archive/2007/09/20/146713.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>《jsf入门》简体中文版.rar 电子书下载</title><link>http://www.blogjava.net/beansoft/archive/2007/05/10/116486.html</link><dc:creator>BeanSoft</dc:creator><author>BeanSoft</author><pubDate>Thu, 10 May 2007 06:38:00 GMT</pubDate><guid>http://www.blogjava.net/beansoft/archive/2007/05/10/116486.html</guid><wfw:comment>http://www.blogjava.net/beansoft/comments/116486.html</wfw:comment><comments>http://www.blogjava.net/beansoft/archive/2007/05/10/116486.html#Feedback</comments><slash:comments>26</slash:comments><wfw:commentRss>http://www.blogjava.net/beansoft/comments/commentRss/116486.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beansoft/services/trackbacks/116486.html</trackback:ping><description><![CDATA[
		<p> </p>
		<p>
				<a href="/Files/beansoft/%E3%80%8Ajsf%E5%85%A5%E9%97%A8%E3%80%8B%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%E7%89%88.rar">《jsf入门》简体中文版.rar</a> 142KB </p>
		<p>来源: <a title="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=2630" href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=2630">http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=2630</a></p>
		<p>
		</p>
		<p>今天费了好大劲找到了简体版的下载,和大家分享.</p>
<img src ="http://www.blogjava.net/beansoft/aggbug/116486.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beansoft/" target="_blank">BeanSoft</a> 2007-05-10 14:38 <a href="http://www.blogjava.net/beansoft/archive/2007/05/10/116486.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转载: 来自 IBM 的 JSF 中文入门教程</title><link>http://www.blogjava.net/beansoft/archive/2007/04/26/113723.html</link><dc:creator>BeanSoft</dc:creator><author>BeanSoft</author><pubDate>Thu, 26 Apr 2007 03:22:00 GMT</pubDate><guid>http://www.blogjava.net/beansoft/archive/2007/04/26/113723.html</guid><wfw:comment>http://www.blogjava.net/beansoft/comments/113723.html</wfw:comment><comments>http://www.blogjava.net/beansoft/archive/2007/04/26/113723.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/beansoft/comments/commentRss/113723.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beansoft/services/trackbacks/113723.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<p>
				<a href="/Files/beansoft/j-jsf.zip">j-jsf.zip</a> 976KB 
</p>
		<p>
		</p>
		<p>内容有点老, 不过学习够用了. 
</p>
		<p>
		</p>
		<p>来源: <a title="http://www-128.ibm.com/developerworks/cn/views/java/tutorials.jsp?cv_doc_id=85059" href="http://www-128.ibm.com/developerworks/cn/views/java/tutorials.jsp?cv_doc_id=85059">http://www-128.ibm.com/developerworks/cn/views/java/tutorials.jsp?cv_doc_id=85059</a></p>
<img src ="http://www.blogjava.net/beansoft/aggbug/113723.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beansoft/" target="_blank">BeanSoft</a> 2007-04-26 11:22 <a href="http://www.blogjava.net/beansoft/archive/2007/04/26/113723.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>