Set html element attribute from wicket message

2019-07-13 04:51发布

Is there some way to get a value from wicket message into an html attribute?

I need to get wicket:message key="nameQtip

into

    <input type="text" id="firstName" info="Here_I_Want_The_Wicket_Message"/>

I'm using the info attribute to pass text to qTip.

标签: java wicket
1条回答
2楼-- · 2019-07-13 05:13

You can achieve this easily with AttributeModifier

public class TextFieldInfoPage extends WebPage {

    public TextFieldInfoPage() {
        super();
        final TextField<String> firstName = new TextField<String>("firstName");
        firstName.add(new AttributeModifier("info", "Here_I_Want_The_Wicket_Message"));
        add(firstName);
    }

}

If you need this regularly, you can make own subclass from TextField. Be aware that while info is not supported attribute for input, HTML validators will complain about this...

Also you can do this more statically as:

<input wicket:id="firstName" type="text" wicket:message="info:infoMessage"/>

where infoMessage is in property file.

查看更多
登录 后发表回答