Jsf 2 在PF3.1中使用onRowKey(p:datatable)传递多个参数
我希望通过以下Primefaces 3.1 p:datatable传递多个参数:Jsf 2 在PF3.1中使用onRowKey(p:datatable)传递多个参数,jsf-2,primefaces,Jsf 2,Primefaces,我希望通过以下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.onR
<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>
非常感谢您的帮助。您需要将复合键改为行键 例如 或者如果您坚持使用
SelectableDataModel
:
@Override
public Car getRowData(String rowKey) {
List<Car> cars = (List<Car>) getWrappedData();
for (Car car : cars) {
if (car.getCompositeKey().equals(rowKey))
return car;
}
return null;
}
@Override
public Object getRowKey(Car car) {
return car.getCompositeKey();
}
或
或者根据
对象#equals()
契约唯一表示为复合键的任何内容。您需要将复合键用作行键
例如
或者如果您坚持使用SelectableDataModel
:
@Override
public Car getRowData(String rowKey) {
List<Car> cars = (List<Car>) getWrappedData();
for (Car car : cars) {
if (car.getCompositeKey().equals(rowKey))
return car;
}
return null;
}
@Override
public Object getRowKey(Car car) {
return car.getCompositeKey();
}
或
或者基于
Object#equals()
contract唯一表示为复合键的任何内容。我通过扩展基类、使用传递对象的属性初始化基类并使用计数器值添加额外的Id字段来解决此问题。尚未尝试,但应与反射一起使用,以自动化属性字段的副本。我不明白为什么PF没有提供这样一种隐式机制。我通过扩展基类,用传递对象的属性初始化基类,并添加一个带有计数器值的附加Id字段,通过提供一个唯一(行)键解决了这个问题。尚未尝试,但应与反射一起使用,以自动化属性字段的副本。我不明白为什么PF没有提供这种隐式机制。您可以直接使用所有键编写rowKey:
<p:dataTable id="productItemsTable" var="i" value="#{b2BOrdersBean.listProductItems}"
rowKey="#{i.id.orderId}_#{i.id.productType}_#{i.id.partId}"
selectionMode="single" selection="#{b2BOrdersBean.selectedProductItemRow}">
您不必担心创建函数来解决此问题
只需在rowKey中键入其工作的每个键。您可以直接使用所有键编写rowKey:
<p:dataTable id="productItemsTable" var="i" value="#{b2BOrdersBean.listProductItems}"
rowKey="#{i.id.orderId}_#{i.id.productType}_#{i.id.partId}"
selectionMode="single" selection="#{b2BOrdersBean.selectedProductItemRow}">
您不必担心创建函数来解决此问题
只需在rowKey中键入每个键即可。感谢您的回复BalusC,您一直以来都是一个很大的帮助!!!我删除了CardDataModel,现在我遇到了这个错误,DataModel必须在启用选择时实现org.primefaces.model.SelectableDataModel。你能帮忙吗?当我删除选择时,它会显示相同的错误。但是,如果我同时删除了selectionMode和selection属性,则表呈现良好,但我需要selectionMode=single,因为我正在单击该行并转到下一页。您需要指定
rowKey
属性。请注意,这与原始代码中的rowkey
不同。请告诉我如何操作?我真的需要弄明白这一点。请记住我正在学习…再次感谢…谢谢你的回复巴卢斯,你一直都是一个很大的帮助!!!我删除了CardDataModel,现在我遇到了这个错误,DataModel必须在启用选择时实现org.primefaces.model.SelectableDataModel。你能帮忙吗?当我删除选择时,它会显示相同的错误。但是,如果我同时删除了selectionMode和selection属性,则表呈现良好,但我需要selectionMode=single,因为我正在单击该行并转到下一页。您需要指定rowKey
属性。请注意,这与原始代码中的rowkey
不同。请告诉我如何操作?我真的需要弄明白这一点。请记住我正在学习…再次感谢。。。
public Object[] getCompositeKey() {
return new Object[] { model, color };
}
<p:dataTable id="productItemsTable" var="i" value="#{b2BOrdersBean.listProductItems}"
rowKey="#{i.id.orderId}_#{i.id.productType}_#{i.id.partId}"
selectionMode="single" selection="#{b2BOrdersBean.selectedProductItemRow}">