s:selected的用法
s:select 標簽輸出一個下拉列表框,相當于HTML代碼中的<select/>
---------------------------------------------------------------
成品:(value=“‘006’”也可以,lable需使用類似的才能取message,value最后始終沒法自動獲得,使用了request)
?<s:select label="%{getText('QuesType')}"? value="#request.aa.queTypeCode"
?name="quesTypeName" list="myList" listKey="queTypeCode" listValue="queTypeTitle"
?οnchange="onChangeType(this.value);" >
</s:select>
這里使用property標簽又是可以的,但select上使用還是不行
<INPUT id=u7? type=text value="<s:property value="quesCode"/>"? name='quesCode'>
-----------------------------------------------------------------
?<s:textarea name="quesSingleDesc" label="%{getText('QuesDesc')}"
?????????? cols="83" rows="5"? value="%{quesSingleDesc}"???? />
-----------------------------------------------------------------------------
例子:
%@ page contentType="text/html;charset=GBK" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<h3>使用name和list屬性,list屬性的值是一個列表</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="{'高中','大學','碩士','博士'}"/>
</s:form>
<h3>使用name和list屬性,list屬性的值是一個Map</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="#{1:'高中',2:'大學',3:'碩士',4:'博士'}"/>
</s:form>
<h3>使用headerKey和headerValue屬性設置header選項</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="{'高中','大學','碩士','博士'}"
?????? headerKey="-1" headerValue="請選擇您的學歷"/>
</s:form>
?
<h3>使用emptyOption屬性在header選項后添加一個空的選項</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="{'高中','大學','碩士','博士'}"
?????? headerKey="-1" headerValue="請選擇您的學歷"
?????? emptyOption="true"/>
</s:form>
?
<h3>使用multiple屬性設置多選</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="{'高中','大學','碩士','博士'}"
?????? headerKey="-1" headerValue="請選擇您的學歷"
?????? emptyOption="true"
?????? multiple="true"/>
</s:form>
<h3>使用size屬性設置下拉框可顯示的選項個數</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="{'高中','大學','碩士','博士'}"
?????? headerKey="-1" headerValue="請選擇您的學歷"
?????? emptyOption="true"
?????? multiple="true" size="8"/>
</s:form>
?
<h3>使用listKey和listValue屬性,利用Action實例的屬性(property)來設置選項的值和選項的內容</h3>
<s:form>
??? <s:select label="最高學歷" name="education" list="educations"
?????? listKey="id" listValue="name"/>
</s:form>
1.select顯示map:
? 1>.在Action中定義一個方法即可。
? public Map<Integer,String> getMaps() {
? Map<Integer,String> map = new HashMap<Integer,String>();
? map.put(new Interger(1), "one");
? map.put(new Interger(2), "two");
? map.put(new Interger(3), "three");
? return map;
? }
? 2>.jsp寫法:
? <s:select list="maps"></s:select>
2.Action中取得select選中值:
? 1>.在action定義屬性:
? private String type;
? type屬性有get/set方法。
? 2>.jsp寫法:
? <s:select list="maps" name="type"></s:select>
?
?如果HashMap<String,Object>
?listValue可以寫成 listValue="value.objName.name" 用來顯示相對復雜數據結構
<s:select name="mylist" list="map" listKey="keys" listValue="values"></s:select>
headerKey="" headerValue="duf"
?
<%
HashMap map = new LinkedHashMap();
map.put(1,"aaa");
map.put(2,"bbb");
map.put(3,"ccc");
request.setAttribute("map",map);
request.setAttribute("aa","2");
%>
<s:select list="#request.map"? label="abc" listKey="key" listValue="value" value="#request.aa"? headerKey="0" headerValue="aabb">
</s:select>
--------------------------------------------------------------
var fpzlmc = fpzldm[fpzldm.selectedIndex].text;
value="%{queTypeCode}"?------------------------------------<s:select
list="venderList"
listKey="id"
listValue="name"
value="%{profile.companyName}" / value="'005'"(單引+雙引,出來結果了。。)label="%{getText('QuesType')}"
name="companyName" cssClass="sel_style_w_180"/>???-------------------------------------------http://www.javaeye.com/topic/625140(組件參考)http://www.blogjava.net/max/category/16130.html(struts2)http://www.zhiweinet.com/struts2-basic-course/(詳解)---------------------------------------------
hidden標簽在頁面產生一個hidden的域,用來存放不需要顯示而不想丟失的值。
使用方法:
<-- 示例一 -->
<s:hidden name="foo" />
這種方式需要對foo變量進行直接賦值
?
<-- 示例二 -->
<s:hidden name="foo" value="bar" />
用這種方式時,系統會根據value屬性的值從action中找getBar這個方法,并試圖把getBar方法的返回值賦值給foo變量
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的s:selected的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 老款gs8可以换机车联网吗老款GS8可以
- 下一篇: 东方红904拖拉机国三款反光镜怎么按