Awesome! I didn't know about Component.getString(). I had it in front of me all the time (you can label me newbie). It's amazing how easy things are in Wicket when you know how to deal with them.
Thank you Igor :) 2009/11/19 Igor Vaynberg <[email protected]> > you should be using getstring() on the component instead of > getlocalizer().getstring(), simpler, but anyways... > > why not simply: > > class componentresourcemodel extends abstractreadonlymodel<string> { > private final component c; > private final string key; > public componentresourcemodel(component c, string key) { > this.c=c;this.key=key; } > public string getobject() { return c.getstring(key); } > } > > -igor > > On Thu, Nov 19, 2009 at 7:30 AM, Xavier López <[email protected]> wrote: > > I've been trying to retrieve the panel's resource, using getLocalizer and > > ComponentStringResourceLoader in the following ways: > > > > button1.setModel(new AbstractReadOnlyModel(){ > > public Object getObject(){ > > // Attempt 1 > > return panel.getLocalizer().getString("button1.label", panel); > > // Attempt 2 > > return new ComponentStringResourceLoader().loadStringResource(panel, > > "button1.label"); > > } > > }); > > > > But I've been never been able to get the resource from the panel. > > I suppose the matter of it all is that I'm trying to get the resource > from > > the parent component, so StringResourceModel and derivates start trying > to > > retrieve it at the invoker's level... > > > > Would it be better to get the label from the component, let's say, by > means > > of an overridable method on MyTabPanel ? > > > > Thanks, > > Xavier > > > > > > 2009/11/17 Igor Vaynberg <[email protected]> > > > >> you can write your own model that first tries to get the resource from > >> the panel and then falls back. > >> > >> -igor > >> > >> On Tue, Nov 17, 2009 at 2:58 AM, Xavier López <[email protected]> > wrote: > >> > Hi, > >> > > >> > I've set up a custom MyTabbedPanel by modifying class TabbedPanel. It > >> will > >> > include a row of buttons, added on setSelectedTab which will be the > same > >> for > >> > all tabs. > >> > Now, I'd like each tab (panel) to be able to override the text of each > >> > button, like this: > >> > > >> > public final void setSelectedTab(int index) { > >> > ... > >> > // Add Panel with content for the tab to global form variable > >> > final MyTabPanel panel = tabs.get(index).getPanel(TAB_PANEL_ID); > >> > form.addOrReplace(panel); > >> > // Add generic buttons to form, with specific settings depending on > >> panel's > >> > properties > >> > Button button1 = new Button("button1"){ ... }; > >> > button1.setModel(new StringResourceModel("button1.label",panel, > null)); > >> > form.addOrReplace(button1); > >> > ... > >> > } > >> > > >> > The problem is that the StringResourceModel is always pointing to the > >> > property in MyTabbedPanel.xml, and not the panel's. > >> > I've noticed that if I remove "button1.label" from MyTabbedPanel's > >> property > >> > file, Wicket gets the panel's "button1.label" property, but I'd like > to > >> > provide some kind of 'default' label for the buttons so that panels > >> aren't > >> > forced to explicitly define this property. > >> > > >> > I expected specifying the 'panel' component on StringResourceModel's > >> > constructor would do the trick, but it doesn't work. Is it possible to > >> > accomplish what I'm trying to do ? > >> > > >> > Thanks, > >> > Xavier > >> > > >> > >> --------------------------------------------------------------------- > >> 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] > > -- "Klein bottle for rent--inquire within."
