问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/18521416/set-html-element-attribute-from-wicket-message