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]的区别,还不太清楚。

你可能感兴趣的:(xml,servlet,ext,Google,gwt)