1,搭建jsf2.0的环境,
建立web项目,添加jsf2.0支持,编写HelloWorld.java helloworld.xhtml 2,添加primefaces的支持jar包, primefaces-2.2.1.jar 和3版本的不同之处,
- package Test;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.SessionScoped;
- @ManagedBean(name="hello")
- @SessionScoped
- public class HelloWorld implements java.io.Serializable{
- private static final long serialVersionUID = 6866250699219535733L;
- private String name;
- /**
- * @return the name
- */
- public String getName() {
- this.name = "World";
- return name;
- }
- }
helloworld.xhtml
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:ui="http://java.sun.com/jsf/facelets">
- <h:head>
- <title>Hello World</title>
- <meta http-equiv="keywords" content="enter,your,keywords,here" />
- <meta http-equiv="description" content="A short description of this page." />
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- </h:head>
- <h:body>
- <h:form id="form">
- <div style="padding:100px 0 0 100px;font-size:22px;font-weight:bold">
- Hello,#{hello.name}!
- </div>
- </h:form>
- </h:body>
- </html>