24

I am using PrimeFaces' dataTable. I get "No records found." when table has no element. I want to change this message to something like "No result" and make this message i18n type.

I don't want to use

<p:dataTable 
    id="idTable" 
    ...
    emptyMessage="#{messages['general.message.EmptyList']}"
>

for every table.

How can I change p:dataTable default emptyMessage message?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ahmet
  • 1,085
  • 2
  • 16
  • 32
  • 11
    I suggest adding issue to PrimeFaces team. Honestly I think it is time (for tool with that level of maturity) to make properties file with all default messages they are using, so it can be overridden like those default JSF validation messages. Not just for datatable, but for all components. – partlov Feb 13 '13 at 14:53

2 Answers2

39

From the PrimeFaces 3.5 DataTable source code:

210    public java.lang.String getEmptyMessage() {
211        return (java.lang.String) getStateHelper().eval(PropertyKeys.emptyMessage, "No records found.");
212    }

So, it's hard coded and there's no way to change it in a single place other way than hacking the PrimeFaces source or creating a tagfile (not composite!) <my:dataTable> which wraps the <p:dataTable> with the desired message set.

<ui:composition ...>
    <p:dataTable id="#{id}" value="#{value}" var="item" 
        emptyMessage="#{messages['general.message.EmptyList']}">
        <ui:insert />
    </p:dataTable>
</ui:composition>
<my:dataTable id="foo" value="#{bean.items}">
    <p:column>#{item.foo}</p:column>
    <p:column>#{item.bar}</p:column>
</my:dataTable>

If you actually don't want to change the message, but merely want to hide it altogether, then you could also opt for a pure CSS solution:

.ui-datatable-empty-message {
    display: none;
}
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
-1

write emptyMessage="" inside the datatable Ej:

<p:dataTable var="hola"
    value="#{logica.hola}"
    emptyMessage="text you want to appear" >
    </p:dataTable>
luisja19
  • 27
  • 5
  • 1
    Just plain code isn't a complete answer. Please explain yourself as well, that's a generell rule. But furthermore you didn't provide any new information, so your answer is redundant and doesn't improve the provided information here. – L. Guthardt Dec 14 '17 at 09:52
  • sorry. I wanted to say that you write the text you want to appear between the quotes "" – luisja19 Jan 09 '18 at 15:04