想用rich:columns动态生成表格,但老是不成功!javax.servlet.jsp.JspTagException: FOREACH_BAD_ITEMS异常!
我的代码是这样的!
后台Bean:
import java.util.ArrayList;
import java.util.List;import javax.faces.model.DataModel;import org.richfaces.model.impl.ListDataModel;public class DynamicBean {
private DataModel recordModel;
private DataModel headerModel; public DataModel getHeaderModel() { if (headerModel == null) {
headerModel = new ListDataModel();
List<String> list = new ArrayList<String>();
list.add("表头1");
list.add("表头2");
list.add("表头3");
headerModel.setWrappedData(list);
}
return headerModel;
} public DataModel getRecordModel() {
if (recordModel == null) {
recordModel = new ListDataModel(); headerModel = new ListDataModel();
List<String> list = new ArrayList<String>();
list.add("内容1");
list.add("内容2");
list.add("内容3");
headerModel.setWrappedData(list);
}
return recordModel;
}}
页面:
<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<head>
</head>
<body>
<f:view>
<h:form>
<rich:dataTable value="#{dynamicBean.recordModel}" var="model"
width="750">
<rich:columns value="#{dynamicBean.headerModel}" var="columns"
index="ind" >
<f:facet name="header">
<h:outputText value="#{columns[ind]}" />
</f:facet>
<h:outputText value="#{model[ind]}" /> </rich:columns> </rich:dataTable> </h:form>
</f:view>
</body>
</html>
我都不知道应该怎样做了!!有谁使用过rich:columns,帮我看看错误!!或者把你的正确代码贴出来让我看看!谢谢!
我的代码是这样的!
后台Bean:
import java.util.ArrayList;
import java.util.List;import javax.faces.model.DataModel;import org.richfaces.model.impl.ListDataModel;public class DynamicBean {
private DataModel recordModel;
private DataModel headerModel; public DataModel getHeaderModel() { if (headerModel == null) {
headerModel = new ListDataModel();
List<String> list = new ArrayList<String>();
list.add("表头1");
list.add("表头2");
list.add("表头3");
headerModel.setWrappedData(list);
}
return headerModel;
} public DataModel getRecordModel() {
if (recordModel == null) {
recordModel = new ListDataModel(); headerModel = new ListDataModel();
List<String> list = new ArrayList<String>();
list.add("内容1");
list.add("内容2");
list.add("内容3");
headerModel.setWrappedData(list);
}
return recordModel;
}}
页面:
<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<head>
</head>
<body>
<f:view>
<h:form>
<rich:dataTable value="#{dynamicBean.recordModel}" var="model"
width="750">
<rich:columns value="#{dynamicBean.headerModel}" var="columns"
index="ind" >
<f:facet name="header">
<h:outputText value="#{columns[ind]}" />
</f:facet>
<h:outputText value="#{model[ind]}" /> </rich:columns> </rich:dataTable> </h:form>
</f:view>
</body>
</html>
我都不知道应该怎样做了!!有谁使用过rich:columns,帮我看看错误!!或者把你的正确代码贴出来让我看看!谢谢!
index="ind" > 这句写这样value="#{columns.headerModel}"
另外后台BEAN里补上:
public DataModel getHeaderModel(){
return this.headerModel;
}
public void setHeaderModel(DataModel dataModel){
this.headerModel=dataModel;
}
public DataModel getRecordModel(){
return this.recordModel;
}
public void setRecordModel(DataModel dataModel){
this.recordModel=dataModel;
}
这个不对,不能迭代, public List <Map> getHeaderModel() {
if(null==headerModel) {
headerModel = new ArrayList <Map>();
Map temp= new HashMap();
temp.put("id", 111);
temp.put("name", 222);
headerModel.add(temp);
headerModel.add(temp);
headerModel.add(temp);
}
return headerModel;
} public void setHeaderModel(List <Map> headerModel) {
this.headerModel = headerModel;
}
ava.lang.NumberFormatException: For input string: "areaId"
郁闷啊!!其他的实体在datatable中显示的就没有问题!!唉