I maintain what I stated below, but <ehem> this one is not working. In the end, I've decided to change the key's name in case there doesn't exist the desired resource in the panel, like this:
public String getObject() { String ret = c.getString(key); if (ret == null){ ret = c.getString(key+".default"); } return ret; } MyTabbedPanel contains keys "button1.label.default" and panel's can define "button1.label" if they need to. Thanks anyway :-) Xavier 2009/11/19 Xavier López <xavil...@gmail.com> > 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 <igor.vaynb...@gmail.com> > > 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 <xavil...@gmail.com> 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 <igor.vaynb...@gmail.com> >> > >> >> 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 <xavil...@gmail.com> >> 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: users-unsubscr...@wicket.apache.org >> >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> >> >> >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > > -- > "Klein bottle for rent--inquire within." >