我正在尝试学习PF所以我开始首先显示datatable并导航到rowClick传递参数的下一页,但是遇到了以下错误.我发现了这个问题的类似问题,但还没有运气.我希望有人会帮助我.
我收到以下错误:
DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.
Caused by:
javax.faces.FacesException - DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.
Run Code Online (Sandbox Code Playgroud)
我的页面:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Primefaces 3.1</title>
</h:head>
<h:body>
<h:form id="form">
<p:dataTable value="#{tableBean.cars}" var="var" rowkey="#{var.model}"
selection="#{tableBean.car}" selectionMode="single">
<p:column> <f:facet name="header">
<h:outputText styleClass="outputText" value="Model"></h:outputText>
</f:facet>
<h:outputText styleClass="outputText"
value="#{var.model}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText styleClass="outputText" value="Color"></h:outputText>
</f:facet>
<h:outputText styleClass="outputText"
value="#{var.randomColor}"></h:outputText>
</p:column></p:dataTable>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的bean类:
@ManagedBean …Run Code Online (Sandbox Code Playgroud) 我希望从以下Primefaces 3.1 p:datatable传递多个参数:
<p:dataTable value="#{tableBean.carsModel}" var="var" rowkey="#{var.model}"
selection="#{tableBean.car}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{tableBean.onRowClick}"></p:ajax>
<p:column>
<f:facet name="header">
<h:outputText styleClass="outputText" value="Model"></h:outputText>
</f:facet>
<h:outputText styleClass="outputText" value="#{var.model}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText styleClass="outputText" value="Color"></h:outputText>
</f:facet>
<h:outputText styleClass="outputText" value="#{var.randomColor}"></h:outputText>
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
我有一种情况,我正在使用多个键作为主键, rowkey="#{var.model}但是,如何使用多个主键。
我也在CarDataModel extends ListDataModel<Car> implements SelectableDataModel<Car>{ 上课。有人可以告诉我如何合作吗?
@Override
public Car getRowData(String rowKey) {
//In a real app, a more efficient way like a query by rowKey
//should be implemented to deal with huge data
List<Car> cars = (List<Car>) getWrappedData();
for(Car car : …Run Code Online (Sandbox Code Playgroud)