JSF开发(2)

JSF是一个规范,并没有做实现,目前比较流行或者主要的实现有MyFaces、IceFaces和RichFaces。本人刚刚入门,对这些实现具体细节的差别没有搞明白,但我想应该都差不多的。
项目中,使用了RichFaces,所以就如何使用RichFaces做说明。
搭建开发环境:
1、在MyEclipse中建立web工程。
   引入jar包
   richfaces-api-3.2.0.GA.jar
   richfaces-impl-3.2.0.GA.jar
   richfaces-ui-3.2.0.GA.jar
   commons-logging.jar
   commons-digester.jar
   commons-collections.jar
   commons-collections-3.2.jar
2、配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>a4jEchoText</display-name>
   

    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>blueSky</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
   
    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
   

    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
   
   


    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
     


    <!-- 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>
     
    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
    </web-app>
3、配置faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD  JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>  
      <managed-bean>
        <managed-bean-name>bean</managed-bean-name>
        <managed-bean-class>demo.Bean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
          <property-name>text</property-name>
          <value/>
        </managed-property>
      </managed-bean>
    </faces-config>
4、写back bean
public class Bean
{
   private String text = "aaaaaaaa";
  

   public String getText() {
      return text;
   }
   public void setText(String text) {
     this.text = text;
   }
5、写jsp页面
<f:view>
  <h:form id="testForm">
    <rich:panel header="Simple Echo">
       <h:inputText size="50" value="#{bean.text}" >
       <a4j:support event="onkeyup" reRender="rep"   limitToList="true" data="#{bean.text}" oncomplete="alert(data)"/>
       </h:inputText>
       <h:outputText value="#{bean.text}" id="rep" />
     </rich:panel>
  </h:form>
</f:view>

访问时,首先将此发布到tomcat下,访问:http://localhost:8080/Richfaces/test.jsf即可。
这样一个完整的jsf  demo就算完成了。
}

你可能感兴趣的:(bean,MyEclipse,servlet,JSF,Richfaces)