鍍金池/ 教程/ Java/ 組合框示例
設(shè)置復(fù)選框的默認(rèn)值
<s:if>, <s:elseIf>, <s:else> 標(biāo)簽示例
下拉框示例
Struts2 &lt;s:bean&gt;標(biāo)簽示例
Struts2 &lt;s:date&gt;標(biāo)簽示例
<s:text>標(biāo)簽示例
Struts2的ActionError&ActionMessage示例
Struts2 MySQL數(shù)據(jù)庫訪問
Struts2上傳多個(gè)文件例子
Struts2+Log4j集成
Struts 2 hello world (XML版本)
Struts2和Spring集成
Struts2 控件標(biāo)簽
Struts2 和 JSON 實(shí)例
Struts2 環(huán)境配置
Struts2 &lt;s:checkboxlist&gt;多個(gè)復(fù)選框例子
Struts2 注釋類型
在Struts2中配置靜態(tài)參數(shù)
Struts2 驗(yàn)證框架
Struts2 param 標(biāo)簽
Struts2 &lt;s:hidden&gt;隱藏值例子
Struts2下載文件實(shí)例
Struts2 &lt;sx:autocompleter&gt;自動(dòng)提示例子
Struts2 action標(biāo)簽
autocompleter自動(dòng)完成示例
Struts2 merge標(biāo)簽
Struts2 &lt;s:action&gt;標(biāo)簽示例
<s:property>標(biāo)簽示例
Struts2 &lt;s:sort&gt;標(biāo)簽示例
Struts2和Hibernate集成
自動(dòng)選擇下拉框示例
Struts2 結(jié)果和結(jié)果類型
Struts2 是什么?
如何刪除Struts2動(dòng)作的后綴擴(kuò)展名
Struts2 Hello World 實(shí)例
<s:action>標(biāo)簽示例
<s:bean>標(biāo)簽示例
Struts2 + Quartz調(diào)度集成實(shí)例
如何獲取ServletContext對象
Struts2 &lt;s:i18n&gt;標(biāo)簽示例
Struts2 append標(biāo)簽
i18n 或本地化示例
autocompleter + JSON 示例
Struts2獲取HttpServletRequest實(shí)例
updownselect 示例
Struts2 &lt;s:debug&gt;標(biāo)簽示例
Struts2重寫攔截器參數(shù)
多個(gè)Struts配置文件示例
<s:i18n>標(biāo)簽示例
Struts2中文本地化問題
文件上傳示例
Struts2 &lt;s:property&gt;標(biāo)簽實(shí)例
Struts2攔截器棧的例子
<s:merge>標(biāo)簽示例
Struts2 數(shù)據(jù)標(biāo)簽
Struts2 &lt;s:merge&gt;標(biāo)簽示例
復(fù)選框checkboxes 示例
Struts2 generator標(biāo)簽
如何配置Struts2全局資源包
key 屬性示例
Struts2 注釋
FilterDispatcher 和 StrutsPrepareAndExecuteFilter區(qū)別?
Struts 2 Hello World (注解版本)
Struts 2 + Log4j 集成實(shí)例
Struts2 值棧/OGNL
Struts2配置Action類的靜態(tài)參數(shù)
Struts2 本地化/國際化(i18n)
Chinese 本地化問題
Struts2單選預(yù)選按鈕值
Struts2 include標(biāo)簽
Struts2 + Hibernate 集成實(shí)例
配置全局資源包
Struts2 異常處理
Struts2 &lt;s:set&gt;標(biāo)簽示例
Struts2 &lt;s:doubleselect&gt;示例
Struts2 iterator標(biāo)簽
optiontransferselect 示例
Struts2映射攔截動(dòng)作
head 示例
Struts2+Hibernate使用Full Hibernate Plugin集成
Struts2命名空間配置和解釋
<s:param>標(biāo)簽示例
Struts2+Hibernate集成實(shí)例
Struts2 &lt;s:head&gt;示例
Struts2 &lt;s:push&gt;標(biāo)簽示例
Struts2文件上傳例子
Struts2 &lt;s:param&gt;標(biāo)簽示例
@ResultPath 注釋示例
Struts2 體系結(jié)構(gòu)
Struts2 execAndWait攔截器例子
Struts2 攔截器
Textarea - 文本域
Struts2教程
<s:push>標(biāo)簽示例
Struts2 文件上傳
Struts2 date 標(biāo)簽
Struts2 &lt;s:texttag&gt;標(biāo)簽示例
Struts2+Quartz2調(diào)度集成實(shí)例
Struts2開發(fā)模式
Struts2 autocompleter+JSON例子
Struts2 類型轉(zhuǎn)換
<s:url>標(biāo)簽示例
Struts2 Ajax 標(biāo)簽
Struts2 bean 標(biāo)簽
<s:iterator>標(biāo)簽迭代示例
Hidden隱藏值示例
在Struts2獲取HttpServletResponse對象
Struts2 主題和模板
Struts2自動(dòng)選擇下拉框的值
Struts2下載文件實(shí)例
在Struts2中獲取 HttpServletRequest
級聯(lián)選擇示例
Struts2 &lt;sx:datetimepicker&gt;示例
Struts2 include(包含)多個(gè)配置文件
Struts2 &lt;s:select&gt;下拉框例子
Struts2 Action/動(dòng)作
Struts2 &lt;s:textarea&gt;文本域?qū)嵗?/span>
Struts2+Spring集成實(shí)例
Struts2 &lt;s:updownselect&gt;示例
Struts2 property 標(biāo)簽
Struts2 &lt;s:url&gt;標(biāo)簽示例
Struts2 表單標(biāo)簽
Struts2資源包使用示例
subset tag example
Struts 2 ActionError &amp; ActionMessage Example
Struts2 MVC架構(gòu)
Struts2 if/else標(biāo)簽
Struts2 &lt;s:generator&gt;標(biāo)簽示例
<s:include>標(biāo)簽示例
Struts2開發(fā)者模式
<s:generator> 標(biāo)簽示例
復(fù)選框heckbox 示例
Struts2 text 標(biāo)簽
Radio 單選按鍵示例
Struts2 &lt;s:a&gt;標(biāo)簽示例
Struts2 key鍵屬性示例
Struts2設(shè)置多個(gè)復(fù)選框缺省值
Struts2 基于XML校驗(yàn)
Struts2 配置文件
Struts2 &lt;s:radio&gt;單選按鈕例子
Struts2 發(fā)送郵件Email
Struts2獲取HttpServletResponse實(shí)例
<s:sort>標(biāo)簽示例
Struts2 &lt;s:optiontransferselect&gt;示例
Struts2和Tiles集成
Struts2模型驅(qū)動(dòng)實(shí)例
Struts2的FilterDispatcher和StrutsPrepareAndExecuteFilter有什么不同?
<s:append>標(biāo)簽示例
組合框示例
Struts2 &lt;s:password&gt;密碼示例
datetimepicker 日期選擇
Struts2 &lt;s:iterator&gt;迭代器標(biāo)簽示例
TextBox文檔示例
Struts2 url標(biāo)簽
資源包使用示例
Struts2本地化和國際化
Struts2 &lt;s:subset&gt;標(biāo)簽示例
Struts2 + Hibernate使用“Full Hibernate Plugin"插件集成
Struts2和JSON實(shí)例
Struts2注解示例
Struts2 &lt;s:checkbox&gt;復(fù)選框例子
Struts2快速入門
<s:date>標(biāo)簽示例
Struts2 set 標(biāo)簽
<s:set>標(biāo)簽示例
Struts2 命名空間配置和解釋
Struts 2 hello world (XML版本)
&nbsp;預(yù)選單選按鈕
<s:a>標(biāo)簽示例
Struts2+Spring+Hibernate集成實(shí)例
Struts2 &lt;s:combobox&gt;組合框的例子
Struts2 if,elseif,else標(biāo)簽示例
Struts2 @ResultPath注釋示例
struts2 &lt;s:append&gt;標(biāo)簽示例
Struts2 &lt;s:textfield&gt;文本示例
多文件上傳示例
使用Struts2動(dòng)作
<s:debug>標(biāo)簽示例
在Struts2中如何獲取ServletContext對象
Struts2 &lt;s:include&gt;標(biāo)簽示例
Password 示例

組合框示例

這里創(chuàng)建一個(gè)Web工程:strut2combobox,來演示在多個(gè)復(fù)選框如何設(shè)置的默認(rèn)值,整個(gè)項(xiàng)目的結(jié)構(gòu)如下圖所示:

在Struts2, <s:combobox>標(biāo)簽是一個(gè)下拉列表單文本框組合在一起,允許用戶直接輸入一個(gè)值在文本框中,或選擇從下拉列表中選擇值,并選定值將自動(dòng)填充到文本框中。

如果下拉列表和組合框列表,請閱讀維基組合框定義以免混淆。
<s:combobox label="What's your favor fruit" 
		headerKey="-1" headerValue="--- Select ---"
		list="fruits" 
		name="yourFruits" />

產(chǎn)生下面的HTML代碼...

<td class="tdLabel">
   <label for="resultAction_yourFruits" class="label">
       What's your favor fruit:
   </label>
</td> 
<td> 
<script type="text/javascript"> 
function autoPopulate_resultAction_yourFruits(targetElement) {
	if (targetElement.options[targetElement.selectedIndex].value == '-1') {
		return;
	}
	targetElement.form.elements['yourFruits'].value=
              targetElement.options[targetElement.selectedIndex].value;
}
</script> 
<input type="text" name="yourFruits" value="" id="resultAction_yourFruits"/>
<br /> 
<select onChange="autoPopulate_resultAction_yourFruits(this);"> 
    <option value="-1">--- Select ---</option> 
    <option value="Apple">Apple</option> 
    <option value="Banana">Banana</option> 
    <option value="Orange">Orange</option> 
    <option value="Watermelon">Watermelon</option> 
</select> 
</td>

<s:combobox> 標(biāo)記將產(chǎn)生輸入文本框,下拉列表中有“onChange()”方法調(diào)用來生成的JavaScript 來從下拉列表中選擇的值到自動(dòng)填充生成的文本框中。

如要?jiǎng)?chuàng)建一個(gè)下拉列表,應(yīng)該使用 <s:select>標(biāo)簽來代替。

Struts 2 <s:combobox> 示例

一個(gè)完整的Struts2示例,通過利用<s:combobox>說明組合框。

1. 動(dòng)作 - Action

Action類來生成并按住選定的組合框的選項(xiàng)。
ComboBoxAction.java

package com.yiibai.common.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class ComboBoxAction extends ActionSupport{

	private List<String> fruits;

	private String yourFruits;
	private String yourMonth;
	
	public String getYourMonth() {
		return yourMonth;
	}

	public void setYourMonth(String yourMonth) {
		this.yourMonth = yourMonth;
	}

	public List<String> getFruits() {
		return fruits;
	}

	public void setFruits(List<String> fruits) {
		this.fruits = fruits;
	}

	public String getYourFruits() {
		return yourFruits;
	}

	public void setYourFruits(String yourFruits) {
		this.yourFruits = yourFruits;
	}

	public ComboBoxAction(){
		
		fruits = new ArrayList<String>();
		fruits.add("Apple");
		fruits.add("Banana");
		fruits.add("Orange");
		fruits.add("Watermelon");
	}

	public String execute() {
		return SUCCESS;
	}
	
	public String display() {
		return NONE;
	}
	
}

2. 結(jié)果頁面

通過“<s:combobox>”標(biāo)簽渲染組合框,并填充通過Java列表,OGNL列表中選擇選項(xiàng)

combobox.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>

<body>
<h1>Struts 2 <s:combobox> example</h1>

<s:form action="resultAction" namespace="/">

<h2>
	<s:combobox label="What's your favor fruit" 
		headerKey="-1" headerValue="--- Select ---"
		list="fruits" 
		name="yourFruits" />
</h2>

<h2>
	<s:combobox label="Select a month" 
		headerKey="-1" headerValue="--- Select ---"
		list="#{'1':'Jan', '2':'Feb', '3':'Mar', '4':'Apr'}" 
		name="yourMonth" />
</h2> 

<s:submit value="submit" name="submit" />
	
</s:form>

</body>
</html>

result.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>

<body>
<h1>Struts 2 <s:combobox> example</h1>

<h2>
  Favor fruit : <s:property value="yourFruits"/>
</h2> 

<h2>
  Selected month : <s:property value="yourMonth"/>
</h2> 

</body>
</html>

3. struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>

 <constant name="struts.devMode" value="true" />
 	
<package name="default" namespace="/" extends="struts-default">
		
   <action name="comboBoxAction" 
         class="com.yiibai.common.action.ComboBoxAction" method="display">
	<result name="none">pages/combobox.jsp</result>
   </action>
		
   <action name="resultAction" class="com.yiibai.common.action.ComboBoxAction">
	<result name="success">pages/result.jsp</result>
   </action>

</package>
	
</struts>

5. 示例

http://localhost:8080/strut2combobox/comboBoxAction.action


http://localhost:8080/strut2combobox/resultAction.action


參考

  1. Struts 2 combobox文檔

  1. Wiki combo box 定義

下載代碼:http://pan.baidu.com/s/1qW8Ds5Y