Re: Lambda expressions on StringResourceModel does not work

2020-07-14 Thread Alberto
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 
> wrote:
> 
> > Hi,
> > 
> > On Tue, Jul 14, 2020 at 10:10 AM Alberto  wrote:
> > 
> > > Hello,
> > > 
> > > I have a StringResourceModel in a parent abstract class of all pages.
> > > 
> > > IModel 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 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



Re: Lambda expressions on StringResourceModel does not work

2020-07-14 Thread Martin Grigorov
Hi again,

On Tue, Jul 14, 2020 at 10:46 AM Martin Grigorov 
wrote:

> Hi,
>
> On Tue, Jul 14, 2020 at 10:10 AM Alberto  wrote:
>
>>
>> Hello,
>>
>> I have a StringResourceModel in a parent abstract class of all pages.
>>
>> IModel 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 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!


>
>
>>
>>
>>
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>


Re: Change pageId Parameter structure

2020-07-14 Thread Bas Gooren
Hi Ravi,

Instead of writing custom implementations of existing mappers, maybe there
is an alternative approach:

Wrap the application’s root request mapper with a decorator, and translate
the parameter in question.
So as the last call in your application’s init method, write:

setRootRequestMapper(new PageComponentInfoRewritingDecorator(
getRootRequestMapper()));

So for incoming requests, remove QueryParameter “pageId” and prepend a new
QueryParameter at index 0 (name=“”, value=(name of original param))
You can clone the request with a new url, see Request#cloneWithUrl
Pass the cloned request on to the delegate/original compound mapper.

For generated urls, check for a QueryParameter at position 0 with an empty
value.
If it’s present, replace it with a new QueryParameter (name=(value of
original param), value=“”)

This does couple you to wicket internals (so write some unit tests!), but
also allows you to solve this in 1 location instead of many locations.

Source: I have written many such custom mappers and mapper decorators, e.g.
for localization of urls.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 14 juli 2020 bij 14:54:07, Ravi Knox (ravi.k...@intellinet.de) schreef:

Hi Martin,



that was a good starting point, thank you.

I had to overwrite basically all Mappers within the SystemMapper and mounts
(since they create mappers themselves).



The following Methods I had to overwrite:

- #encodePageComponentInfo - for adding the custom page param

- #getPageComponentInfo - for reading the custom page param as
component id

- #extractPageParameters - to remove the custom page param from the
parameter list



Does that make sense to you or did I miss something?



Thanks,



Ravi





Hi Ravi,



The logic you look for is at

https://github.com/apache/wicket/blob/267fb06eec31e8e530fb5f0a4f691a0782e3d5
b8/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractC

omponentMapper.java#L79

It is called by:

https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/a
pache/wicket/core/request/mapper/PageInstanceMapper.java#L133



You will need to use custom version of PageInstanceMapper that overrides

protected void encodePageComponentInfo(Url url, PageComponentInfo info)



On Mon, Jul 13, 2020 at 8:40 AM Ravi Knox  wrote:



> Hi all,

>

>

>

> my client has a website, where he includes our Wicket application (Wicket

> 8.3.0) via JQuery.load() in his template.

>

> Because of a Reverse-Proxy, he has to whitelist all PageParameters.

>

>

>

> To keep it short;

>

> We need to change the pageId Parameter to something like

> "myapp.com/homepage?pageId=1".

>

>

>

> After reading source code and googleing I couldn't find a way to do this.

>

> Is it even possible? If so, where would be the place to look for?

>

>

>

> Thanks for any hints,

>

>

>

> Ravi

>

>





Quoted from:

http://apache-wicket.1842946.n4.nabble.com/Change-pageId-Parameter-structure
-tp4684229p4684233.html


Re: Change pageId Parameter structure

2020-07-14 Thread Martin Grigorov
On Tue, Jul 14, 2020 at 3:54 PM Ravi Knox  wrote:

> Hi Martin,
>
>
>
> that was a good starting point, thank you.
>
> I had to overwrite basically all Mappers within the SystemMapper and mounts
> (since they create mappers themselves).
>
>
>
> The following Methods I had to overwrite:
>
> -#encodePageComponentInfo - for adding the custom page param
>
> -#getPageComponentInfo - for reading the custom page param as
> component id
>
> -#extractPageParameters - to remove the custom page param from the
> parameter list
>
>
>
> Does that make sense to you or did I miss something?
>

I didn't expect that you will need to overwrite all mappers but I haven't
tried myself such thing so I am not fully certain how many changes are
needed.
I've expected that you will need MyPageInstanceMapper registered and this
one is either consulted before the original one or produces a better
compatibility score.


>
>
>
> Thanks,
>
>
>
> Ravi
>
>
>
> 
>
> Hi Ravi,
>
>
>
> The logic you look for is at
>
>
> https://github.com/apache/wicket/blob/267fb06eec31e8e530fb5f0a4f691a0782e3d5
>
> b8/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractC
> omponentMapper.java#L79
> 
>
> It is called by:
>
>
> https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/a
> pache/wicket/core/request/mapper/PageInstanceMapper.java#L133
> 
>
>
>
> You will need to use custom version of PageInstanceMapper that overrides
>
> protected void encodePageComponentInfo(Url url, PageComponentInfo info)
>
>
>
> On Mon, Jul 13, 2020 at 8:40 AM Ravi Knox  wrote:
>
>
>
> > Hi all,
>
> >
>
> >
>
> >
>
> > my client has a website, where he includes our Wicket application (Wicket
>
> > 8.3.0) via JQuery.load() in his template.
>
> >
>
> > Because of a Reverse-Proxy, he has to whitelist all PageParameters.
>
> >
>
> >
>
> >
>
> > To keep it short;
>
> >
>
> > We need to change the pageId Parameter to something like
>
> > "myapp.com/homepage?pageId=1".
>
> >
>
> >
>
> >
>
> > After reading source code and googleing I couldn't find a way to do this.
>
> >
>
> > Is it even possible? If so, where would be the place to look for?
>
> >
>
> >
>
> >
>
> > Thanks for any hints,
>
> >
>
> >
>
> >
>
> > Ravi
>
> >
>
> >
>
>
>
> 
>
> Quoted from:
>
>
> http://apache-wicket.1842946.n4.nabble.com/Change-pageId-Parameter-structure
> -tp4684229p4684233.html
> 
>
>


Re: Change pageId Parameter structure

2020-07-14 Thread Ravi Knox
Hi Martin,

 

that was a good starting point, thank you. 

I had to overwrite basically all Mappers within the SystemMapper and mounts
(since they create mappers themselves).

 

The following Methods I had to overwrite:

-#encodePageComponentInfo - for adding the custom page param

-#getPageComponentInfo - for reading the custom page param as
component id

-#extractPageParameters - to remove the custom page param from the
parameter list

 

Does that make sense to you or did I miss something?

 

Thanks,

 

Ravi

 



Hi Ravi,

 

The logic you look for is at

https://github.com/apache/wicket/blob/267fb06eec31e8e530fb5f0a4f691a0782e3d5
b8/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractC
omponentMapper.java#L79

It is called by:

https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/a
pache/wicket/core/request/mapper/PageInstanceMapper.java#L133

 

You will need to use custom version of PageInstanceMapper that overrides

protected void encodePageComponentInfo(Url url, PageComponentInfo info)

 

On Mon, Jul 13, 2020 at 8:40 AM Ravi Knox  wrote:

 

> Hi all,

> 

> 

> 

> my client has a website, where he includes our Wicket application (Wicket

> 8.3.0) via JQuery.load() in his template.

> 

> Because of a Reverse-Proxy, he has to whitelist all PageParameters.

> 

> 

> 

> To keep it short;

> 

> We need to change the pageId Parameter to something like

> "myapp.com/homepage?pageId=1".

> 

> 

> 

> After reading source code and googleing I couldn't find a way to do this.

> 

> Is it even possible? If so, where would be the place to look for?

> 

> 

> 

> Thanks for any hints,

> 

> 

> 

> Ravi

> 

> 

 



Quoted from: 

http://apache-wicket.1842946.n4.nabble.com/Change-pageId-Parameter-structure
-tp4684229p4684233.html



Re: Lambda expressions on StringResourceModel does not work

2020-07-14 Thread Martin Grigorov
Hi,

On Tue, Jul 14, 2020 at 10:10 AM Alberto  wrote:

>
> Hello,
>
> I have a StringResourceModel in a parent abstract class of all pages.
>
> IModel 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.


>
>
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Lambda expressions on StringResourceModel does not work

2020-07-14 Thread Alberto


Hello,

I have a StringResourceModel in a parent abstract class of all pages.

IModel 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?




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org