java - JSF/Primefaces 数据表和排序问题

标签 java internet-explorer jsf-2 primefaces

我正在使用 PrimeFaces 2.2 和 JSF 2.0.3。

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

<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() 方法是针对 UNsorted 表中的最后一条记录。

任何人都可以识别出我的 xhtml 或支持 bean 有什么问题吗?这是已知的 PrimeFaces 问题吗?已知的 IE 问题?

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

最佳答案

我解决了。我只需更改此:

<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 的新实例,并且正在加载以默认排序顺序选择的行。现在它不会实例化新实例,而是加载我单击的实际记录。

关于java - JSF/Primefaces 数据表和排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12828205/

相关文章:

tomcat - Maven tomcat :run goal and jsf annotation based component/converter/validator scanning

java - 在 Android 上分析来自麦克风的声音(谐波、分音、泛音)

windows - 如何在多脚本中使用 powershell 函数?

Python 保护设置 IE

IE 中 CSS 类的 Jquery 选择器确实很慢 - 有解决方法吗?

jsf - 如何为 h :dataTable/ui:repeat? 的每一行/项目设置转换器属性

jsf-2 - JSF 2 中的范围

java - Java中如何停止输入

java - 货币代码到货币符号映射

java - 将新的列属性添加到 shapefile 并使用 Geotools Java 将其保存到数据库