如何更改默认 p:dataTable emptyMessage 消息 [英] How to change default p:dataTable emptyMessage message
问题描述
我正在使用 PrimeFaces 的数据表.我收到未找到记录".当表没有元素时.我想将此消息更改为无结果"之类的内容,并将此消息设为 i18n 类型.
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.
我不想使用
<p:dataTable
id="idTable"
...
emptyMessage="#{messages['general.message.EmptyList']}"
>
对于每张桌子.
如何更改 p:dataTable 默认的 emptyMessage
消息?
How can I change p:dataTable default emptyMessage
message?
推荐答案
来自 PrimeFaces 3.5 DataTable
源代码:
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 }
因此,它是硬编码的,除了破解 PrimeFaces 源或创建一个 标记文件(不是复合!)
包装了
带有所需的消息集.
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>
如果您实际上不想更改消息,而只想将其隐藏,那么您也可以选择纯 CSS 解决方案:>
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;
}
这篇关于如何更改默认 p:dataTable emptyMessage 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!