本文目的,轻松实现ajax组件式编程,并引用轻量级框架完成WEB应用.
开发环境:myeclipse 6.01GA jave ee5 tomcat6.0
组件版本:jsf1.2(呵呵) spring2.0 hibernate3.2 icesoft1.62
1下载icesoft for myeclipse plugin
地址: http://www.icefaces.org//main/downloads/os-downloads.iface
2)创建web project
3)增加JSF框架
4)加入icesoft组件
5)加入SPRING框架
6)加入hibernate框架
7)创建一个xhtml页面
8)测试,http://localhost:8090/icesoft/test.iface 可以通过.
程序基本组织形式:
所有代码见附件.
其中没有包括的代码列表如下:
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> <application> <variable-resolver> org.springframework.web.jsf.DelegatingVariableResolver </variable-resolver> <view-handler> com.icesoft.faces.facelets.D2DFaceletViewHandler </view-handler> </application> <managed-bean> <managed-bean-name>prtAgeBean</managed-bean-name> <managed-bean-class> com.antbee.hnds.action.PrtAgeBean </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>proAgencyDAO</property-name> <value>#{proAgencyDAO}</value> </managed-property> </managed-bean> </faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="hnds4"> <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>com.icesoft.faces.uploadDirectory</param-name> <param-value>upload</param-value> </context-param> <context-param> <param-name>com.icesoft.faces.uploadMaxFileSize</param-name> <param-value>4048576</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <listener> <listener-class> com.icesoft.faces.util.event.servlet.ContextEventRepeater </listener-class> </listener> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet> <servlet-name>Persistent Faces Servlet</servlet-name> <servlet-class> com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet </servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet> <servlet-name>Blocking Servlet</servlet-name> <servlet-class> com.icesoft.faces.webapp.xmlhttp.BlockingServlet </servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet> <servlet-name>uploadServlet</servlet-name> <servlet-class> com.icesoft.faces.component.inputfile.FileUploadServlet </servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Persistent Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Persistent Faces Servlet</servlet-name> <url-pattern>/xmlhttp/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Persistent Faces Servlet</servlet-name> <url-pattern>*.iface</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Blocking Servlet</servlet-name> <url-pattern>/block/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>uploadServlet</servlet-name> <url-pattern>/uploadHtml</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!--Tomcat 5 Workaround: Listener used to initialize JSF on startup--> <!--Remove comment tags to enable listener. <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> --> <!--Tomcat 5 Workaround: Listener implementation to handle web application lifecycle event--> <!--Remove comment tags to enable listener. <listener> <listener-class>com.sun.faces.application.WebappLifecycleListener</listener-class> </listener> --> </web-app>
test2.html
<?xml version="1.0" encoding="UTF-8"?> <!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" xmlns:ice="http://www.icesoft.com/icefaces/component"> <head> <title>My Facelets Page</title> <ice:outputStyle rel='stylesheet' type='text/css' href='xmlhttp/css/xp/xp.css' /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> </head> <body> <f:view> <ice:form partialSubmit="true"> <ice:dataTable border="1" var="u" value="#{prtAgeBean.agency}" id="data" rows="10"> <f:facet name="header"> <ice:outputText value="机票代理人基本信息列表"></ice:outputText> </f:facet> <ice:column id="column1"> <ice:rowSelector></ice:rowSelector> <f:facet name="header"> <ice:outputText value="代理号"></ice:outputText> </f:facet> <ice:outputText value="#{u.id.offcIataCd}"></ice:outputText> </ice:column> <ice:column id="column2"> <f:facet name="header"> <ice:outputText value="Office号"></ice:outputText> </f:facet> <ice:outputText value="#{u.id.offcCd}"></ice:outputText> </ice:column> <ice:column id="column3"> <f:facet name="header"> <ice:outputText value="中文名称"></ice:outputText> </f:facet> <ice:outputText value="#{u.id.offcChnNm}"></ice:outputText> </ice:column> <ice:column id="column4"> <f:facet name="header"> <ice:outputText value="英文名称"></ice:outputText> </f:facet> <ice:outputText value="#{u.id.offcEngNm}"></ice:outputText> </ice:column> <ice:column id="column5"> <f:facet name="header"> <ice:outputText value="分布系统"></ice:outputText> </f:facet> <ice:outputText value="#{u.id.ttlSysCd}"></ice:outputText> </ice:column> <f:facet name="footer"> <ice:outputText value="共有#{prtAgeBean.agency.rowCount}条记录!"></ice:outputText> </f:facet> </ice:dataTable> <ice:panelGrid border="1" columns="1" styleClass="scrollerTable2" columnClasses="standardTable_ColumnCentered" style="width: 552px; "> <ice:dataPaginator for="data" fastStep="10" pageCountVar="pageCount" pageIndexVar="pageIndex" paginator="true" paginatorMaxPages="9"> <f:facet name="first"> <ice:graphicImage style="border:none;" url="xmlhttp/css/xp/css-images/arrow-first.gif"></ice:graphicImage> </f:facet> <f:facet name="last"> <ice:graphicImage style="border:none;" url="xmlhttp/css/xp/css-images/arrow-last.gif"></ice:graphicImage> </f:facet> <f:facet name="previous"> <ice:graphicImage style="border:none;" url="xmlhttp/css/xp/css-images/arrow-previous.gif"></ice:graphicImage> </f:facet> <f:facet name="next"> <ice:graphicImage style="border:none;" url="xmlhttp/css/xp/css-images/arrow-next.gif"></ice:graphicImage> </f:facet> <f:facet name="fastforward"> <ice:graphicImage style="border:none;" url="xmlhttp/css/xp/css-images/arrow-ff.gif"></ice:graphicImage> </f:facet> <f:facet name="fastrewind"> <ice:graphicImage style="border:none;" url="xmlhttp/css/xp/css-images/arrow-fr.gif"></ice:graphicImage> </f:facet> </ice:dataPaginator> </ice:panelGrid> </ice:form> </f:view> </body> </html>