我一直在尝试从JSF Facelets中的ArrayList<String>
打印值,但没有运气。该值将存储在ArrayList中,但页面上的输出为空白。
Bean文件:
import java.io.Serializable;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="newCompanyName")
@SessionScoped
public class CompanyNames implements Serializable {
private static final long serialVersionUID = 1L;
private ArrayList<String> list = new ArrayList<String>();
private String companyName;
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
list.add(companyName);
System.out.println("Size of array list is : "+list.size());
for (String number : list) {
System.out.println("Number = " + number);
}
}
public CompanyNames(String companyName) {
this.companyName = companyName;
}
public CompanyNames() {
}
}
这是我在XHTML 1.0 Transitional文件中的JSF文件:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<h:body>
<ui:repeat var="item" value="#{CompanyNames.list}">
<h1>#{item}</h1>
</ui:repeat>
</h:body>
</html>
答案 0 :(得分:1)
而不是
<ui:repeat var="item" value="#{CompanyNames.list}"> <h1>#{item}</h1> </ui:repeat>
使用
<ui:repeat var="item" value="#{newCompanyName.list}"> <h1>#{item}</h1> </ui:repeat>
您还需要一个类CompanyNames的getList方法
public List<String> getList() {
return this.list;
}
答案 1 :(得分:0)
使用companyNames.list
代替CompanyNames.list
,您还需要get()
的{{1}}功能。