On 3/6/08, Ned Collyer <[EMAIL PROTECTED]> wrote:
>
>  I'd like to get some thoughts around adding the following to the base
>  Component class.
>
>  I may have missed something and it's already available via some other
>  elegant means :)
>
>  add(new Label("testLabel", getString(dashboardModel.getNameKey(),
>  DashboardTestModel.class, "default val")));
>
>  It's sort of a convience method that would get used in panels, forms, pages
>  etc. and would allow any class to have its appopriate translations written
>  in property files next to the class.
>
>  At the moment I have it in an abstract DashboardPanel, but I'd like to
>  expose it to all components, and I think it could be useful for others.
>
>  (I can of course put it into some Util thing, but it makes it less handy,
>  and every impl a bit less elegant.)
>
>  What are your thoughts?
>

Since you're passing in the class, couldn't this go into a utils type
class?  I don't know, but the fact that you're asking for resources
from other classes seems like it doesn't belong in the component
hierarchy.

>
>     /**
>      * @param key   The resource key
>      * @param clazz The class
>      *
>      * @return the resolved string, or null if it cannot be found.
>      */
>     public String getString(final String key, final Class clazz) {
>         return getString(key, clazz, null);
>     }
>
>     /**
>      * @param key          The resource key
>      * @param clazz        The class
>      * @param defaultValue A default value if the string cannot be found
>      *
>      * @return the resolved string, or null if it cannot be found.
>      */
>     public String getString(final String key, final Class clazz, final
>  String defaultValue) {
>         final IResourceSettings resourceSettings =
>  Application.get().getResourceSettings();
>
>         String string = null;
>
>         for (Object o : resourceSettings.getStringResourceLoaders()) {
>             IStringResourceLoader loader = (IStringResourceLoader) o;
>             string = loader.loadStringResource(clazz, key, getLocale(),
>  getStyle());
>             if (string != null) {
>                 break;
>             }
>         }
>         return (string != null) ? string : defaultValue;
>     }
>
> --
>  View this message in context: 
> http://www.nabble.com/Can-we-get-a-couple-of-methods-added-to-Component-Localizer--tp15885409p15885409.html
>  Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to