gpt4 book ai didi

java - Struts2中Select标签中ArrayList的ArrayList

转载 作者:行者123 更新时间:2023-11-30 10:48:27 24 4
gpt4 key购买 nike

当我尝试显示 <select> 时带有列表的标签包含嵌套的 ArrayList

ArrayList<ArrayList<String>> districts=new ArrayList<ArrayList<String>>();

districts 数组列表将是这样的 [ [0,"one"],[1,"two"],[2,"three"] ]

当我使用 Struts 2 时 <s:select>标签如下:

<s:select label="District" headerKey="-1" headerValue="Select State"  list="districts" >

它将生成如下代码:

<select name="" id="">
<option value="-1">Select State</option>
<option value="[12, Anantapur]">[12, Anantapur]</option>
<option value="[10, Chittoor]">[10, Chittoor]</option>
<option value="[04, East Godavari]">[04, East Godavari]</option>
<option value="[07, Guntur]">[07, Guntur]</option>
<option value="[11, Kadapa]">[11, Kadapa]</option>
<option value="[06, Krishna]">[06, Krishna]</option>
<option value="[13, Kurnool]">[13, Kurnool]</option>
<option value="[08, Prakasam]">[08, Prakasam]</option>
<option value="[09, S.P.S Nellore]">[09, S.P.S Nellore]</option>
<option value="[01, Srikakulam]">[01, Srikakulam]</option>
<option value="[03, Visakhapatnam]">[03, Visakhapatnam]</option>
<option value="[02, Vizianagaram]">[02, Vizianagaram]</option>
<option value="[05, West Godavari]">[05, West Godavari]</option>
</select>

但我想要01,02,03...作为在选择标签中显示的值名称。

我的 Action会是这样的:

package authentication;

import java.util.ArrayList;

import Testing.Database_Access;

import com.opensymphony.xwork2.ActionSupport;

public class Reports extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
//private String district;
private ArrayList<ArrayList<String>> districts;

public String dbDistricts(){
districts=Database_Access.getDbDistricts("01");
return SUCCESS;

}

public ArrayList<ArrayList<String>> getDistricts() {
return districts;
}

public void setDistricts(ArrayList<ArrayList<String>> districts) {
this.districts = districts;
}



/*public String getDefaultDistrict() {
return "Select State";
}

public void setDistrict(String district) {
this.district = district;
}*/



}

struts.xml是这样的:

<action name="Reports" class="authentication.Reports" method="dbDistricts">
<result name="success">/Reports.jsp</result>
</action>

这是我的 Struts2 选择标签:

<s:select label="District" headerKey="-1" headerValue="Select State"  list="districts" >

我想要这样的结果:

<select name="" id="">
<option value="-1">Select State</option>
<option value="12"> Anantapur</option>
<option value="10"> Chittoor</option>
<option value="04"> East Godavari</option>
<option value="07">Guntur</option>
<option value="11">Kadapa</option>
<option value="06"> Krishna</option>
<option value="13">Kurnool</option>
<option value="08">Prakasam</option>
<option value="09"> S.P.S Nellore</option>
<option value="01"> Srikakulam</option>
<option value="03">Visakhapatnam</option>
<option value="02"> Vizianagaram</option>
<option value="05">West Godavari</option>
</select>

最佳答案

制作一张新 map ,如

 private Map<String, String> districts;
//getter here

还有 <s:select>标签

<s:select list="districts" headerKey="-1" headerValue="Select State"/> 

了解有关 struts 的更多信息 <s:select> tag :

Render an HTML input tag of type select.

关于java - Struts2中Select标签中ArrayList的ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35793163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com