p:datatable filter: cannot validate component with empty value

只愿长相守 提交于 2019-12-02 07:34:29
Jasper de Vries

I was able to achieve this by setting widgetVar="myTable" to the data table, using a custom filter field, replacing the cell contents with p:outputLabel (which has ondblclick) and JavaScript it all together:

<p:column headerText="Session" filterBy="#{transaction.session}" ...>
    <f:facet name="filter">
        <p:inputText id="myFilter"
                     value="#{myBean.myFilter}"
                     onchange="PF('myTable').filter()"/>
    </f:facet>
    <p:outputLabel value="#{transaction.session}"
                   ondblclick="document.getElementById('myForm:myTable:myFilter').value = this.innerText;PF('myTable').filter()"/>
</p:column>

For better readability, here's the ondblclick:

var filterId = 'myForm:myTable:myFilter';
document.getElementById(filterId).value = this.innerText;
PF('myTable').filter();

You could replace p:outputLabel with a simple h:outputText, but in that case (assuming you are on JSF 2.2+) you need to add the namespace xmlns:a="http://xmlns.jcp.org/jsf/passthrough". Now you can use:

<h:outputText value="#{transaction.session}"
              a:ondblclick="..."/>

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!