smartgwt (A)
? smartgwt一個比較陌生的名字,卻充滿了神奇,模糊了web應用和windows應用的界限。很多人聽過gwt,是的,用java寫Ajax,smartgwt不僅多了一層華麗的包裝,而且將gwt發揮到了極致!三者結合所產生的優勢:跨操作系統、跨瀏覽器(主流的)、異步的實現web應用程序。
? smartgwt很大的一個特點是,即使你不會美工,也能將頁面處理的很得體,很美觀(限網絡應用程序,不需要太多的修飾)。
grid:? ?? tree:
? 在開始smartgwt編碼前,有很多準備工作。
? 先去了解“Google 網頁工具包 ”,站內有很詳細的文檔和實例。IBM中國也有不少例子,值得了解。當完成第一個異步相應的例子時,你一定覺得,異步原來這么輕松有趣。接下來就要去裝點界面,去了解smartgwt 豐富的界面,在google的項目站點能找到不少資料,還有官網的論壇 ,很多問題能在那里解決!下載完smartgwt,解壓部署里面的war,就是官網提供的在線例子,頁面中提供源代碼,這是了解smartgwt最好的途徑,也可以運行源代碼。
? 我目前的開發環境:jdk 1.6,netbeans 6.7(加gwt4nb插件),firefox 3.5(加firebug插件),mssql 2000打好補丁,tomcat 6.0
? 開發框架:smartgwt,gwt,spring,hibernate(jpa)
? 開發類庫:
(有些類庫要按照應用的需求來選擇,并不一定用得到)
? 現在是將smartgwt和gwt框架整合的時候了。當然,還要整合spring和hibernate,了解SSH的應該都知道,就不多說了。
新建一個web應用程序的項目。
web.xml(片段)配置spring入口
<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/classes/com/smartgwt/sample/showcase/server/resources/applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
加載應用的集中配置文件applicationContext.xml,加載數據庫,dao,service和gwt的配置文件。
<import resource="applicationContext-database.xml" /> <import resource="applicationContext-DAO.xml" /> <import resource="applicationContext-Service.xml" /> <import resource="applicationContext-GWT.xml" />
applicationContext-database.xml
<!-- Hibernate EntityManager Factory --><bean id="entityManagerFactory"class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"><property name="persistenceXmlLocation" value="classpath:persistence.xml"/><property name="jpaVendorAdapter"><beanclass="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"><property name="showSql" value="true" /><property name="generateDdl" value="true" /><property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" /></bean></property></bean><!-- Data source --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName"><value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value></property><property name="url"><value>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db;SelectMethod=Cursor</value></property><property name="username"><value>username</value></property><property name="password"><value>password</value></property></bean><!-- Transaction manager --><bean id="transactionManager"class="org.springframework.orm.jpa.JpaTransactionManager"></bean><bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /><tx:annotation-driven />
applicationContext-DAO.xml(片段)
<bean id="xtyhDAO" class="com.smartgwt.sample.showcase.server.dao.jpa.XTYHDAO"/>
applicationContext-Service.xml(片段)
<bean id="ixtyhService" class="com.smartgwt.sample.showcase.server.service.implementation.XTYHService"><property name="xtyhDAO" ref="xtyhDAO" /> </bean>
applicationContext-GWT.xml
<!-- hibernate4gwt configuration --> <bean id="pojoStore" class="net.sf.hibernate4gwt.core.store.stateless.StatelessPojoStore" /> <bean id="hibernateBeanManager" class="net.sf.hibernate4gwt.core.HibernateBeanManager"><property name="pojoStore" ref="pojoStore" /><property name="entityManagerFactory" ref="entityManagerFactory" /> </bean>
日志配置文件和持久化單元:
persistence.xml(片段)
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL"><class>com.smartgwt.sample.showcase.client.XT_YH</class> </persistence-unit>
gwt的配置文件
Showcase.gwt.xml
<module><inherits name='com.google.gwt.user.User'/><inherits name="com.google.gwt.core.Core"/><inherits name="com.google.gwt.user.History"/> <inherits name="com.smartgwt.SmartGwtNoScript"/><!-- 皮膚 --><inherits name="com.smartclient.theme.treefrog.TreeFrogResources"/><!-- 國際化(非必需) --><inherits name='com.google.gwt.i18n.I18N'/><!-- 與hibernate持久化映射(非必需) --><inherits name='net.sf.hibernate4gwt.Hibernate4Gwt15'/><inherits name='net.sf.hibernate4gwt.emul.java5.ejb3.Ejb3'/><!-- gwt特殊math類型(非必需) --><inherits name="com.googlecode.gwt.math.Math"/><!-- smartgwt主程序入口 --><entry-point class='com.smartgwt.sample.showcase.client.Showcase'/><!-- Additional source path(非必需) --><source path='domain'/><source path='exception'/><source path='client'/><!-- 語言環境(非必需) --><extend-property name="locale" values="zh_CN" /> </module>
smartgwt主程序入口這里要說明下,如果下載了gwt4nb插件,新建項目時會自動生成,只要填寫生成客戶端的路徑和gwt安裝的路徑。
gwt.properties
# The name of the module to compile gwt.module=com.smartgwt.sample.showcase.Showcase # Path of the GWT installation directory.Use Internet-Standard of forward slases for this path gwt.install.dir=D:/gwt/gwt-windows-1.6.4 # Folder within the web app context path where the output # of the GWT module compilation will be stored. gwt.output.dir=/com.smartgwt.sample.showcase.Showcase # Script output style: OBF[USCATED], PRETTY, or DETAILED gwt.compiler.output.style=OBF # The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, gwt.compiler.logLevel=WARN # Script output style: OBF[USCATED], PRETTY, or DETAILED gwt.shell.output.style=OBF # The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, gwt.shell.logLevel=WARN # Additional JVM arguments for the GWT compiler gwt.compiler.jvmargs=-Xmx256M # Specifies the number of local workers to use whe compiling permutations and module(s) gwt.compiler.local.workers=1 # Additional JVM arguments for the GWT shell/GWT hosted mode (GWT 1.6) gwt.shell.jvmargs=-Xmx256M # GWT version: 1.5 or 1.6 gwt.version=1.6
?
?
以上是所有的配置文件,下來進入代碼部分...
總結
以上是生活随笔為你收集整理的smartgwt (A)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 钉钉注册阿里云账号全流程
- 下一篇: vxworks 笔记