基于html中的标签所需的错误消息?

时间:2016-06-22 15:39:49

标签: java properties internationalization wicket

我尝试使用表单和标签的WicketApplication。

我使用Wicket 7.3.0,从jetty中的maven-quickstart运行。

我希望反馈消息使用label内容,但现在它使用了字段名称。我记得在过去的某个时候看到这个工作,但现在似乎不起作用。也许我依赖边缘案例。无论如何,我的问题是,如果这是“正确的”方式,或者如果不是,我应该采取不同的方式。

这是我的(测试用例)代码:

HTML

<body>
    <div wicket:id="fp"></div>
    <form wicket:id="f">
        <table>
        <tr><td><label wicket:for="naam"><wicket:message key="Naam"></wicket:message></label></td><td><input wicket:id="naam" /></td></tr>
        <tr><td><label wicket:for="adres"><wicket:message key="Adres"></wicket:message></label></td><td><input wicket:id="adres" /></td></tr>
        <tr><td><label wicket:for="woonplaats"><wicket:message key="Woonplaats"></wicket:message></label></td><td><input wicket:id="woonplaats"/></td></tr>
        </table>
        <a wicket:id="save">Save!</a>
    </form>
</body>

爪哇

public HomePage(final PageParameters parameters) {
        super(parameters);
        final FeedbackPanel fp = new FeedbackPanel("fp");
        fp.setOutputMarkupId(true);
        this.add(fp);
        Form f = new Form<Void>("f") {
        };
        f.setOutputMarkupId(true);
        f.add(new TextField("naam", Model.of("Rob")).setRequired(true));
        f.add(new TextField("adres", Model.of("Fantasieweg 4")));
        f.add(new TextField("woonplaats", Model.of("Babbelerdam")).setRequired(true));
        // TODO Add your page's components here
        f.add(new AjaxSubmitLink("save", f) {
            @Override
            protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
                target.add(fp);
            }

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                // TODO Auto-generated method stub
                target.add(fp);
            }
        });
        this.add(f);
    }

WicketApplication.properties

Required=Veld ${label} is verplicht
Naam=PropertyNaam
Adres=PropertyAdres
Woonplaats=PropertyWoonplaats

1 个答案:

答案 0 :(得分:0)

尝试setlabel为您的组件,如下所示:

    ...
    f.add(new TextField("naam", Model.of("Rob")).setRequired(true).setLabel(YOUR_COMPONENT_LABEL));
    ...