jsf2.0牛刀小试

1.在eclipse3.0中新建动态web项目jsfTest
  把src目录修改为src.java
  把webRoot修改为web
2.添加jar包
 这里我使用的是jsf2.0版本的
 所以需要:
   jsf-impl.jar jsf-api.jar
 还有一些基本包:
commons-digester-1.8.jar commons-logging-1.1.1.jar commons-collections-3.2.jar commons-beanutils-1.7.0.jar standard.jar jstl-1.1.0.jar
3.然后就是修改web.xml文件了
 先加上faces的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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
  <context-param><!--这里是告诉系统默认的页面是xhtml页面 -->
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
4.创建backing bean

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class SubscriberAction implements Serializable {

public SubscriberAction() {
super();
// TODO Auto-generated constructor stub
}
public String userName;
public String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String checkLogin() {
return "pages/aaa.xhtml";
}
}
5.创建国际化实现
  在src.java的目录下新建一个文件夹resource.Config
新建三个文件messageUI_en_US.properties
messageUI_zh_CN.properties
messageUI.properties
6.新建xhtml页面
这里我用的是html的模板
<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core">
<head>
  <title><ui:insert name="title">Default title</ui:insert></title>
</head>

<body>

<div id="header">
    <ui:insert name="header">
      Header area.  See comments below this line in the source.
      <!--  include your header file or uncomment the include below and create header.xhtml in this directory -->
      <!-- <ui:include src="header.xhtml"/> -->
    </ui:insert>
</div>


<div id="content">
  <ui:insert name="content">
  <f:loadBundle basename="resource.Config.messageUI" var="msg"/>
      Content area.  See comments below this line in the source.
      <!--  include your content file or uncomment the include below and create content.xhtml in this directory -->
   <!-- <div> -->
      <!-- <ui:include src="content.xhtml"/> -->  
      <!-- </div> -->
      <h:form> 
      <h:panelGrid columns="2">
      #{msg.nameText}<h:inputText value="#{subscriberAction.userName}"/>
      #{msg.passText}<h:inputText value="#{subscriberAction.password}"/>
      </h:panelGrid>
      <h:commandButton value="#{msg.commandText}" action="#{subscriberAction.checkLogin}"/>
      </h:form>
     
  </ui:insert>
</div>

 
<div id="footer">
  <ui:insert name="footer">
      Footer area.  See comments below this line in the source.
      <!--  include your header file or uncomment the include below and create footer.xhtml in this directory -->
<!--<ui:include src="footer.xhtml"/>  -->
  </ui:insert>
</div>

</body>

</html>
7.效果如下:
 
只是做的一个简单的小例子 不要见笑哦
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值