posts - 56, comments - 54, trackbacks - 0, articles - 4
             ::  ::  :: 聯(lián)系 :: 聚合  :: 管理
          STRUTS的 ActionForm到現(xiàn)在為止,出現(xiàn)了最少三種方式: 普通的,動(dòng)態(tài)的和懶的.

          所以你在你自已的開發(fā)中,可以有很多選擇,如果你安全第一,可以用普通的.如果你更喜歡XML,則用動(dòng)態(tài)的.

          如果你很懶,那就用Lazy ActionForm.? available in Version 1.2.6 onwards

          STRUTS提供的這三種ActionForm方式,要實(shí)際應(yīng)用中你只要選擇一種就可以了.

          下面說說Lazy ActionForm:?

          如果你喜歡STRUTS的強(qiáng)大的功能的特性(就比如這個(gè)ActionForm有多種選擇),又喜歡快捷, Lazy ActionForm對(duì)你來說是一個(gè)好消息. 這個(gè)有點(diǎn)類似于WW2中值得稱道的一個(gè)特性,可以減少編寫ActionForm的麻煩.(STRUTS正在把WW2中好的東西都吸收進(jìn)來了,難怪這兩個(gè)東西以后會(huì)合并為STRUTS IT).

          示例代碼如下:

          struts-config.xml配置
          <struts-config>?

          ? <form-beans>?
          ?????<form-bean name="lazyForm" type="org.apache.struts.validator.LazyValidatorForm"/>?
          ??</form-beans>?

          ??<action-mappings>?
          ? ??<action path="/myActionPath" type="myPackage.MyAction" name="lazyForm" validate="true"/>?
          ??</action-mappings>

          </struts-config>
          JSP網(wǎng)頁
          <html:form action="/myActionPath">?

          ? <h2>Simple Property Example</h2>
          ? ? ? ? ?
          ? ? ? ? ? Customer Number: <html:text property="custNo"/>
          ? ? ? ? ? Customer Name:? ?<html:text property="custName"/>?

          ? <h2>Mapped Property Example</h2>
          ? ? ? ? ?
          ? ? ? ? ? Street:? <html:text property="address(street)"/>
          ? ? ? ? ? Town:? ? <html:text property="address(town)"/>
          ? ? ? ? ? State:? ?<html:text property="address(state)"/>
          ? ? ? ? ? Country: <html:text property="address(country)"/>?

          ? <h2>Indexed Property Example</h2>?
          ??????????
          ? <logic:iterate id="products" property="products">?
          ????Product Code:<html:text name="products" property="code" indexed="true"/>?
          ????Product Description:<html:text name="products" property="description" indexed="true"/>?
          ????Product Price:<html:text name="products" property="price"?indexed="true"/>?
          ? </logic:iterate>

          </html:form>
          action調(diào)用
          java代碼:?
          public ActionForward execute(ActionMapping mapping,
          ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ActionForm form,
          ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?HttpServeletRequest request,
          ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?HttpServletResponse response)throwsException{?
          ????// Cast form to DynaBean?
          ????DynaBean dynaForm = (DynaBean)form;?

          ????// Use the DynaBean?
          ????String custNo = (String)dynaForm.get("custNo");? ?// simple?
          ????Map address? ?= (Map)dynaForm.get("address");? ? ?// mapped?
          ????List products = (List)dynaForm.get("products");? ?// indexed??
          ????//... etc
          }
          在ACTION中,你可以使用 BeanUtils 1.7.0的特性,把dynaForm一次性拷貝到HIBERNATE的POJO中去!

          轉(zhuǎn)載地址:http://forum.javaeye.com/viewtopic.php?t=17441
          主站蜘蛛池模板: 长岛县| 衡南县| 赣榆县| 陇川县| 遵义市| 郓城县| 彩票| 会泽县| 屏东市| 阜南县| 通化县| 阳泉市| 阳新县| 清流县| 青州市| 家居| 恭城| 乐都县| 崇左市| 徐州市| 达拉特旗| 汪清县| 祁连县| 婺源县| 积石山| 那曲县| 玛多县| 达孜县| 晋州市| 十堰市| 广汉市| 鄂尔多斯市| 遂昌县| 弋阳县| 福鼎市| 白水县| 图们市| 通许县| 汶川县| 铜陵市| 新竹市|