日期:2014-05-16  浏览次数:20392 次

JSF2+Primefaces简单应用系列(一)

准备: netbeans6.9.1,glassfish3.0(netbeans自带),primefaces2.2.1(http://www.primefaces.org/downloads.html)

?

我们也先从jsf2的hello world开始

1、? 创建普通Web应用程序,如下图:

2、? 加入JSF2的jar包( glassfish服务器自带了 jsf2.0的jar包,不用单独添加了)

3、 ?? 建立HelloView类

[java] view plain copy
  1. package ?org.jineral.school.demo;??
  2. ??
  3. import ?javax.faces.bean.ManagedBean;??
  4. import ?javax.faces.bean.ViewScoped;??
  5. ??
  6. /** ?
  7. ?* ?
  8. ?*?@author?jineral ?
  9. ?*?@create?date?2011-11-20 ?
  10. ?*/ ??
  11. @ManagedBean (name?=? "helloView" )??
  12. @ViewScoped ??
  13. public ? class ?HelloView? implements ?Serializable?{???
  14. ??
  15. ????private ?String?hello;??
  16. ??
  17. ????public ?HelloView()?{??
  18. ????????hello="hello?world!" ;??
  19. ????}??
  20. ??
  21. ????public ?String?getHello()?{??
  22. ????????return ?hello;??
  23. ????}??
  24. ??
  25. ????public ? void ?setHello(String?hello)?{??
  26. ????????this .hello?=?hello;??
  27. ????}??
  28. ??
  29. }??

下面是配置web.xml 和制作 jsf的 hello页面
4、目录结构如下

5、建立JSF页面hello.xhtml,代码如下

[html] view plain copy
  1. < html ? xmlns = "http://www.w3.org/1999/xhtml" ??
  2. ??????xmlns:h = "http://java.sun.com/jsf/html" > ??
  3. ????< h:head > ??
  4. ????????< title > Facelet?Title </ title