Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
On Wed, Apr 30, 2008 at 2:55 AM, Ned Collyer <[EMAIL PROTECTED]> wrote: > > Still - would be nice if the > MarkupInheritanceResolver$TransparentWebMarkupContainer somehow indicated it > was the the page (and returned the pages model). Component c=...; boolean page=(c==c.getPage()); -igor > > I can live without it. > > > > igor.vaynberg wrote: > > > > hm. dont know if doing localization based on type of model object is a > > great idea. there are many usecases where model type is quiet > > aribitrary, and as you have found out yourself you dont know what > > component you get passed in, so you just need to handle it in a way > > that makes sense to you. > > > > -igor > > > > -- > View this message in context: > http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16979272.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
err... i mean... mypanel extends panel { mypanel(id, Person person) { setModel(new Model(new Person())) } but u get the drift ;) On Wed, Apr 30, 2008 at 7:55 PM, Ned Collyer <[EMAIL PROTECTED]> wrote: > > > > mypanel extends panel { > mypanel(id, Person person) { > setModel(new Person()) > } > } > > >
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
Sure I can appreciate that :) However I define my panels to accept certain objects to chuck into the model, so thats fine. It means I can provide translations for pojos from non wicket jars using a method similar to wickets nice 1 class, 1 property file approach. Eg, mypanel extends panel { mypanel(id, Person person) { setModel(new Person()) } } MyNonWicketProject.jar Person.class Person.properties entity=Person name=Name surname=Surname Great for generating forms, and combined with generics becomes quite powerful. My usecase and requirement of wicket is probably non typical (which is why wicket rocks because I can customise it) - I have a large team each developing different modules, and things like translations need to be available in non wicket environments. Everything is translatable. Still - would be nice if the MarkupInheritanceResolver$TransparentWebMarkupContainer somehow indicated it was the the page (and returned the pages model). I can live without it. igor.vaynberg wrote: > > hm. dont know if doing localization based on type of model object is a > great idea. there are many usecases where model type is quiet > aribitrary, and as you have found out yourself you dont know what > component you get passed in, so you just need to handle it in a way > that makes sense to you. > > -igor > -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16979272.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
hm. dont know if doing localization based on type of model object is a great idea. there are many usecases where model type is quiet aribitrary, and as you have found out yourself you dont know what component you get passed in, so you just need to handle it in a way that makes sense to you. -igor On Tue, Apr 29, 2008 at 7:11 PM, Ned Collyer <[EMAIL PROTECTED]> wrote: > > I'm writing my own > > It does this > > @Override > public String loadStringResource(Component component, String key) { > if (component == null) { > return null; > } > String result = null; > Locale locale = component.getLocale(); > String style = component.getStyle(); > > IModel model = component.getInnermostModel(); > > if (model != null) { > Object object = model.getObject(); > > if (object != null) { > result = loadStringResource(object.getClass(), key, locale, > style); > } > } > return result; > } > > Basically if does the translation lookup based on whatever object is set to > the model of the component. > > It works fantastically except when the keys are in key="foodbar"/> - because component becomes an instance of > > MarkupInheritanceResolver$TransparentWebMarkupContainer and getModel returns > null. > > Are there other circumstances where the component can be > MarkupInheritanceResolver$TransparentWebMarkupContainer and it not be a > page? > > > > igor.vaynberg wrote: > > > > sorry, but i dont really get what the problem is or why it matters > > what component stringresourceloader gets. it simply traverses up the > > hieararchy looking for .properties files > > > > -igor > > > > -- > View this message in context: > http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16974123.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
I'm writing my own It does this @Override public String loadStringResource(Component component, String key) { if (component == null) { return null; } String result = null; Locale locale = component.getLocale(); String style = component.getStyle(); IModel model = component.getInnermostModel(); if (model != null) { Object object = model.getObject(); if (object != null) { result = loadStringResource(object.getClass(), key, locale, style); } } return result; } Basically if does the translation lookup based on whatever object is set to the model of the component. It works fantastically except when the keys are in - because component becomes an instance of MarkupInheritanceResolver$TransparentWebMarkupContainer and getModel returns null. Are there other circumstances where the component can be MarkupInheritanceResolver$TransparentWebMarkupContainer and it not be a page? igor.vaynberg wrote: > > sorry, but i dont really get what the problem is or why it matters > what component stringresourceloader gets. it simply traverses up the > hieararchy looking for .properties files > > -igor > -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16974123.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
sorry, but i dont really get what the problem is or why it matters what component stringresourceloader gets. it simply traverses up the hieararchy looking for .properties files -igor On Tue, Apr 29, 2008 at 4:55 PM, Ned Collyer <[EMAIL PROTECTED]> wrote: > > Do you know an elegant solution Igor? > > Detecting when the component IS a page - when something like key="foobar"/> is used in a page's markup, the component sent to the > StringResourceLoader is > MarkupInheritanceResolver$TransparentWebMarkupContainer and not Page. > > If the strings are resolved in java (ie, getString("foobar")) (according to > michael) > component instanceof Page == true > > if the strings are resolved in markup (ie, ) > component instanceof Page == false > > Rgds > > Ned > > > igor.vaynberg wrote: > > > > Page page=component.getPage() ? > > > > -igor > > > > -- > View this message in context: > http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16973039.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
Do you know an elegant solution Igor? Detecting when the component IS a page - when something like is used in a page's markup, the component sent to the StringResourceLoader is MarkupInheritanceResolver$TransparentWebMarkupContainer and not Page. If the strings are resolved in java (ie, getString("foobar")) (according to michael) component instanceof Page == true if the strings are resolved in markup (ie, ) component instanceof Page == false Rgds Ned igor.vaynberg wrote: > > Page page=component.getPage() ? > > -igor > -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16973039.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
Page page=component.getPage() ? -igor On Tue, Apr 29, 2008 at 3:53 AM, Michael Sparer <[EMAIL PROTECTED]> wrote: > > well one (as said ugly ;-)) way that comes to my mind is to ask if > component.getParent().getParent() instanceof Page (that should also work if > you use nested subpages). > > regards, > Michael > > > > you could check if it's a transparentwebmarkupcontainer with instanceof. > > > > Ned Collyer wrote: > > > > I basically want the components Model. > > > > It's legitimate for it to be null. So, if I can see which component is a > > page, then i can easily call the "getPage().getModel()" > > > > Of course if it's TransparentWebMarkupContainer then getModel returns null > > even if the page has a model set. > > > > It appears to work with panels, just not page. > > > > Are there other conditions that will cause the component to come through > > as > > TransparentWebMarkupContainer? How can I determine it's a page :). Ugly > > hacks are not something i enjoy/advocate using. > > > > On Tue, Apr 29, 2008 at 6:56 PM, Michael Sparer <[EMAIL PROTECTED]> > > wrote: > > > >> > >> yepp, then the TransparentWebMarkupContainer gets passed in. And you're > >> right, it's gonna be a filthy hack if you try to find out if its a Page. > >> Unfortunately I've got no further suggestions but it'd be interesting to > >> know why you want to distinguish between pages and other components > >> anyway > >> ... > >> > >> regards, > >> Michael > >> > >> > > > > > > > > - > Michael Sparer > http://talk-on-tech.blogspot.com > -- > View this message in context: > http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16957722.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
I did an elegantish... workaround. - the page instantiates a panel - the panel has the model. Basically my pages defer almost everything to panels - and I guess it also aids in their reuse/embeddability. I'm quite familiar with instanceof thanks ;) Michael Sparer wrote: > > well one (as said ugly ;-)) way that comes to my mind is to ask if > component.getParent().getParent() instanceof Page (that should also work > if you use nested subpages). > > regards, > Michael > -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16957861.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
well one (as said ugly ;-)) way that comes to my mind is to ask if component.getParent().getParent() instanceof Page (that should also work if you use nested subpages). regards, Michael you could check if it's a transparentwebmarkupcontainer with instanceof. Ned Collyer wrote: > > I basically want the components Model. > > It's legitimate for it to be null. So, if I can see which component is a > page, then i can easily call the "getPage().getModel()" > > Of course if it's TransparentWebMarkupContainer then getModel returns null > even if the page has a model set. > > It appears to work with panels, just not page. > > Are there other conditions that will cause the component to come through > as > TransparentWebMarkupContainer? How can I determine it's a page :). Ugly > hacks are not something i enjoy/advocate using. > > On Tue, Apr 29, 2008 at 6:56 PM, Michael Sparer <[EMAIL PROTECTED]> > wrote: > >> >> yepp, then the TransparentWebMarkupContainer gets passed in. And you're >> right, it's gonna be a filthy hack if you try to find out if its a Page. >> Unfortunately I've got no further suggestions but it'd be interesting to >> know why you want to distinguish between pages and other components >> anyway >> ... >> >> regards, >> Michael >> >> > > - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16957722.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
I basically want the components Model. It's legitimate for it to be null. So, if I can see which component is a page, then i can easily call the "getPage().getModel()" Of course if it's TransparentWebMarkupContainer then getModel returns null even if the page has a model set. It appears to work with panels, just not page. Are there other conditions that will cause the component to come through as TransparentWebMarkupContainer? How can I determine it's a page :). Ugly hacks are not something i enjoy/advocate using. On Tue, Apr 29, 2008 at 6:56 PM, Michael Sparer <[EMAIL PROTECTED]> wrote: > > yepp, then the TransparentWebMarkupContainer gets passed in. And you're > right, it's gonna be a filthy hack if you try to find out if its a Page. > Unfortunately I've got no further suggestions but it'd be interesting to > know why you want to distinguish between pages and other components anyway > ... > > regards, > Michael > >
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
yepp, then the TransparentWebMarkupContainer gets passed in. And you're right, it's gonna be a filthy hack if you try to find out if its a Page. Unfortunately I've got no further suggestions but it'd be interesting to know why you want to distinguish between pages and other components anyway ... regards, Michael Ned Collyer wrote: > > Thanks for your reply, > > Maybe it's because I am using a in the > markup?! > > There isn't really any code to show. I put the wicket:message into the > page, then i check the params coming in to the method. > > I'll have a bit more of a play I think, but I would be interested in what > your results are with the > > Rgds > > Ned > > > Michael Sparer wrote: >> >> I just subclassed ComponentStringResourceLoader and tried calling >> getString("foobar"); from a page (that extends another page). There >> instanceof Page returns true. Maybe it'd be helpful to see some code (and >> your usecase 'cause maybe there's another way to do it). >> >> regards >> Michael >> > > - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16955747.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
Thanks for your reply, Maybe it's because I am using a in the markup?! There isn't really any code to show. I put the wicket:message into the page, then i check the params coming in to the method. I'll have a bit more of a play I think, but I would be interested in what your results are with the Rgds Ned Michael Sparer wrote: > > I just subclassed ComponentStringResourceLoader and tried calling > getString("foobar"); from a page (that extends another page). There > instanceof Page returns true. Maybe it'd be helpful to see some code (and > your usecase 'cause maybe there's another way to do it). > > regards > Michael > -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16955733.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
I just subclassed ComponentStringResourceLoader and tried calling getString("foobar"); from a page (that extends another page). There instanceof Page returns true. Maybe it'd be helpful to see some code (and your usecase 'cause maybe there's another way to do it). regards Michael Ned Collyer wrote: > > > Michael Sparer wrote: >> >> comp instanceof Page ? >> >> or am I misunderstanding somethin? >> > comp instanceof Page == false > > comp is instance of > MarkupInheritanceResolver$TransparentWebMarkupContainer > > I need to get the model out of the page - if its a page. Unfortunatly > "getModel" returns null > > I'm not sure if there are other circumstances where > MarkupInheritanceResolver$TransparentWebMarkupContainer could match the > component. > > I can call comp.getPage() or comp.getParent() a few times - but I need to > determine that it IS a page - because if it is not, then I handle it > differently. > - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16953713.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
Michael Sparer wrote: > > comp instanceof Page ? > > or am I misunderstanding somethin? > comp instanceof Page == false comp is instance of MarkupInheritanceResolver$TransparentWebMarkupContainer I need to get the model out of the page - if its a page. Unfortunatly "getModel" returns null I'm not sure if there are other circumstances where MarkupInheritanceResolver$TransparentWebMarkupContainer could match the component. I can call comp.getPage() or comp.getParent() a few times - but I need to determine that it IS a page - because if it is not, then I handle it differently. -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16945995.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]
Re: loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
comp instanceof Page ? or am I misunderstanding somethin? Ned Collyer wrote: > > Hi, > > I've written my own class that extends ComponentStringResourceLoader (i > might change it to extend some other class) > > At any rate, when loadStringResource(Component component, String key) is > called, and the component is a panel I can call "getModel" and retrieve > the model. > > When the component is a Page, it comes in as > MarkupInheritanceResolver$TransparentWebMarkupContainer - and getModel > returns null (even if the page has had the model set). > > So... how do I determine is the component is a page? - what is the > condition I should check? > - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16938536.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]
loadStringResource(Component component, String key) - correct method to check if the component IS a Page?
Hi, I've written my own class that extends ComponentStringResourceLoader (i might change it to extend some other class) At any rate, when loadStringResource(Component component, String key) is called, and the component is a panel I can call "getModel" and retrieve the model. When the component is a Page, it comes in as MarkupInheritanceResolver$TransparentWebMarkupContainer - and getModel returns null (even if the page has had the model set). So... how do I determine is the component is a page? - what is the condition I should check? -- View this message in context: http://www.nabble.com/loadStringResource%28Component-component%2C-String-key%29---correct-method-to-check-if-the-component-IS-a-Page--tp16930303p16930303.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]