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

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

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

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

          下面說說Lazy ActionForm:?

          如果你喜歡STRUTS的強(qiáng)大的功能的特性(就比如這個ActionForm有多種選擇),又喜歡快捷, Lazy ActionForm對你來說是一個好消息. 這個有點(diǎn)類似于WW2中值得稱道的一個特性,可以減少編寫ActionForm的麻煩.(STRUTS正在把WW2中好的東西都吸收進(jìn)來了,難怪這兩個東西以后會合并為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
          主站蜘蛛池模板: 安国市| 柯坪县| 阿尔山市| 娄烦县| 呼伦贝尔市| 边坝县| 陆良县| 城口县| 桂阳县| 云安县| 铁岭县| 湛江市| 资兴市| 喜德县| 林口县| 布拖县| 澎湖县| 舞阳县| 鄂温| 大同县| 秭归县| 班玛县| 凤阳县| 神农架林区| 枣阳市| 沙坪坝区| 紫阳县| 宜川县| 秦安县| 保亭| 泾源县| 甘孜县| 安顺市| 卢氏县| 定南县| 友谊县| 察哈| 浠水县| 五原县| 墨玉县| 竹山县|