SpringSide 里翻到一個好東西: jodd:form

"
Jodd Form的使用極其簡單,因為太簡單了,才會名不見經傳而被我們選用,讓我們罔顧各大Framework的Form Tag.

他只要把<form>的頭尾以<jodd:form bean= "mybean">包住即可,就會自動綁定mybean的所有同名屬性到普通html標記--input, selectbox, checkbox,radiobox.....在這些input框里不用再寫任何代碼

可見,它的好處一是節約代碼,二是保留了html版的form tag, 不需要用一套taglib來代替

而且支持內嵌對象的綁定,如book.category.name。

比那些需要使用非純html標記的<ww:input>,逐個綁定input框,select框的Form Tag,雖減了些許靈活性,但實在方便得太厲害。

如果屬性來自于request,而不是某個java bean,寫<jodd:form bean= "request">

jodd采用的是普通的bean反射,調用所有屬性的toString()函數。

注意,jodd在html tag不含value="xxx"屬性時才會自動綁定。如果某個input框你不希望jodd自動綁定,或者默認的toString()不能滿足要求時,可以手工為該input框寫上 value="xxxx",jodd看到你已經定義了屬性值,就會自動繞開。
"

< form? name ="form1" ?action ="action.do?method=save" /> "??method="post">?
??????
< jodd:form? bean ="form1" ?scope ="request" >
??????
< table? class ="border" ?width ="90%" ?cellSpacing =0? cellPadding =2? align ="center" >
????
< tr >
??????
< td? width ="160" ?class ="left" > 姓名 </ td >
??????
< td? colspan ="3" ?class ="right" >
??????????
< input? name ="name" ?type ="text" ?class ="text" ?size ="40" >
??????????
< label? class ="star" > * </ label >
??????
</ td >
????
</ tr >
????
< tr >
??????
< td? width ="160" ?class ="left" > 性別 </ td >
??????
< td? width ="303" ?class ="right" >
????????
< input? name ="sex" ?type ="text" ?class ="text" ?size ="40" >
????????
< label? class ="star" > * </ label >
??????
</ td >
????
</ tr > ??
????
</ table >
????
</ jodd:form >
</ form >

確實好用!