<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    VIRGIN FOREST OF JAVA
    不要埋頭苦干,要學習,學習,再學習。。。。。
    powered by R.Zeus

    Implementing the catalog

    The starting point of a DWR application is writing your server-side object model. In this case, I start by writing a DAO to provide search capabilities on the product catalog datastore. CatalogDAO.java is a simple, stateless class with a zero-argument constructor. Listing 1 shows the signatures of the Java methods that I want to expose to Ajax clients:



    Listing 1. The CatalogDAO methods to expose via DWR
    /**
     * Returns a list of items in the catalog that have 
     *  names or descriptions matching the search expression
     * @param expression Text to search for in item names 
     *  and descriptions 
     * @return list of all matching items
     */
    public List<Item> findItems(String expression);
    
    /**
     * Returns the Item corresponding to a given Item ID
     * @param id The ID code of the item
     * @return the matching Item
     */
    public Item getItem(String id);
    

    Next, I need to configure DWR, telling it that Ajax clients should be able to construct a CatalogDAO and call these methods. I do this with the dwr.xml config file shown in Listing 2:



    Listing 2. Config to expose CatalogDAO methods
    <!DOCTYPE dwr PUBLIC
      "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
      "http://www.getahead.ltd.uk/dwr/dwr10.dtd">
    <dwr>
      <allow>
        <create creator="new" javascript="catalog">
          <param name="class" 
            value="developerworks.ajax.store.CatalogDAO"/>
          <include method="getItem"/> 
          <include method="findItems"/> 
        </create> 
        <convert converter="bean" 
          match="developerworks.ajax.store.Item">
          <param name="include" 
            value="id,name,description,formattedPrice"/>
        </convert>
      </allow>
    </dwr>
    

    The root element of the dwr.xml document is dwr. Inside this element is the allow element, which specifies the classes that DWR will remote. The two child elements of allow are create and convert.

    The create element

    The create element tells DWR that a server-side class should be exposed to Ajax requests and defines how DWR should obtain an instance of that class to remote. The creator attribute here is set to the value new, meaning that DWR should call the class's default constructor to obtain an instance. Other possibilities are to create an instance through a fragment of script using the Bean Scripting Framework (BSF), or to obtain an instance via integration with the IOC container, Spring. By default, when an Ajax request to DWR invokes a creator, the instantiated object is placed in page scope and therefore is no longer available after the request completes. In the case of the stateless CatalogDAO, this is fine.

    The javascript attribute of create specifies the name by which the object will be accessible from JavaScript code. Nested within the create element, a param element specifies the Java class that the creator will create. Finally, include elements specify the names of the methods that should be exposed. Explicitly stating the methods to expose is good practice to avoid accidentally allowing access to potentially harmful functionality -- if this element is omitted, all of the class's methods will be exposed to remote calls. Alternately, you can use exclude elements to specify only those methods you wish to prevent access to.

    The convert element

    While creators are concerned with exposing classes and their methods for Web remoting, convertors are concerned with the parameters and return types of those methods. The role of the convert element is to tell DWR how to convert datatypes between their server-side Java object representation and serialized JavaScript representation, and vice versa.

    DWR automatically mediates simple data types between Java and JavaScript representations. These types include Java primitives, along with their respective class representations, as well as Strings and Dates, arrays, and collection types. DWR can also convert JavaBeans into JavaScript representations, but for security reasons, doing so requires explicit configuration.

    The convert element in Listing 2 tells DWR to use its reflection-based bean convertor for the Items returned by the exposed methods of CatalogDAO and specifies which of the Item's members should be included in the serialization. The members are specified using the JavaBean naming convention, so DWR will call the corresponding get methods. In this case, I'm omitting the numerical price field and instead including the formattedPrice field, which is currency-formatted ready for display.

    At this point, I'm ready to deploy my dwr.xml to my Web application's WEB-INF directory, where the DWR servlet will pick it up. Before proceeding, however, it's a good idea to ensure that everything is working as expected.

    posted on 2007-01-17 16:52 R.Zeus 閱讀(355) 評論(0)  編輯  收藏 所屬分類: AJAX

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲黄色三级视频| 国产成人精品久久亚洲高清不卡 | 国产精品亚洲片在线观看不卡 | 一级成人a毛片免费播放| 亚洲日产无码中文字幕| 波霸在线精品视频免费观看| 亚洲中文字幕无码久久综合网| 国产福利免费视频| 亚洲人成网站在线播放vr| a级成人毛片免费视频高清| 亚洲国产成人久久综合碰碰动漫3d| 91视频精品全国免费观看| 亚洲AV无码专区亚洲AV伊甸园| 无码A级毛片免费视频内谢| 337p日本欧洲亚洲大胆色噜噜| 久久久久av无码免费网| 亚洲国产日韩综合久久精品| 日韩视频免费一区二区三区| 在线播放免费人成视频网站| 亚洲色欲色欲www在线丝| 99xxoo视频在线永久免费观看| 亚洲黄色免费网址| 四虎免费在线观看| 一区视频免费观看| 亚洲AV无码专区国产乱码4SE| 曰批全过程免费视频播放网站| 国产精品高清视亚洲一区二区| 四虎永久成人免费| 日本免费人成网ww555在线| 亚洲成a人片在线观| 日本一区二区三区日本免费| 国产精品永久免费| 亚洲国产超清无码专区| 免费的一级片网站| 久久精品国产免费一区| 亚洲中文字幕久久精品无码2021| 国产无遮挡吃胸膜奶免费看视频| 久久99免费视频| 亚洲国产精品ⅴa在线观看| 亚洲色欲久久久综合网| 青娱分类视频精品免费2|