How to change default p:dataTable emptyMessage message

26,535

Solution 1

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;
}

Solution 2

write emptyMessage="" inside the datatable Ej:

<p:dataTable var="hola"
    value="#{logica.hola}"
    emptyMessage="text you want to appear" >
    </p:dataTable>
Share:
26,535

Related videos on Youtube

ahmet
Author by

ahmet

Computer Engineering, Java, Web, Backend, Frontend, Spring Boot, Restful, HTML, CSS, Javascript, Maven, Apache, Primefaces, JSF, Java: IntelliJ, Dropwizard, NodeJS, EmberJS, Handlebars, CoffeeScript, Consul, Zookeeper, MongoDB, Hazelcast, Redis, Logstash, Kibana, Vagrant, Riemann, MySQL, Oracle Python: PyCharm, Flask, Requests, Suds-Jurko, OpenPYXL

Updated on January 10, 2020

Comments

  • ahmet
    ahmet over 4 years

    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?

    • partlov
      partlov about 11 years
      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.
  • L. Guthardt
    L. Guthardt over 6 years
    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.
  • luisja19
    luisja19 over 6 years
    sorry. I wanted to say that you write the text you want to appear between the quotes ""
  • sergioFC
    sergioFC almost 6 years
    Is it there any reason for this to be hardcoded still in version 6?