我有以下数据表:
<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()覆盖,但当我覆盖所有属性时,以及当我根本不覆盖它时,会发生相同的行为。如果我不排序表,它按预期工作。有什么建议?提前谢谢!
答案 0 :(得分:1)
Bean是RequestScoped。把它变成了ViewScoped,很有效。感谢@Geinmachi。