问题
I have recently started to integrate datatables in my spring mvc 4 + hibernate 4 + tiles 3 Project.
I want it to display header with various language support.
So I started with this link.
As per this page suggests my header shows ???key??? message.
I want to display Id in column header but it is showing ???table.header.id???.
This link says
If the key cannot be found in the bundle, the ???key??? message will be displayed in the column header.
But I have put following in datatables.properties
i18n.locale.resolver=com.github.dandelion.datatables.extras.spring3.i18n.SpringLocaleResolver
global.i18n.message.resolver=com.github.dandelion.datatables.extras.spring3.i18n.SpringMessageResolver
Also have put in global_en.properties
table.header.id=Id
I also copied same file as global.properties.. but not worked.
My jsp file contains
<datatables:table id="users" ...>
<datatables:column titleKey="table.header.id" property="userId" />
<datatables:table />
My Resource folder structure is
Where should I put table.header.id=Id??
Any help is required. Thanks in advance.
Note: I am using AJAX source + server-side processing.
回答1:
About the location of your messages
You seem to be using the Spring ResourceBundleMessageSource with global as a basename. So it makes sense to put all translations of header columns in global_*.properties files.
About the ???key??? message
It turns out to be a bug introduced in the v0.10.0.
Waiting for the next version to be released, there is a workaround, but working only with DOM sources. Here follows the steps.
1) Instead of using the titleKey column attribute, you will use the <spring:message> tag. Theorically, they do the exact same thing: lookup a resource in your configured resource bundle.
Begin by declaring the Spring taglib in your JSP:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
2) Then you need to update the usage of the Dandelion-Datatables taglib. As a workaround, you can use the <datatables:columnHead> (docs here) tag to insert any content in a column header.
Just use it as follows:
<datatables:table id="users" ... row="user" >
...
<datatables:column>
<%-- Everything inside this tag will only appear in the header column --%>
<datatables:columnHead>
<spring:message code="table.header.id" /> <== this will appear in the column header only
</datatables:columnHead>
<%-- Everything else will appear in all cells --%>
<c:out value="${person.id}" /> <== this will appear in all column cells
</datatables:column>
...
<datatables:table />
Some observations:
- You need to add the
rowtable attribute if you need to access the object of the collection being iterated on, as it's done with the<c:out>tag of the JSTL - You need to remove the
propertycolumn attribute, or the content of the<datatables:column>tag will not be evaluated
This is a lot of work for very little return - sorry for that - but waiting for the next version to be released, at least it works. A new issue has been added.
If you are using AJAX source + server-side processing.
Make a variable first
<spring:message code="table.header.id" var="titleId" />
and added it in
<datatables:column title="${titleId}" property="userId" />
Also a fix is available here. Kindly upgrade to 0.10.1-SNAPSHOT version.
(Disclaimer required by StackOverflow: I'm the author of Dandelion)
来源:https://stackoverflow.com/questions/24011927/dandelion-datatables-i18n-spring-resolver-not-working