- 浏览: 766715 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (386)
- Linux (36)
- Tomcat (6)
- windows (8)
- Apache (10)
- Java (25)
- jquery (7)
- Jquery 插件 (3)
- Oracle (5)
- Oracle SQL (68)
- Spring (15)
- 开发工具 (6)
- Struts (20)
- js (14)
- Project Code (2)
- Project Code Tomcat (1)
- libset (1)
- JSP (8)
- arithmetic (2)
- 浏览器 (1)
- extjs (3)
- 学习网站 (5)
- 生活情感 (0)
- 电话号码算法 (3)
- 快捷键 (1)
- 转载 (1)
- Dos命令 (2)
- services (1)
- Resources (1)
- 行业积累 (3)
- 项目积累 (3)
- Web (3)
- 文档 (1)
- JavaEE (2)
- JSF (3)
- http (3)
- JS窗口 (1)
- Html (4)
- Flex (1)
- 资讯 (2)
- 项目规范 (1)
- Struts s:property textarea中默认值用 (1)
- Quartz 2.0.2 (12)
- 1天有多少毫秒 (1)
- 专题 (1)
- intellij idea 10 CD-KEY (1)
- restlet (4)
- Mail (1)
- Excel (3)
- Menu (1)
- Big Data技术综述 (1)
- Quart 1 (1)
- nosql (1)
- linux远程 (1)
- jdk (5)
- wind7 (1)
- 虚拟人 (0)
- 虚拟机 (1)
- 终端 (1)
- Ubuntu (16)
- Myeclipse (2)
- Wmware (1)
- eclipse (2)
- css (2)
- csv (1)
- 开源 (1)
- plsql (2)
- cassandra (4)
- maven (1)
- hadoop (2)
- mysql (1)
- spring security (1)
- tools (1)
- jdbc (2)
- exception (2)
- 硬盘数据备份 (1)
- dwr (1)
- svn (1)
- PowerDesigner15使用时的十五个问题 (1)
- tomcat 项目发部路径 (1)
- js 暂停执行 (1)
- jquery jqgrid 格式化数据显示 (1)
- js 代码模板 (1)
- strutss2 直接跳转到jsp页面 (1)
- servlet (1)
- jdbc spring (1)
- js学习网站 (1)
- 自学考试 (2)
- hibernate (2)
- eos (1)
- c (4)
- 黑马 (2)
- 大数据 (2)
- 实战云大数据案例分享 (0)
- Spark (2)
- Flink (1)
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
jquery button 漂亮 -
thinktothings:
Array_06 写道你好,我是一名刚毕业学生,我以后就是做J ...
如何转型架构师 -
thinktothings:
软考,考有职业资格证,有系统的知识体系学习
如何转型架构师 -
Array_06:
你好,我是一名刚毕业学生,我以后就是做Java的架构师,那请问 ...
如何转型架构师 -
beykery:
你这也太复杂了。。。。jsf2不应该是这样的。。。。
JSF2.0的一个简单Demo
学习javaeetutorial6.pdf 106页到113页 附件中javaeetutorial6.zip
环增需求:JDK1.6 服务器:tomcat6.0.29 web项目 框架:JSF2.0
简单描述:项目启动后,进入欢迎界面faces/greeting.xhtml
<welcome-file-list>
<welcome-file>faces/greeting.xhtml</welcome-file>
</welcome-file-list>
被
Servlet
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
交给JSF处理
进入faces-config.xml的配置
/greeting.xhtml
<navigation-rule>
<description>
The decision rule used by the NavigationHandler to
determine which view must be displayed after the
current view, greeting.jsp is processed.
</description>
<from-view-id>/greeting.xhtml</from-view-id>
<navigation-case>
<description>
Indicates to the NavigationHandler that the response.jsp
view must be displayed if the Action referenced by a
UICommand component on the greeting.jsp view returns
the outcome "success".
</description>
<from-outcome>success</from-outcome>
<to-view-id>/response.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
由于请求的操作,应该action默认的不是success 即<from-outcome>success</from-outcome>
不符合,所以直接返回请求页面/greeting.xhtml
进入开始页面,
<managed-bean>
<description>
The backing bean that backs up the guessNumber Web application
</description>
<managed-bean-name>UserNumberBean</managed-bean-name>
<managed-bean-class>guessNumber.UserNumberBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>minimum</property-name>
<property-class>long</property-class>
<value>0</value>
</managed-property>
<managed-property>
<property-name>maximum</property-name>
<property-class>long</property-class>
<value>10</value>
</managed-property>
</managed-bean>
配的是Session作用域,所以每次请求的,bean只有第一次会被实例化(无参构造函数生成的随机数就被确定了,以后的请求这这个值是不会改变的),然后是返回结果页面response.xhtml只显示Bean中的UserNumberBean.response,如果用户输的value等于随机数就显示猜对了,否则显示猜错了。。
JSF的一个简单例子:
说明:
Web\WEB-INF\web.xml配置
<!--上下文参数--> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <!--servlet路径拦截--> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <!--session的生命周期--> <session-config> <session-timeout> 30 </session-timeout> </session-config> <!--欢迎页面--> <welcome-file-list> <welcome-file>faces/greeting.xhtml</welcome-file> </welcome-file-list>
Web\WEB-INF\faces-config.xml配置
<!-- =========== FULL CONFIGURATION FILE ================================== --> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0"> <application> <resource-bundle> <base-name>guessNumber.ApplicationMessages</base-name> <var>ErrMsg</var> </resource-bundle> <locale-config> <default-locale>en</default-locale> </locale-config> </application> <managed-bean> <description> The backing bean that backs up the guessNumber Web application </description> <managed-bean-name>UserNumberBean</managed-bean-name> <managed-bean-class>guessNumber.UserNumberBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>minimum</property-name> <property-class>long</property-class> <value>0</value> </managed-property> <managed-property> <property-name>maximum</property-name> <property-class>long</property-class> <value>10</value> </managed-property> </managed-bean> <navigation-rule> <description> The decision rule used by the NavigationHandler to determine which view must be displayed after the current view, greeting.jsp is processed. </description> <from-view-id>/greeting.xhtml</from-view-id> <navigation-case> <description> Indicates to the NavigationHandler that the response.jsp view must be displayed if the Action referenced by a UICommand component on the greeting.jsp view returns the outcome "success". </description> <from-outcome>success</from-outcome> <to-view-id>/response.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <description> The decision rules used by the NavigationHandler to determine which view must be displayed after the current view, response.jsp is processed. </description> <from-view-id>/response.xhtml</from-view-id> <navigation-case> <description> Indicates to the NavigationHandler that the greeting.jsp view must be displayed if the Action referenced by a UICommand component on the response.jsp view returns the outcome "success". </description> <from-outcome>success</from-outcome> <to-view-id>/greeting.xhtml</to-view-id> </navigation-case> </navigation-rule> </faces-config>
guessNumber.UserNumberBean.java
/* * Copyright 2009 Sun Microsystems, Inc. * All rights reserved. You may not modify, use, * reproduce, or distribute this software except in * compliance with the terms of the License at: * http://developer.sun.com/berkeley_license.html */ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guessNumber; import java.util.Random; public class UserNumberBean { Integer randomInt = null; Integer userNumber = null; String response = null; private boolean maximumSet = false; private boolean minimumSet = false; private long maximum = 0; private long minimum = 0; public UserNumberBean() { Random randomGR = new Random(); randomInt = new Integer(randomGR.nextInt(10)); System.out.println("Duke's number: " + randomInt); } public void setUserNumber(Integer user_number) { userNumber = user_number; } public Integer getUserNumber() { return userNumber; } public String getResponse() { if ((userNumber != null) && (userNumber.compareTo(randomInt) == 0)) { return "Yay! You got it!"; } else { return "Sorry, " + userNumber + " is incorrect."; } } public long getMaximum() { return (this.maximum); } public void setMaximum(long maximum) { this.maximum = maximum; this.maximumSet = true; } public long getMinimum() { return (this.minimum); } public void setMinimum(long minimum) { this.minimum = minimum; this.minimumSet = true; } }
相关推荐
包括richfaces mysql log4j 在eclipse里手动配置环境经常会因jar出现种种问题,我把完整的jsf2.0 spring2.5 hibernate3整合所有jar传上来希望有用 如果有需要我会传上一个jsf2.0 spring hibernate的小demo上来
引用别人的Demo,自己运行。做个备份。 http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/
学习的好助手richfaces-demo-jsf2-3.3.3.CR1-tomcat6.war
jsf1.2+spring2.0+hibernate3.2整合demo part1
JavaServer Faces+eclipse,入门教程。本人觉得挺好用,和jsp细节不同。需要自己体会
本程序使用JSF2.0,WELD(CDI)1.0 ,ibatis开发的一个个人日志系统,系统功能很简单. 本demo谨献给热爱java,学习weld(CDI)的朋友们.
根据以往做过的ICEface的经验, 初次尝试了ICEFaces 2.0Beta. 极力推荐这个便捷的AJAX框架.开发工具是Intellij Idea 9.0.3. 废话少说,各自体验吧.
此项目设置为允许您使用 JSF 2.0、CDI 1.0、EJB 3.1、JPA 2.0 和 Bean Validation 1.0 创建兼容的 Java EE 7 应用程序。 它包括一个持久性单元和一些示例持久性和事务代码,向您介绍企业 Java 中的数据库访问。系统...
本教程分析了 Spring Web Flow 2.0 的技术要点,并且通过创建一个示例应用程序,展示了 Spring Web Flow 2.0 的基本知识。 开始之前 关于本教程 本教程通过一个简化的购物车应用,介绍了如何使用 Spring Web Flow ...
PrettyFaces: EL API访问PrettyContext 支持JSF 1.1 增强了错误页面和servlet重定向 PrettyFaces是一个JSF1.2和JSF2.0的扩展,用来创建便于书签收藏、漂亮的网址。 PrettyFaces优雅的解决了这个问题,包括诸如功能:...
commons-digester-2.0.jar, commons-fileupload-1.3.2.jar, commons-io-2.2.jar, commons-lang-2.4.jar, commons-lang3-3.2.jar, commons-logging-1.1.3.jar, commons-validator-1.3.1.jar, core-0.6.2.jar, dwr-...
struts2-osgi-demo-bundle-2.3.15.3.jar struts2-osgi-plugin-2.3.15.3.jar struts2-oval-plugin-2.3.15.3.jar struts2-pell-multipart-plugin-2.3.15.3.jar struts2-plexus-plugin-2.3.15.3.jar struts2-portlet-...