我一直在使用Spring表單taglib(http://www.springframework.org/tags/form)的Spring項目。
我正在使用一些多個選擇框來指示一些選項(國家,工廠,...)
當我將整個列表傳遞給select時 - 一切正常:默認情況下選擇列表的第一個選項是默認選擇的。但是,當用戶來自特定國家時,該列表將被過濾,並且只顯示他的國家。在這種情況下,默認情況下不會選擇第一個元素。彈簧形式:選擇 - 多個默認情況下不選擇第一個選項
JSP頁面:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:select path="countryValues" multiple="true" size="9" style="width:192px;" cssErrorClass="field-error">
<form:options items="${command.countries}" itemValue="countryCode" itemLabel="correctDisplayString"/>
</form:select>
Command.java
public List<CountryMaster> getCountries() {
return countries;
}
public void setCountries(List<CountryMaster> countries) {
this.countries = countries;
}
Controller.java
@RequestMapping(value = "/overview", method = RequestMethod.GET)
public String overview(HttpServletRequest request, Model model) {
Attrs attrs = getAttrs(request);
UserLocale.initUser(getUser(request));
User user = UserLocale.getUser();
List<FactoryMaster> factoryList = getFactoryList(attrs);
List<CountryMaster> countryList = getCountryList(attrs);
Command command = initCommand(attrs);
model.addAttribute(command);
if(user.hasRole(User.NORMAL)&& user.getCountryCode() != null){
if(countries == null){
countries= getDaoBuilder().getDaoCountry().countryMap();
}
String isoCode = countries.get(user
.getCountryCode());
List<CountryMaster> buffer = new ArrayList<CountryMaster>();
for(CountryMaster i : countryList){
if(isoCode.equalsIgnoreCase(i.getIsoCode())){
buffer.add(i);
}
}
System.out.println("List size: "+buffer.size());
command.setCountries(buffer);
}
else{
command.getCountries().addAll(getCountryList(attrs));
}
command.getModels().addAll(getModelList(attrs));
command.setBrands(getBrandList(attrs));
return "/reporting/overview";
}
private List<CountryMaster> getCountryList(Attrs attrs) {
List<CountryMaster> result = new ArrayList<CountryMaster>();
CountryMaster ct = new CountryMaster(CountryMaster.ISO_COUNTRY_JOKER, 00);
ct.setDescription("ALL");
result.add(ct);
result.addAll(attrs.countryList);
return result;
}
在HTML頁面中,我可以在其他列表中看到,第一個元素有attr ibute selected="selected"
。任何人有任何想法,當我操縱我的列表時,爲什麼不是這種情況?或者是否有人知道選擇屬性配置是什麼是resposible? (這是JavaScript,Java屬性,...?)
在此先感謝!