Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Creating a Model for your Label really is <strong>The Wicket Way</strong>. That said, you can make it easy on yourself with the occasional utility function. Here's one I use:</p> <pre><code>/** * Creates a resource-based label with fixed arguments that will never change. Arguments are wrapped inside of a * ConvertingModel to provide for automatic conversion and translation, if applicable. * * @param The component id * @param resourceKey The StringResourceModel resource key to use * @param component The component from which the resourceKey should be resolved * @param args The values to use for StringResourceModel property substitutions ({0}, {1}, ...). * @return the new static label */ public static Label staticResourceLabel(String id, String resourceKey, Component component, Serializable... args) { @SuppressWarnings("unchecked") ConvertingModel&lt;Serializable&gt;[] models = new ConvertingModel[args.length]; for ( int i = 0; i &lt; args.length; i++ ) { models[i] = new ConvertingModel&lt;Serializable&gt;( new Model&lt;Serializable&gt;( args[i] ), component ); } return new CustomLabel( id, new StringResourceModel( resourceKey, component, null, models ) ); } </code></pre> <p>Details I'm glossing over here are:</p> <ol> <li>I've created my own <code>ConvertingModel</code> which will automatically convert objects to their String representation based on the IConverters available to the given component</li> <li>I've created my own <code>CustomLabel</code> that applies custom label text post-processing (as detailed in <a href="https://stackoverflow.com/questions/4387228/using-wicketmessage-tag-to-produce-partially-formatted-text/4391039#4391039">this answer</a>)</li> </ol> <p>With a custom IConverter for, say, a Temperature object, you could have something like:</p> <pre><code>Properties key: temperature=The current temperature is ${0}. Page.java code: // Simpler version of method where wicket:id and resourceKey are the same add( staticResourceLabel( "temperature", new Temperature(5, CELSIUS) ) ); Page.html: &lt;span wicket:id='temperature'&gt;The current temperature is 5 degrees Celsius.&lt;/span&gt; </code></pre> <p>The downside to this approach is that you no longer have direct access to the Label class, you can't subclass it to override <code>isVisible()</code> or things like that. But for my purposes it works 99% of the time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload