wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Grigorov <mgrigo...@apache.org>
Subject Re: mounting resources "on the fly"
Date Fri, 08 Feb 2013 08:42:09 GMT
What is your reason to use a mounted resource ?
- nice looking url ?
- avoid synchronization on the page

If these two are not hard requirements then you can use
IResourceListener/IBehaviorListener, so each component will have its own
"mount point".


On Fri, Feb 8, 2013 at 9:37 AM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> Martin.
>
> Thanks for your answer!
>
> Yes, that approach would be a cleaner. What I was hoping was to be able to
> do the mounting cleanly inside component... But then I would have to keep a
> constant with "/some/path"... which would amount the the same kind of non
> DRYness.
>
> On Thu, Feb 7, 2013 at 5:18 PM, Martin Grigorov <mgrigorov@apache.org
> >wrote:
>
> > Hi Ernesto,
> >
> > How about:
> >
> > class Select2JsonRef extends
> JsonResourceReference<CategoryTranslation>() {
> >  private static final long serialVersionUID = 1L;
> >
> > @Override
> > protected ChoiceProvider<CategoryTranslation> getChoiceProvider() {
> > return CategoriesTextChoiceProvider.getInstance();
> > }
> > });
> >
> > app.mountResource("/some/path", new Select2JsonRef());
> >
> > and later:
> > Select2MultiChoice<CategoryTranslation> c = new
> > Select2MultiChoice<CategoryTranslation>("categories", new
> > PropertyModel<Collection<CategoryTranslation>>(searchBean,
> "translations"),
> > CategoriesTextChoiceProvider.getInstance());
> > c.getSettings().setStateless(true);
> > c.getSettings().setMountPath(urlFor(new Select2JsonRef())));
> > form.add(c);
> >
> >
> >
> > On Thu, Feb 7, 2013 at 3:16 PM, Ernesto Reinaldo Barreiro <
> > reiern70@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > While implementing "support for stateless JSON servicing"
> > >
> > >
> > >
> >
> https://github.com/reiern70/wicket-select2/commit/018dbffc581003560bc021e83c1ea457e8b68acd
> > >
> > > I came across following issue.
> > >
> > >
> > > 1- I have to mount a JSON serving JsonResourceReference on
> > > Appliction#init()
> > >
> > > mountResource(CATEGORIES_JSON, new
> > > JsonResourceReference<CategoryTranslation>() {
> > >  private static final long serialVersionUID = 1L;
> > >
> > > @Override
> > > protected ChoiceProvider<CategoryTranslation> getChoiceProvider() {
> > > return CategoriesTextChoiceProvider.getInstance();
> > > }
> > > });
> > >
> > >
> > > and later on
> > >
> > > 2- On defining the select2 I have to pass the the mount path
> > > CATEGORIES_JSON as
> > >
> > > Select2MultiChoice<CategoryTranslation> c = new
> > > Select2MultiChoice<CategoryTranslation>("categories", new
> > > PropertyModel<Collection<CategoryTranslation>>(searchBean,
> > "translations"),
> > > CategoriesTextChoiceProvider.getInstance());
> > > c.getSettings().setStateless(true);
> > > c.getSettings().setMountPath(Application.CATEGORIES_JSON);
> > > form.add(c);
> > >
> > > So, thy is not very DRY.
> > >
> > > My idea then was mounting JsonResourceReference "dynamically" as a
> > > Select2MultiChoice is being created. E.g by writing
> > > AbstractSelect2Choice#onConfigure
> > >
> > >
> > >
> >
> https://github.com/reiern70/wicket-select2/blob/018dbffc581003560bc021e83c1ea457e8b68acd/wicket-select2/src/main/java/com/vaynberg/wicket/select2/AbstractSelect2Choice.java#L185
> > >
> > > as
> > >
> > >  protected void onConfigure() {
> > > super.onConfigure();
> > > if(getSettings().isStateless()) {
> > > if(Strings.isEmpty(getSettings().getMountPath())) {
> > >   throw new IllegalStateException("Select2 in stateless mode should
> > specify
> > > a mountPath");
> > > }
> > > getSettings().getAjax().setUrl(getSettings().getMountPath());
> > >
> > > WebApplication.get().mountResource(getSettings().getMountPath(), new
> > > JsonResourceReference<T>() {
> > >  @Override
> > > protected ChoiceProvider<T> getChoiceProvider() {
> > > return AbstractSelect2Choice.this.getProvider();
> > > }
> > > });
> > > } else {
> > > getSettings().getAjax().setUrl(urlFor(IResourceListener.INTERFACE,
> > null));
> > > }
> > >     }
> > >
> > > So that compenent registers a recource when it needs it. But with this
> > find
> > > two possible problems...
> > >
> > > 1- Thread safety when mounting the JsonResourceReference...
> > > 2- There does not seem to be a way to ask if something has been mounted
> > > under a given path
> > >
> > > Is there a nice/clean way to make the above working? So, that component
> > is
> > > more more "DRY".
> > >
> > > --
> > > Regards - Ernesto Reinaldo Barreiro
> > >
> >
> >
> >
> > --
> > 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>
>



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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message