Java 在JSF中使用Apache配置时遇到问题<;选择项目>;标签

Java 在JSF中使用Apache配置时遇到问题<;选择项目>;标签,java,jsf,properties,Java,Jsf,Properties,我正在从事一个项目,我对JSF不太熟悉,所以请纠正这个问题中的任何漏洞 我有一个保存域值的属性文件…例如 domain=.com domain=.net 我的豆子里有这个 private String domain; private String[] domainSelection; public void initProp(){ try { Configuration config = new PropertiesConfiguration("prop.properti

我正在从事一个项目,我对JSF不太熟悉,所以请纠正这个问题中的任何漏洞

我有一个保存域值的属性文件…例如

domain=.com
domain=.net
我的豆子里有这个

private String domain;
private String[] domainSelection;

public void initProp(){

   try {
      Configuration config = new PropertiesConfiguration("prop.properties");
      domainSelection = config.getStringArray("domain");

   } catch (ConfigurationException e) {
      Log.error("Error");
   }

}
在带有JSF的
.jsp
页面中

<rich:select id="domain" value="#{Bean.domain}"                                               
      required="true">
     <f:selectItems itemValue="#{Bean.domainSelection}" />
</rich:select>


当我调试这个时,我在domainSelection中得到了两个值,但我需要将它们交给JSF,我不知道如何做到这一点

对于最初的回答我感到抱歉,我完全没有回答这个问题

private List<SelectItem> domains = new ArrayList<SelectItem>();
//for each domain
domains.add("com",firstFromDomainSelection);
domains.add("net",secondFromDomainSelection);

<f:selectItems value="#{Bean.domains}" />
我会怎么做


我不使用属性文件,而是为域使用一个表,并将这些记录动态地添加到表中,然后相应地检索它们。当该视图上有许多请求时,它可能会减慢速度——至少会稍微减慢一点。要记住的另一个问题是apache是否缓存这些文件。记住这一点。在我看来,使用db表更安全。

我们希望能够在需要时在属性文件中动态添加域。这不可能吗?我希望把整个列表都带进来,而不是在每个列表上加一个“.add”。我很接近,非常感谢。我现在得到的唯一结果是当我执行for循环和do domains.add(domain,domain)时,我得到错误“类型列表中的add(int,SelectItem)方法不适用于参数(String,String)抱歉,这是一个错误。SelectItem的列表需要相同的类型。显示您的代码和堆栈跟踪。如果它说它是添加时的NPE,那么此行
domains=new ArrayList();
必须丢失。另外,请确保您有一个setter
public void setDomains(list domains){this.domains=domains}
private List<SelectItem> domains;
private Configuration config = new PropertiesConfiguration("prop.properties"); // with accessors

public List<SelectItem> getDomains(){
  domains = new ArrayList<SelectItem>();
  String[]  domainSelection = getConfig().getStringArray("domain");
  for(String domain : domainSelection ){
     //Define desired logic for the value if its the same (.com) pass the same as value
     domains.add( new SelectItem(domain ,domain)); // SelectItem(value, label);
  }
  return domains;
}