【问题标题】:Dandelion Datatables i18n spring resolver not working蒲公英数据表 i18n 弹簧解析器不工作
【发布时间】:2014-06-03 09:44:18
【问题描述】:

我最近开始在我的 spring mvc 4 + hibernate 4 + tiles 3 项目中集成datatables

我希望它显示具有各种语言支持的标题。

所以我从link开始。

根据此页面建议,我的标题显示???key??? 消息。

我想在列标题中显示Id,但它显示的是???table.header.id???

这个link

如果在捆绑包中找不到密钥,则 ???key???消息将显示在列标题中。

但我已经关注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

还有global_en.properties

table.header.id=Id

我还复制了与 global.properties.. 相同的文件,但没有成功。

我的jsp文件包含

<datatables:table id="users" ...>
   <datatables:column titleKey="table.header.id" property="userId" />
<datatables:table />

我的资源文件夹结构是

我应该把table.header.id=Id放在哪里??

需要任何帮助。提前致谢。

注意:我使用的是AJAX source + server-side processing

【问题讨论】:

    标签: spring spring-mvc internationalization datatables dandelion


    【解决方案1】:

    关于您的消息的位置

    您似乎使用 Spring ResourceBundleMessageSourceglobal 作为基本名称。因此,将标题列的所有翻译放在global_*.properties 文件中是有意义的。

    关于???key??? 消息

    原来是 v0.10.0 中引入的一个错误。

    等待下一个版本发布,有一个解决方法,但仅适用于 DOM 源。 步骤如下。

    1) 您将使用&lt;spring:message&gt; 标记,而不是使用titleKey 列属性。从理论上讲,它们做的事情完全相同:在您配置的资源包中查找资源。

    首先在 JSP 中声明 Spring 标签库:

    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    

    2) 然后你需要更新蒲公英-数据表标签库的使用。作为一种解决方法,您可以使用&lt;datatables:columnHead&gt; (docs here) 标记在列标题中插入任何内容。

    按如下方式使用即可:

    <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 />
    

    一些观察:

    • 如果你需要访问被迭代的集合的对象,你需要添加row表属性,因为它是通过JSTL的&lt;c:out&gt;标签完成的
    • 您需要删除property列属性,否则&lt;datatables:column&gt;标签的内容将不会被评估

    这是很多工作,但回报很少 - 很抱歉 - 但等待下一个版本发布,至少它可以工作。 已添加new issue

    如果您使用的是AJAX source + server-side processing

    先做一个变量

    <spring:message code="table.header.id" var="titleId" /> 
    

    并添加到

    <datatables:column title="${titleId}" property="userId" />
    

    还有一个修复程序here。请升级到0.10.1-SNAPSHOT 版本。

    (StackOverflow 要求的免责声明:我是蒲公英的作者)

    【讨论】:

    • 但这在我的控制器的标准中返回 0 而不是 userId ......评估的查询变为 From com.models.UserLogin u ORDER BY u.0 ASC 而不是 From com.models.UserLogin u ORDER BY u.userId ASC.. 这个抛出错误......
    • 这不适用于服务器端...对于任何项目服务器端都需要实现...但没有 i18n 支持正在工作..!!!!请提供一些解决方案....尽快....
    • 确实,我忘了提到这个解决方法只适用于 DOM 源。我会在我的回答中提到它。请编辑您的答案并提及您正在使用 AJAX 源 + 服务器端处理。这很重要。
    • 顺便提一下问题has been fixed,你可以试试0.10.1-SNAPSHOT版本。阅读here 了解如何使用 SNAPSHOT 版本。
    • 我找到了另一种解决方法...请在您的回答中提及这个...我做了&lt;spring:message code="table.header.id" var="titleId" /&gt; 并将其添加到&lt;datatables:column title="${titleId}" property="userId" /&gt;...并且它有效!!!!在你的答案中提到这一点,这样我就可以批准你的答案是正确的...... :)
    猜你喜欢
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 2016-09-08
    • 1970-01-01
    相关资源
    最近更新 更多