Class WicketMessageResolver
- java.lang.Object
-
- org.apache.wicket.markup.resolver.WicketMessageResolver
-
- All Implemented Interfaces:
Serializable
,IComponentResolver
,IClusterable
public class WicketMessageResolver extends Object implements IComponentResolver
This is a tag resolver which handles <wicket:message key="myKey">Default Text</wicket:message>. The resolver will replace the whole tag with the message found in the properties file associated with the Page.You can also nest child components inside a wicket:message and then reference them from the properties file. For example in the html
<wicket:message key="myKey"> This text will be replaced with text from the properties file. <span wicket:id="amount">[amount]</span>. <a wicket:id="link"> <wicket:message key="linkText"/> </a> </wicket:message>
Then in the properties file have a variable with a name that matches the wicket:id for each child component. The variables can be in any order, they do NOT have to match the order in the HTML file.myKey=Your balance is ${amount}. Click ${link} to view the details. linkText=here
And in the javaadd(new Label("amount", new Model<String>("$5.00"))); add(new BookmarkablePageLink<Void>("link", DetailsPage.class));
This will outputYour balance is $5.00. Click <a href="#">here</a> to view the details.
If variables are not found via child component, the search will continue with the parents container model object and if still not found with the parent container itself. It is possible to switch between logging a warning and throwing an exception if either the property key/value or any of the variables can not be found.- Author:
- Juergen Donnerstag, John Ray
- See Also:
ResourceSettings.setThrowExceptionOnMissingResource(boolean)
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
ESCAPE_ATTRIBUTE
The name of the attribute that defines whether the resource value should be HTML escapedstatic String
KEY_ATTRIBUTE
The name of the attribute that defines the resource keystatic String
MESSAGE
-
Constructor Summary
Constructors Constructor Description WicketMessageResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Component
resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
Try to resolve a component.
-
-
-
Field Detail
-
MESSAGE
public static final String MESSAGE
- See Also:
- Constant Field Values
-
KEY_ATTRIBUTE
public static final String KEY_ATTRIBUTE
The name of the attribute that defines the resource key- See Also:
- Constant Field Values
-
ESCAPE_ATTRIBUTE
public static final String ESCAPE_ATTRIBUTE
The name of the attribute that defines whether the resource value should be HTML escaped- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WicketMessageResolver
public WicketMessageResolver()
-
-
Method Detail
-
resolve
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
Description copied from interface:IComponentResolver
Try to resolve a component.- Specified by:
resolve
in interfaceIComponentResolver
- Parameters:
container
- The container parsing its markupmarkupStream
- The current markupStreamtag
- The current component tag while parsing the markup- Returns:
- component or
null
if not found
-
-