Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added "Putting wicket components into the message"

...

Code Block
add(new Label("summary", getString("summ.$\{msgPrefs.style\}", new Model(summary))));

Putting wicket components into the message

If you want to translate a components text containing additional Wicket components (e.g. Links) you can use wicket:message-tag in combination with a container around it. Example a form component label related to a checkbox (label for) containing two links:

Java:

Code Block

final FormComponentLabel termsAndConditionsCheckLabel = new FormComponentLabel("termsAndConditionsCheckLabel", acceptedTerms);
form.add(termsAndConditionsCheckLabel);

final Link terms = new Link("terms") {
  @Override
  public void onClick() {
    setResponsePage(TermsOfUsePage.class);
  }
};
termsAndConditionsCheckLabel.add(terms);

final Label termsOfUse = new Label("terms_of_use", new ResourceModel("terms_of_use"));
termsOfUse.setRenderBodyOnly(true);
terms.add(termsOfUse);

Markup (HTML):

Code Block

<label wicket:id="termsAndConditionsCheckLabel">
  <wicket:message key="termsAndConditionsCheckLabel">I am 18 years old and agree with the <a href="#" wicket:id="terms"><span wicket:id="terms_of_use">terms of use</span></a> and conditions.</wicket:message>
</label>

Messages (in ....properties.xml):

Code Block

<entry key="termsAndConditionsCheckLabel">I am 18 years old and agree with the ${terms_of_use} and conditions.</entry>
<entry key="terms_of_use">Terms of Use</entry>

The trouble with property files

...