Struts標簽庫詳解 (2)
遺補:1.)<html:link>標簽
forward屬性:鏈接到一個global forward上;action屬性:鏈接到一個action mapping上;
href屬性:這個鏈接會轉發(fā)給控制器,由控制器做決定;page屬性:一個相對的鏈接。
用page屬性鏈接到action上:
href屬性:這個鏈接會轉發(fā)給控制器,由控制器做決定;page屬性:一個相對的鏈接。
用page屬性鏈接到action上:
<html:link page="/html-link.do">
Linking with the page attribute. </html:link> |
注意,上面的代碼中你不必指定web的關聯(lián)。相反的,如果你使用href屬性,你就必須像下面所示指出web的關聯(lián)(這里的關聯(lián)就是struts-exercise):
<html:link href="/struts-exercise-taglib/html-link.do">
Using Href </html:link> |
很明顯,當你在相同的web應用程序中做鏈接是,它比page屬性更加好。你也能用href在不同的服務器上創(chuàng)建鏈接:
<html:link href="http://otherserver/strutsTut/html-link.do">
Using Href </html:link> |
另一種鏈接到html-link.do的方法是用action屬性:
<html:link action="/html-link">
Using Action attribute </html:link> |
你也可以以硬編碼的方式使用參數(shù):
<html:link page="/htmllink.do?doubleProp=3.3&longProp=32">
Double and long via hard coded changes </html:link> |
或者使用paramId, paramName, and paramProperty屬性:
<html:link page="/html-link.do" paramId="booleanProperty" paramName="testbean"
paramProperty="nested.booleanProperty"> Boolean via paramId, paramName, and paramValue </html:link> |
解析后的代碼:
<a href="/struts-exercise-taglib/html-link.do?booleanProperty=false">
Boolean via paramId, paramName, and paramValue </a> |
另外,還能使用帶name屬性的Map來實現(xiàn)傳遞多個參數(shù):
<%
java.util.HashMap newValues = new java.util.HashMap(); newValues.put("floatProperty", new Float(444.0)); newValues.put("intProperty", new Integer(555)); newValues.put("stringArray", new String[] { "Value 1", "Value 2", "Value 3" }); pageContext.setAttribute("newValues", newValues); %> ... <html:link action="/html-link" name="newValues"> Float, int, and stringArray via name (Map) </html:link> |
你也能夠鏈接到Map類型的action上,上面的代碼解析后的結果:
<html:messages property="property2" message="true" id="msg" header="messages.header" footer="messages.footer">
<tr><td><%= pageContext.getAttribute("msg") %></td></tr> </html:messages> |
2.) select和option標簽
<html:select> 的屬性:property-與ActionForm中的某個屬性對應;size-顯示option的數(shù)目;multiple-默認為fales,表示不能多選,當設定為true時,property對應的ActionForm的屬性必須為數(shù)組。
<html:select property="name" size=6 multiple="true">
<html:option>的屬性:key、local、bundle-指定Resource Bundle中的內容。
例如 <html:option value="color1">Orange</html:option>
<html:option value="color1" bundle="htmlselect.Colors" key="htmlselect.red"/>
它和配置文件中的<message-resources>元素的key屬性匹配 --> <message-resource parmeter="HtmlSelectColors" key="htmlselect.Colors"/>
<message-resource>中配置的資源文件為HtmlSelectColors.properties,相關內容為 htmlselect.red=RED
<html:options>標簽,提供了一組<option>元素,在<html:select>元素中可以包含多個<html:options>元素。非常靈活,可以取得集合或數(shù)組中的值。
例1 <html:options collection="coll" property="value" labelProperty="label" /> 這指在coll的集合中存放了options,value指實際能被提交的值,label是顯示給用戶的值。
例2 <html:options property="value" labelProperty="label" /> collection屬性不被指定時,將使用表單相關的form bean,form bean中value屬性存放option value,label屬性值顯示給用戶。
例3 <html:options name="valueBean" property="values" labelName="labelsBean" labelProperty="labels" /> 這個意思是value值存放在名為valueBean的bean的vlaues屬性中,它是一個collection;label值也是同樣的意思。
<html:optionsCollection>標簽,和<html:options>的用法很相似。
例如 <html:select property="custId"><html:optionsCollection property="customers" label="name" value="custId" /></html:select>
這個標簽和org.apache.structs.util.LabelValueBean結合的很好,如果把label和value都放到這個對象中,可以很簡單的這樣應用:
<html:select property="custId"><html:optionsCollection property="customers" /></html:select>
<html:select> 的屬性:property-與ActionForm中的某個屬性對應;size-顯示option的數(shù)目;multiple-默認為fales,表示不能多選,當設定為true時,property對應的ActionForm的屬性必須為數(shù)組。
<html:select property="name" size=6 multiple="true">
<html:option>的屬性:key、local、bundle-指定Resource Bundle中的內容。
例如 <html:option value="color1">Orange</html:option>
<html:option value="color1" bundle="htmlselect.Colors" key="htmlselect.red"/>
它和配置文件中的<message-resources>元素的key屬性匹配 --> <message-resource parmeter="HtmlSelectColors" key="htmlselect.Colors"/>
<message-resource>中配置的資源文件為HtmlSelectColors.properties,相關內容為 htmlselect.red=RED
<html:options>標簽,提供了一組<option>元素,在<html:select>元素中可以包含多個<html:options>元素。非常靈活,可以取得集合或數(shù)組中的值。
例1 <html:options collection="coll" property="value" labelProperty="label" /> 這指在coll的集合中存放了options,value指實際能被提交的值,label是顯示給用戶的值。
例2 <html:options property="value" labelProperty="label" /> collection屬性不被指定時,將使用表單相關的form bean,form bean中value屬性存放option value,label屬性值顯示給用戶。
例3 <html:options name="valueBean" property="values" labelName="labelsBean" labelProperty="labels" /> 這個意思是value值存放在名為valueBean的bean的vlaues屬性中,它是一個collection;label值也是同樣的意思。
<html:optionsCollection>標簽,和<html:options>的用法很相似。
例如 <html:select property="custId"><html:optionsCollection property="customers" label="name" value="custId" /></html:select>
這個標簽和org.apache.structs.util.LabelValueBean結合的很好,如果把label和value都放到這個對象中,可以很簡單的這樣應用:
<html:select property="custId"><html:optionsCollection property="customers" /></html:select>
posted on 2009-02-15 17:30 丁克設計 閱讀(184) 評論(0) 編輯 收藏 所屬分類: struts標簽