GWT and Smart GWT

刚刚接触GWT,记录一下自己的问题:

1.今天把Smart GWT 和GWT-Ext弄混了,

我也注意到了下面:

GWT-Ext is no longer under active development and has been superseded by Smart GWT . Assistance will be provided to existing users of GWT-Ext looking to migrate to Smart GWT

但是下载时,下载了GWT-Ext 2.0.5 http://gwt-ext.com/download/ ,

以为它们会相互兼容呢,调试Smart GWT Showcase 提供的例子时,才发现,它们根本是两个完全不同的东西,费了好大劲才明白,哈,一直以为是版本不对呢。重新下载smartgwt-2.0 http://www.smartgwt.cn/

 

2.Smart GWT与GWT 整合

 

  创建GWT Project(GwtProject),引入smartgwt.jar,smartgwt-skins.jar,

在GwtProject.gwt.xml(自动生成的)加入下面一行:<inherits name="com.smartgwt.SmartGwt"/>

编译后,会在war/gwtproject(自动创建)下生成sc目录,这目录下的东西我还没全明白,目前只用到了skins,

其它以后慢慢研究。

  另外sc目录下有一个文件initsc.js,打开后发现if(!isomorphicDir){var isomorphicDir = "sc/";},原来sc目录是可以变的。在GwtProject.html(自动生成)中可以添加变量< script >  var  isomorphicDir  =  "gwtproject/sc /"</ script >

Note:如果SC目录设置不符,会出现404 error.

 

3.GWT RPC(Remote Procedure Calls)

 

   通过RPC,可以在client和server之间传递object对象。

     the step of RPC:

    1)Define an interface  for your service that extends RemoteService and lists all your RPC methods.

    2)Create a class that extends RemoteServiceServlet and implements the interface you created above.

    3)Define an asynchronous interface to your service to be called from the client-side code.

   @RemoteServiceRelativePath("stockPrices")
   public interface StockPriceService extends RemoteService {
       StockPrice[] getPrices(String[] symbols);
    }

    public class StockPriceServiceImpl extends RemoteServiceServlet implements  StockPriceService {

      //implemets the method StockPrice[] getPrices(String[] symbols);

   }

    public interface StockPriceServiceAsync {
         void getPrices(String[] symbols, AsyncCallback<StockPrice[]> callback);
    }

 

    Note: @RemoteServiceRelativePath 指定default path relative to the module base URL.

             StockPrice must be serializable.

   4)在Web.xml中添加映射

      <servlet>

              <servlet-name>stockPriceServiceImpl</servlet-name>

                <servlet-class>

                      com.google.gwt.sample.stockwatcher.server.StockPriceServiceImpl

               </servlet-class>

       </servlet>

   <servlet-mapping>

       <servlet-name>stockPriceServiceImpl</servlet-name>

       <url-pattern>/stockwatcher /stockPrices </url-pattern>

   </servlet-mapping>

//stockwatcher is set in StockWatcher.gwt.xml: <module rename-to='stockwatcher'>

//stockPrices is set by @RemoteServiceRelativePath

5)client调用:

  // Initialize the service proxy.
        StockPriceServiceAsync stockPriceSvc = GWT.create(StockPriceService.class);
        // Set up the callback object.
        AsyncCallback<StockPrice[]> callback = new AsyncCallback<StockPrice[]> () {
          public void onFailure (Throwable caught) {
            // TODO: Do something with errors.
          }
          public void onSuccess (StockPrice[] result) {
            //TODO: Do something with success.
          }
        };
        // Make the call to the stock price service.
        stockPriceSvc.getPrices(stocks.toArray(new String[0]), callback);

 

4.Image URLs in Smart GWT

 

alignCenterButton.setSrc("icons/24/text_align_center.png");
war/images/icons/24/text_align_center.png

stretchButton.setIcon("[SKINIMG]/actions/search.png");
..\sc\skins\Enterprise\images\actions\search.png

 

imgButton.setSrc("[SKIN]/Window/minimize.png");

..\sc\skins\Enterprise\images\Window\search.png

[SKINIMG] 与 [SKIN]的区别,还不太清楚。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值