【发布时间】:2016-02-14 23:50:42
【问题描述】:
我有以下数据表:
<p:dataTable var="file" value="#{fileManagementController.storedFiles}"
styleClass="right-aligned" emptyMessage="No files found" id="fileTable" sortBy="#{fileManagementController.sortOrder}">
<p:column headerText="Scenario" sortBy="#{file.scenario}" id="scenario">
<h:outputText value="#{file.scenario}"/>
</p:column>
<p:column headerText="File Type" sortBy="#{file.fileType}" id="type">
<h:outputText value="#{file.fileType}"/>
</p:column>
<p:column headerText="Affiliated Month" sortBy="#{file.affiliatedMonth}" id="affiliatedMonth">
<h:outputText value="#{fileManagementController.convertAffiliationMonthForDisplayInTable(file.affiliatedMonth)}"/>
</p:column>
<p:column headerText="Creation Date" sortBy="#{file.creationDate}" id="sreationDate">
<h:outputText value="#{fileManagementController.convertDateForDisplayInTable(file.creationDate)}"/>
</p:column>
<p:column headerText="Last changed/Uploaded" sortBy="#{file.uploadDate}">
<h:outputText value="#{fileManagementController.convertTimestampForDisplayInTable(file.uploadDate)}"/>
</p:column>
<p:column headerText="Size" sortBy="#{file.sizeInByte}">
<h:outputText value="#{fileManagementController.roundToOneDecimal(file.sizeInByte/1024)} kB"/>
</p:column>
<p:column headerText="Actions" styleClass="centered">
<p:commandButton icon="ui-icon-pencil" action="#{fileManagementController.editFileContent(file)}" alt="Edit" title="Edit"/>
<p:commandButton icon="ui-icon-closethick" action="#{fileManagementController.archiveFile(file.fullPath)}"
update="manageFilesForm:fileTable, growl" alt="Delete" title="Delete"/>
</p:column>
</p:dataTable>
以及控制器中对应的方法:
public List<SortMeta> getSortOrder() {
UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
DataTable table = (DataTable) view.findComponent(":manageFilesForm:fileTable");
List<SortMeta> preSortOrder = new ArrayList();
SortMeta sm1 = createSortMeta(table, 0, "scenario");
SortMeta sm2 = createSortMeta(table, 1, "type");
SortMeta sm3 = createSortMeta(table, 2, "affiliatedMonth");
preSortOrder.add(sm1);
preSortOrder.add(sm2);
preSortOrder.add(sm3);
LOG.debug("Created sortOrder for File Table; ordered by {} and {}", sm1.getSortField(), sm2.getSortField());
return preSortOrder;
}
排序本身有效,但是当我创建排序顺序时,按钮:
<p:commandButton icon="ui-icon-closethick" action="#{fileManagementController.archiveFile(file.fullPath)}"
update="manageFilesForm:fileTable, growl" alt="Delete" title="Delete"/>
提交了错误的路径,我看不到那里的模式,它似乎只是随机提交一个。我覆盖了 equals() ,但是当我使用所有考虑的属性覆盖它以及根本不覆盖它时,会发生相同的行为。如果我不对表格进行排序,它会按预期工作。有什么建议?提前致谢!
【问题讨论】:
-
您使用的是哪个版本的 PF?也许您需要强制对排序事件进行 ajax 更新。
如:stackoverflow.com/questions/23761333/… -
你的bean至少是
@ViewScoped吗?
标签: sorting jsf primefaces datatable controller