internationalization - Wicket 中表单组件的国际化标签

标签 internationalization wicket

如何为我的表单组件正确创建国际化标签,以便在显示反馈消息时显示国际化字段名称而不是 java 代码中的字段名称?

我读过这个:

https://cwiki.apache.org/WICKET/everything-about-wicket-internationalization.html

以及 wicket 的 xhtml 标签的文档:

https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html

<label wicket:for="name">
     <wicket:label>
         <wicket:message key="label.name"/>
     </wicket:label>
</label>
<input wicket:id="name" type="text" wicket:message="placeholder:label.name" />

这会导致以下错误:
Last cause: Expected close tag for '<wicket:label>' Possible attempt to embed 
component(s) '<wicket:message key="label.name"/>' in the body of this 
component which discards its body

如果我更换 wicket:message使用一些任意文本,它会在任何关联的反馈消息中显示文本。

(有一个相关的 jira 问题:https://issues.apache.org/jira/browse/WICKET-3903 但是我仍然不明白已经做了什么来解决这个问题以及我必须做什么......)

刚刚发现在java中有一种方法可以做到这一点:
add(new TextField<String>("name").setRequired(true).setLabel(new Model<String>(getString("label.name"))));

是否有可能以更舒适的方式做到这一点?

最佳答案

我刚刚测试了以下内容:

<form wicket:id="form">
        <label for="input"><wicket:message key="input">some input</wicket:message></label>
        <input wicket:id="input" type="text" name="input">
        <input type="submit" value="submit">
 </form>

在java类中:
Form<HomePage> form = new Form<HomePage>("form"
                              , new CompoundPropertyModel<HomePage>(this));
    wmc.add(form);

    TextField textField = new TextField("input");
    textField.setRequired(true);
    form.add(textField);

在我提供的属性文件中:
input=SomeInputField

这导致了以下屏幕(如果我将所需字段留空并按提交。

enter image description here

这是你想要的?

关于internationalization - Wicket 中表单组件的国际化标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393610/

相关文章:

nginx - 如何避免 Wicket 将页面从 HTTPS 重定向到 HTTP

java - 如何在我的自定义 Wicket 模型类中注入(inject) Spring bean?

java - 防止 Wicket 8 AjaxEventBehavior onChange 为不在子页​​面上提交表单

javascript - dust.js:在作用域部分使用路径

ios - 以编程方式更改应用程序语言

python - django rest框架中日期的国际化?

ExtJS MVC、动态加载和 i18n

在 ts 代码中带有 i18n 的 Angular 6 应用程序

java - 返回字符串而不是在 wicket 中呈现页面

java - 在 DataProvider 中使用 LoadableDetachableModel 有何目的?