我的老板想在反馈表单中添加一个选择表单,要求用户选择他/她的国家/地区。我可以通过以下方式实现这一目标:
Select country = form.addItem().addSelect("country ");
userType.setLabel("Country");
userType.addOption("","Please select your country");
userType.addOption("ABW","Aruba");
userType.addOption("AFG","Afghanistan");
<----- Rest of countries from A to Z --->
userType.setOptionSelected(parameters.getParameter("country",""));
TextArea countryOther = form.addItem().addTextArea("countryOther");
countryOther.setValue(parameters.getParameter("countryOther", ""));
我想避免代码中包含很长的国家/地区列表。是否有其他选择,例如将国家/地区列表放在单独的位置并仅提取此信息?提前致谢。
最佳答案
一种简单的方法是创建一个配置文件:config/modules/countries.cfg
并填写您的列表,如配置属性:
ABW=Aruba
AFG=Afghanistan
...
然后使用 ConfigurationManager
将它们添加到您的 Select 中
Select country = form.addItem().addSelect("country ");
country.setLabel("Country");
country.addOption("", "Please select your country");
Enumeration<?> countries = ConfigurationManager.propertyNames("countries");
while (countries.hasMoreElements()) {
String key = (String) countries.nextElement();
String value = ConfigurationManager.getProperty("countries", key);
country.addOption(key, value);
}
关于java - 如何在 DSpace 中添加包含超长数据的输入表单(反馈)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26300095/