[ 
https://issues.apache.org/jira/browse/WICKET-1213?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Johan Compagner updated WICKET-1213:
------------------------------------

          Description: 
In my wicket programming experience so far I always didn't feel quite 
comfortable with the ajax part.

I had some issues in particular with these as an example:

- "Always include a common feedback panel from my template page"
   --> add 'target.addComponent(feedbackPanel)' just _everywhere_ (very 
cumbersome and not elegant at all)

- add a listener using AjaxRequestTarget#addListener
  --> not possible without subclassing the request cycle (which is *yuk* if you 
ask me) to catch the short moment in between AjaxRequestTarget is instantiated 
and AjaxRequestTarget#onRespond() is called

- automatically set focus on the first form component with errors
   --> add bulky code into all onSubmit() and onError() to check for errrors 
and call AjaxRequestTarget#setFocus

- add some common function like AjaxRequestTarget#yellowFade(FormComponent)
  --> have some utility method and call it like this: 
AjaxUtil.yellowFade(target) -- not nice as functionality like this should 
really belong to the request target

I found that all these issues can be solved very elegantly if you could just 
catch the moment where AjaxRequestTarget is instantiated.

I attached a very little patch (!) which solves all that issues and makes ajax 
just a lot more powerful inside wicket *imho*

also, it will not break current code but is just an enhancement you will not 
notice unless you need it.

  was:
In my wicket programming life I always had some trouble with the ajax part when 
wanting stuff like this:

- "Always update a common feedback panel from my template page"
   --> add 'target.addComponent(feedbackPanel)' just _everywhere_ (very 
cumbersome and not elegant at all)

- add a listener using AjaxRequestTarget#addListener
  --> not quite possible without subclassing the request cycle (which is *yuk* 
if you ask me) to catch the short moment in between AjaxRequestTarget is 
instantiated and IRequestTarget#onRespond() is called

- automatically set focus on the first form component with errors
   --> add bulky code into all onError() to check for the proper component and 
call AjaxRequestTarget#setFocus

- add some common function like 
AjaxRequestTarget#yellowFadeEffect(FormComponent)
  --> have some utility method and call it like this: 
AjaxUtil.yellowFade(target) -- not nice as functionality like this should 
really belong to the ajax target which represents the ajax request / response.

I found that all these issues can be solved very elegantly if you could just 
catch the moment where AjaxRequestTarget is instantiated.

I attached a very little patch (!) which enables you to

- subclass
- add listeners to

the AjaxRequestTarget

In AbstractDefaultAjaxBehavior:281

    public final void onRequest()
    {
        AjaxRequestTarget target = new 
AjaxRequestTarget(getComponent().getPage()); // *******
        RequestCycle.get().setRequestTarget(target);
        respond(target)
    }

is changed to

    public final void onRequest()
    {
        AjaxRequestTarget target = 
getComponent().getPage().newAjaxRequestTarget(); // *******
        RequestCycle.get().setRequestTarget(target);
        respond(target);
    }

org.apache.wicket.Page will have an additional method:

  public AjaxRequestTarget newAjaxRequestTarget()
  {
    return new AjaxRequestTarget(this);
  }
}

so by overriding newAjaxRequestTarget in your page you could customize or 
subclass the ajax response very easily

also, this will not break current code but is just an enhancement you will not 
notice unless you need it.

    Affects Version/s: 1.3.0-rc1
        Fix Version/s: 1.4.0-alpha
             Assignee: Matej Knopp

please clean up your patch if possible, its a bit messy with the javadoc 
changes (but maybe this is because of our own formatter and the page isn't 
formatted right)

But i am against this method on page. That is really the wrong place. 
Page.newAjaxRequestTarget()
what does page has to do with request processing.. Page is just a component.
Or do you really want to have all kinds of different AjaxRequestTargets for all 
kinds of differnent pages?
But still i don't like it to have it on that place for example the 
PageRequestTarget is also not made inside the page.
When quickly looking at it i think the best way to do it is instead of this

                     public final void onRequest()
        {
                AjaxRequestTarget target = new 
AjaxRequestTarget(getComponent().getPage());
                RequestCycle.get().setRequestTarget(target);
                respond(target);
        }

this

                     public final void onRequest()
        {
                                          RequestCycle rc = RequestCycle.get();
                AjaxRequestTarget target = 
rc.newAjaxRequestTarget(getComponent().getPage());
                RequestCycle.get().setRequestTarget(target);
                respond(target);
        }

and then you can do anything you want, You can ask the page for its ajax 
request target if you want or create a default one (call super) or create a 
none standaard global one.



> enable subclassing of AjaxRequestTarget
> ---------------------------------------
>
>                 Key: WICKET-1213
>                 URL: https://issues.apache.org/jira/browse/WICKET-1213
>             Project: Wicket
>          Issue Type: Wish
>          Components: wicket
>    Affects Versions: 1.3.0-rc1
>            Reporter: Peter Ertl
>            Assignee: Matej Knopp
>             Fix For: 1.4.0-alpha
>
>         Attachments: AjaxRequestTarget_with_subclassing.patch
>
>
> In my wicket programming experience so far I always didn't feel quite 
> comfortable with the ajax part.
> I had some issues in particular with these as an example:
> - "Always include a common feedback panel from my template page"
>    --> add 'target.addComponent(feedbackPanel)' just _everywhere_ (very 
> cumbersome and not elegant at all)
> - add a listener using AjaxRequestTarget#addListener
>   --> not possible without subclassing the request cycle (which is *yuk* if 
> you ask me) to catch the short moment in between AjaxRequestTarget is 
> instantiated and AjaxRequestTarget#onRespond() is called
> - automatically set focus on the first form component with errors
>    --> add bulky code into all onSubmit() and onError() to check for errrors 
> and call AjaxRequestTarget#setFocus
> - add some common function like AjaxRequestTarget#yellowFade(FormComponent)
>   --> have some utility method and call it like this: 
> AjaxUtil.yellowFade(target) -- not nice as functionality like this should 
> really belong to the request target
> I found that all these issues can be solved very elegantly if you could just 
> catch the moment where AjaxRequestTarget is instantiated.
> I attached a very little patch (!) which solves all that issues and makes 
> ajax just a lot more powerful inside wicket *imho*
> also, it will not break current code but is just an enhancement you will not 
> notice unless you need it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to