【问题标题】:JSF / Primefaces dataTable and sorting issueJSF / Primefaces dataTable 和排序问题
【发布时间】:2012-10-01 10:44:13
【问题描述】:

我正在使用 PrimeFaces 2.2 和 JSF 2.0.3。

我有一个包含以下数据表的 xhtml 视图:

<p:dataTable id="fooTable" 
    widgetVar="fooTable" 
    rowKey="#{foo.id}" 
    var="foo" 
    value="#{fooQueue.foos}"
    styleClass="table" 
    selection="#{fooQueue.selectedfoo}" 
    filteredValue="#{fooQueue.filteredfoos}"
    paginatorPosition="bottom" 
    paginatorAlwaysVisible="true" 
    selectionMode="single"
    rowEditListener="#{fooQueue.save}" 
    paginator="true" 
    rows="10" 
    rowIndexVar="#{foo.id}"
    emptyMessage="No foos found with given criteria" 
    rowStyleClass="#{foo.status == const.submitted ? 'gray' : null}"
    onRowSelectUpdate=":form:deleteValidation">

        <p:column id="mothersName" filterBy="#{foo.header1}"  filterMatchMode="contains">
            <f:facet name="header">
                <h:outputText value="Mother's Name" styleClass="tableHeader2" />
            </f:facet>

            <p:commandLink action="#{fooQueue.next(foo)}" 
                ajax="false" 
                disabled="#{foo.status == const.submitted || foo.id == 0}">
                <f:setPropertyActionListener value="#{foo}" target="#{fooQueue.selectedfoo}" />  
                <h:outputText value="#{foo.header1}" styleClass="tableData" />
            </p:commandLink>
        </p:column>

        <p:column sortBy="#{foo.header4}" >
            <f:facet name="header">
                <h:outputText value="DOB" styleClass="tableHeader2" style="width: 400px" />
            </f:facet>
            <h:outputText value="#{foo.header4}" styleClass="#{(foo.overSevenDays and foo.status != const.submitted and foo.id != 0)?'tableDataRed':'tableData'}" />
        </p:column></p:dataTable>

.. 使用以下支持 bean:

@ViewScoped @ManagedBean public class FooQueue extends BaseViewBean { private List foos; private Foo selectedFoo; private List filterdFoos; public FooQueue() { logger.debug("Creating new FooRegQueue"); retrieveFooRecords(); } private void retrieveFooRecords(){ foos = new ArrayList(); foos.addAll(fooService.getAllFoos()); } public String next(Foo clickedFoo) { System.out.println(clickedFoo.getId()); return ""; } public Collection getFoos() { return foos; } public Foo getSelectedFoo() { return selectedFoo; } public void setSelectedFoo(Foo foo) { if (foo != null) { this.selectedFoo = foo; } } public void setFilterdFoos(List filterdFoos) { this.filterdFoos = filterdFoos; } public List getFilterdFoos() { return filterdFoos; } }

注意母亲姓名列上的“commandLink”和出生日期列上的“sortBy”。

我遇到了一个奇怪的问题,似乎仅限于IE,如果我按DOB对数据进行排序,然后分页到最后一页并单击表格中最后一条记录的commandLink,它会触发两个动作事件。第一个事件正确报告我单击了排序表中的最后一条记录。但是第二次调用 next() 方法是针对未排序表中的最后一条记录。

谁能发现我的 xhtml 或支持 bean 有什么问题?这是一个已知的 PrimeFaces 问题吗?已知的 IE 问题?

我正在使用 IE 8 进行测试。

【问题讨论】:

  • 你用的是什么pf版本?
  • 我认为不再支持该版本的 PF。您会更高兴升级到 3.3.X 版本。我什至不认为 cagatay 会招待这个:)
  • 那么我想我的问题是,primefaces 2.x 版本是否存在已知问题,这会导致这种行为,并且这些问题在 3.3.X 中得到解决了吗?如果在 3.3.X 中发生同样的行为,那我该怎么办?
  • 我刚刚注意到,如果我先选择行,然后单击 commandLink,它会打开预期的记录并且只触发一次操作。如果未选择该行并且我单击该链接,则会触发该操作两次。

标签: java internet-explorer jsf-2 primefaces


【解决方案1】:

我解决了。我只需要改变它:

<p:commandLink action="#{fooQueue.next(foo)}" 
  ajax="false" 
  disabled="#{foo.status == const.submitted || foo.id == 0}">
   <f:setPropertyActionListener value="#{foo}" target="#{fooQueue.selectedfoo}" />  
   <h:outputText value="#{foo.header1}" styleClass="tableData" />
</p:commandLink>

到这里:

<p:commandLink action="#{fooQueue.next(foo)}" 
  ajax="true" 
  disabled="#{foo.status == const.submitted || foo.id == 0}">
   <f:setPropertyActionListener value="#{foo}" target="#{fooQueue.selectedfoo}" />  
   <h:outputText value="#{foo.header1}" styleClass="tableData" />
</p:commandLink>

注意 ajax="true"。因为它以前设置为 ajax="false",所以它正在实例化我的支持 bean 的一个新实例,并且正在加载以默认排序顺序选择的行。现在它不会实例化一个新实例,而是加载我点击的实际记录。

【讨论】:

    猜你喜欢
    • 2013-12-26
    • 2011-07-24
    • 2011-09-22
    • 2012-04-29
    • 2015-01-27
    • 1970-01-01
    • 2012-02-28
    • 1970-01-01
    • 2014-09-13
    相关资源
    最近更新 更多