You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martijn Dashorst <ma...@gmail.com> on 2013/01/21 08:14:18 UTC

Registering converters for PageParameters

We have a really nice type safe API but the thing that strikes me as
odd is that AFIAK we don't have converters from PageParameters to
objects and back. Now it probably is not easy to get it right, but
what would be not too crazy is to be able to register a
PersonPageParametersConverter such that a PersonPage taking a Person
as a constructor parameter would be considered bookmarkable.

Perhaps this would be good to have as an annotation?

Martijn

-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

Re: Registering converters for PageParameters

Posted by Guillaume Smet <gu...@gmail.com>.
Hi Martijn,

On Mon, Jan 21, 2013 at 8:14 AM, Martijn Dashorst
<ma...@gmail.com> wrote:
> We have a really nice type safe API but the thing that strikes me as
> odd is that AFIAK we don't have converters from PageParameters to
> objects and back. Now it probably is not easy to get it right, but
> what would be not too crazy is to be able to register a
> PersonPageParametersConverter such that a PersonPage taking a Person
> as a constructor parameter would be considered bookmarkable.
>
> Perhaps this would be good to have as an annotation?

It's a nice idea.

I recommend to take a look at how Spring MVC solved this problem in
the @Controller layer as it's really nicely done and flexible.

See especially the @PathVariable annotation and the ConversionService
(and the converters).

-- 
Guillaume

Re: Registering converters for PageParameters

Posted by Michael Mosmann <mi...@mosmann.de>.
Am 21.01.2013 08:14, schrieb Martijn Dashorst:

+1

> We have a really nice type safe API but the thing that strikes me as
> odd is that AFIAK we don't have converters from PageParameters to
> objects and back. Now it probably is not easy to get it right, but
> what would be not too crazy is to be able to register a
> PersonPageParametersConverter such that a PersonPage taking a Person
> as a constructor parameter would be considered bookmarkable.
>
> Perhaps this would be good to have as an annotation?
>
> Martijn
>


Re: Registering converters for PageParameters

Posted by Michael Mosmann <mi...@mosmann.de>.
Am 21.01.2013 09:55, schrieb Martin Grigorov:
> What would such converter actually do? I guess the encoder for an employee
> it will generate PageParameters with id->empId (assuming you want a nice
> looking url which will encode 'employee' as Url segment, e.g.
> /company/employee/34).
> Later the decoder will do what ? Will make a request to the DB to load all
> the details for the Employee ? I think it should provide a model -
> MyPage(IModel<Employee>), e.g. LDM<Employee>, and make the request to the
> DB as late as possible. But we already have this constructor in (Web)Page
> API (org.apache.wicket.Page#Page(IModel))
>
I think more of a PageParameter<->Bean converter .. no DB access.

I did this before, but more this way:

public MyPage(PageParameters p) {
     MyBean state=MyBean.from(p);

     // some code
     MyBean newState=state.withId(nextEntryId);

    add(new BookmarkableStateLink("link",MyPage.class,newState));
}


Re: Registering converters for PageParameters

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi,

On Mon, Jan 21, 2013 at 9:55 AM, Martin Grigorov <mg...@apache.org>wrote:

> This is not available out of the box but it is possible to do it without
> any changes in wicket-core.
> Just provide your own impl of IPageFactory interface. Use
> DefaultPageFactory as inspiration.
>
> Here are the problems that I see with it:
> - it will use reflection to find all available constructors in a page
> -- needs a cache to not read class metadata more than once per page
> - needs a logic to decide what to do if  there are more than one converters
> which would create a POJO for the same parameters
>

In such case maybe converter can be specified on annotation?


> - FormComponents' IConverter currently has a unresolved problem - it
> doesn't support base type. E.g. if there is registered converter
> for Employee but a Page has constructor with Person (which is base for
> Employee) parameter should the converter be used ?
>
> What would such converter actually do? I guess the encoder for an employee
> it will generate PageParameters with id->empId (assuming you want a nice
> looking url which will encode 'employee' as Url segment, e.g.
> /company/employee/34).



Later the decoder will do what ? Will make a request to the DB to load all
> the details for the Employee ? I think it should provide a model -
> MyPage(IModel<Employee>), e.g. LDM<Employee>, and make the request to the
> DB as late as possible. But we already have this constructor in (Web)Page
> API (org.apache.wicket.Page#Page(IModel))
>
> A converter could be an interface and have different implementations that
can be chained/combined defined at annotation. E.g. One implementation that
extracts a POJO out of the request parameters using reflection to populate
some fields,  combined with one that fetches the rest of entity from data
for database... Also once bean is constructed users could do whatever they
want with the supplied POJO. Maybe this could be used to provide also an
IModel<Bean> by combining converter?


>
>
> On Mon, Jan 21, 2013 at 9:14 AM, Martijn Dashorst <
> martijn.dashorst@gmail.com> wrote:
>
> > We have a really nice type safe API but the thing that strikes me as
> > odd is that AFIAK we don't have converters from PageParameters to
> > objects and back. Now it probably is not easy to get it right, but
> > what would be not too crazy is to be able to register a
> > PersonPageParametersConverter such that a PersonPage taking a Person
> > as a constructor parameter would be considered bookmarkable.
> >
> > Perhaps this would be good to have as an annotation?
> >
> > Martijn
> >
> > --
> > Become a Wicket expert, learn from the best: http://wicketinaction.com
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>
>



-- 
Regards - Ernesto Reinaldo Barreiro
Antilia Soft
http://antiliasoft.com/ <http://antiliasoft.com/antilia>

Re: Registering converters for PageParameters

Posted by Martin Grigorov <mg...@apache.org>.
This is not available out of the box but it is possible to do it without
any changes in wicket-core.
Just provide your own impl of IPageFactory interface. Use
DefaultPageFactory as inspiration.

Here are the problems that I see with it:
- it will use reflection to find all available constructors in a page
-- needs a cache to not read class metadata more than once per page
- needs a logic to decide what to do if  there are more than one converters
which would create a POJO for the same parameters
- FormComponents' IConverter currently has a unresolved problem - it
doesn't support base type. E.g. if there is registered converter
for Employee but a Page has constructor with Person (which is base for
Employee) parameter should the converter be used ?

What would such converter actually do? I guess the encoder for an employee
it will generate PageParameters with id->empId (assuming you want a nice
looking url which will encode 'employee' as Url segment, e.g.
/company/employee/34).
Later the decoder will do what ? Will make a request to the DB to load all
the details for the Employee ? I think it should provide a model -
MyPage(IModel<Employee>), e.g. LDM<Employee>, and make the request to the
DB as late as possible. But we already have this constructor in (Web)Page
API (org.apache.wicket.Page#Page(IModel))



On Mon, Jan 21, 2013 at 9:14 AM, Martijn Dashorst <
martijn.dashorst@gmail.com> wrote:

> We have a really nice type safe API but the thing that strikes me as
> odd is that AFIAK we don't have converters from PageParameters to
> objects and back. Now it probably is not easy to get it right, but
> what would be not too crazy is to be able to register a
> PersonPageParametersConverter such that a PersonPage taking a Person
> as a constructor parameter would be considered bookmarkable.
>
> Perhaps this would be good to have as an annotation?
>
> Martijn
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>