0

我开始了我在 JSF 中的第一步。

我已经读过这个链接

http://docs.oracle.com/javaee/6/tutorial/doc/bnawq.html#bnaww

关于地图初始化。

问题是,我想用文件中的值填充我的地图。

我怎样才能做到这一点?

我试过不使用 faces-config.xml 并在 bean 的构造函数中调用支持方法,但我的选择列表框没有填充。

我的豆类:

@ManagedBean
public class ADGroupListBean {

private static final String WITH_ACCESS = "D:\\workspace\\AccessControl\\permissions.txt";
private static final String WITHOUT_ACCESS = "D:\\workspace\\AccessControl\\noPermissions.txt";
private Map<String,String> withAccess, withoutAccess;

private LDAPQueries queries;


public ADGroupListBean(){

    withAccess = new LinkedHashMap<String, String>();
    withoutAccess = new LinkedHashMap<String, String>();

    queries = new LDAPQueries();

    initList(WITH_ACCESS, withAccess);
    initList(WITHOUT_ACCESS, withoutAccess);

}   

private void initList(String filename, Map<String,String> list) {

    File f = new File(filename);

    if ( !f.exists() && f.getAbsolutePath().equals(WITHOUT_ACCESS) )
    {
        queries.queryAllGroups(WITHOUT_ACCESS);
    }

    try 
    {   

        Scanner sc = new Scanner(f);

        while (sc.hasNext())
        {
            String group = sc.nextLine();
            list.put(group, group);
        }

    }catch (IOException e) {

        e.printStackTrace();
    }


}

//  public void populateList() {
//      
//      
//  }

public Map<String,String> getWithAccess() {

    return withAccess;
}

public Map<String,String> getWithoutAccess() {

    return withoutAccess;
}

public void setWithoutAccess(Map<String,String> withoutAccess) {

    this.withoutAccess = withoutAccess;
}

public void setwithAccess(Map<String,String> withAccess) {

    this.withAccess = withAccess;
}

public void test() {

    System.out.println("workssssssssssssssssss");
}
}

至于我的 JSF 文件,是这样的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html">
<h:head><title>Your Title Here</title>
</h:head>
<h:body>
<h1>Your Heading Here</h1>

<h:form>
    <h:selectOneMenu value="teste">
         <f:selectItem itemLabel="" itemValue="" />
        <f:selectItems value="#{ADGroupListBean.withoutAccess}" />
</h:selectOneMenu>
</h:form>

</h:body>
</html>

我已经在测试应用程序中测试了 bean 的功能,一切正常。

所以我的猜测是bean没有实例化?

问候,努诺。

4

0 回答 0