On Tue, 2020-07-14 at 18:44 +0300, Martin Grigorov wrote: > Hi again, > > On Tue, Jul 14, 2020 at 10:46 AM Martin Grigorov <mgrigo...@apache.org> > wrote: > > > Hi, > > > > On Tue, Jul 14, 2020 at 10:10 AM Alberto <abros...@inogs.it> wrote: > > > > > Hello, > > > > > > I have a StringResourceModel in a parent abstract class of all pages. > > > > > > IModel<String> titleModel = new StringResourceModel("contentTitle", > > > getModel()); > > > > > > where "contentTitle" is a property specified for every child page in > > > specific > > > property files and getModel() returns a chain of a CompoundPropertyModel > > > and a > > > LoadableDetachableModel. > > > > > > If I simple use it, it works: > > > > > > add(new Label("pageTitle", titleModel)); > > > > > > > > > But if I apply a lambda expression to it (for example): > > > > > > add(new Label("pageTitle", titleModel.map(String::trim))); > > > > > > I have an exception.: > > > > > > java.util.MissingResourceException: Unable to find property: > > > 'contentTitle'. > > > Locale: null, style: null > > > > > > > > > Why it happens? > > > > > > > Because .map() returns a new IModel that does not > > implement IComponentAssignedModel and Wicket cannot find the property in > > the visible resource bundles. > > I.e. your properties are in MyPage.properties and Wicket does not look > > into them because the model does not know the Component it is assigned to. > > If the property is in MyApplication.properties then it will work, because > > this is not related to specific Component. > > > > Please file a ticket in JIRA. I think this could be improved. > > > > I just took a look at your ticket ( > https://issues.apache.org/jira/browse/WICKET-6801) and it is not exactly as > I thought it is. > > add(new Label("pageTitle", titleModel.map(String::trim))); > > at this line titleModel doesn't yet know its component because at the time > IModel#map() is called titleModel is not yet added as a model to the Label > and thus IComponentAssignedModel is not yet involved. > The new IModel returned by .map() does not implement > IComponentAssignedModel and thus it cannot delegate the > #wrapOnAssignment(Component) call. > > The good news for you is that you can use IModel<String> titleModel = new > StringResourceModel("contentTitle", *this*, getModel()); to solve your > problem. By passing 'this' as parameter you tell StringResourceModel to use > it instead of depending on > the Component it is added to (the Label in this case). > > I'll see what I can do for WICKET-6801! > >
Yes, you are right. I should have read better the documentation. Sorry for that. Thanks A > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > 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