更改订单时,访问DataTable项会返回错误的选定项目

时间:2018-05-23 12:19:58

标签: jsf primefaces

为了更好地读取dataTable中单元格的内容,我使用commandLink打开了一个对话框。

只要dataTable的sortOrder设置为升序,这就可以正常工作。在使用sortOrder desc并单击commandLink时,如果sortOrder已升序(换句话说,在desc dataTable -8,7,....,2中),该对话框将显示该项目的结果。 1-8行,单击id = 2的行将显示行id = 7的内容。

导致ID混淆的原因是什么?我暂时不在临时bean中存储实际点击的项目,不应该受sortOrder的影响吗?对于我想要实现的目标,是否有更好的实践?

PF版本5.3,JSF 2.2.7

dataTable和对话

<p:dataTable id="improvementTable" var="improvement" widgetVar="improvementsTable" value="#{Controller.improvements}" sortBy="#{improvement.id}" sortOrder="descending">
    <p:column headerText="ID">
        <p:cellEditor>
            <f:facet name="output">
                <h:outputText value="#{improvement.id}" />
            </f:facet>
            <f:facet name="input">
                <p:inputText id="modelInput" value="#{improvement.id}" />
            </f:facet>
        </p:cellEditor>
    </p:column>
    <p:column>
        <p:commandLink id="detailOut" value="#{improvement.detail}" action="#{Controller.setSelectedImprovement(improvement)}" process="@this" oncomplete="PF('wDetail').show();" update=":dlgDetail" />
    </p:column>
</p:dataTable>
</h:form>
<p:dialog id="dlgDetail" widgetVar="wDetail">
    <h:outputText value="#{Controller.selectedImprovement.detail}" />
</p:dialog>

在Bean中

@ManagedBean (name="Controller")  
@RequestScoped  
public class Controller{   

    private List<Improvement> improvements;   
    private Improvement selectedImprovement;

    @PostConstruct
    public void load()  {  
        CIMImprovementDao cimDao = new CIMImprovementDao();
        improvements = cimDao.getAll();
    }    

    public List<Improvement> getImprovements() {  
        return improvements;  
    }  

    public Improvement getSelectedImprovement() {
        return selectedImprovement;
    }

    public void setSelectedImprovement(Improvement selectedImprovement) {
        this.selectedImprovement = selectedImprovement;
    }

} 

0 个答案:

没有答案