You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Joachim Schrod <js...@acm.org> on 2022/05/31 00:12:54 UTC

One button in a form shall show result in new tab

Hi,

I'm tasked with upgrading an application from Wicket 7 to Wicket 9.

There is one class with a heavy code smell: it relies on a Wicket
internal realization. (Which promptly doesn't work any more in Wicket
9...) This email is part of my search for a better realization method.

The use case:
 -- There is a form with lots of submit buttons.
 -- One button realizes a "show as pdf" functionality.
     -- The PDF shall be shown in a new tab.
     -- It shall be possible to use the button while still working on
        the form. This is a form submit -- the PDF shall show the then
        current content of the page. (Validation is not an issue in
        this case, the submit and form processing will succeed.)
 -- After showing a PDF representation of the form, it shall be
    possible to use the other buttons in this form, which are part of
    the HTML sequence of pages.

I cannot use Javascript popups, as too many browsers block them. (In
fact, my own developer browser blocks them. ;-)) So I need to have the
following functionality for this button:
 -- Before the submit, a target attribute "_blank" get's added to the
    form.
 -- The form is submittet, by this button. (I.e., its onSubmit() must
    be called.)
 -- Afterwards, the target attribute is deleted from the form.

The previous programmer in this project simply copied the Javascript
code for an AjaxSubmitLink from Wicket 7 and enriched it with
adding/deleting the form attribute. Not the smartest move, indeed; but
it was working all this time

I'm looking for best practice to achieve that functionality with the
available Wicket API. I.e., I want to prepend and append Javascript to
the Wicket-supplied submit functionality of a button or ajax submit
action. I have looked at Javadoc and source code of the following
classes (and their superclasses) and didn't found any hook/method
where I can achieve my desired result:
 -- AjaxRequestAttributes: No methods to prepend/append JS code.
 -- AjaxSubmitLink: No methods to manipulate the emmitted JS code.
 -- AjaxFormSubmitBehavior: No methods to manipulate the emmitted JS
    code.
 -- Button: has getOnClickScript(), but this is empty.
 -- AjaxButton: doesn't redefine getOnClickScript(), so no gain to be
    get here either.

FWIW: The application uses getCspSettings().blocking().disabled(). 
There's too much JS code in HTML that I don't want to touch in this
round of update; that's a step after the Wicket 9 migration. Thus,
currently I have no qualms to add JS code to HTML "onsubmit"
attributes if that's the way to go at the moment.

I'm looking for something like #prependJavaScript() and
#appendJavaScript() in AjaxRequestTarget -- but not in the response
handling, instead for the code that triggers the click event.

tl;dr: How can I specify JS code that's executed before and after a
(specific) button or ajax submit of a form?

Here's hoping for some tips,

	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org

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


Re: One button in a form shall show result in new tab

Posted by Joachim Schrod <js...@acm.org>.
Hi,

Martin Grigorov writes:
> 
> On Tue, May 31, 2022 at 6:50 AM Joachim Schrod <js...@acm.org> wrote:
> >
> > So I need to have the
> > following functionality for this button:
> >  -- Before the submit, a target attribute "_blank" get's added to the
> >     form.
> >  -- The form is submittet, by this button. (I.e., its onSubmit() must
> >     be called.)
> >  -- Afterwards, the target attribute is deleted from the form.
> >
> > I'm looking for best practice to achieve that functionality with the
> > available Wicket API. I.e., I want to prepend and append Javascript to
> > the Wicket-supplied submit functionality of a button or ajax submit
> > action. I have looked at Javadoc and source code of the following
> > classes (and their superclasses) and didn't found any hook/method
> > where I can achieve my desired result:
> >  -- AjaxRequestAttributes: No methods to prepend/append JS code.
> 
> Actually this is the one you need ^^
> atrts.getAjaxCallListeners().add(new
> AjaxCallListener().onBefore("...").onComplete("..."));
> 
> see also onBeforeSend() and onAfter()

Thanks a lot for this tip, it worked like a charm. I learned something
new about Wicket; that's always a good thing. :-)

When I did read "Listener" in the classe name, I associated it with
some callback or event hook on the server side -- seems, that I need
to pay more attention to the AJAX mechanisms, how they work.

Cheers,
	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org

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


Re: One button in a form shall show result in new tab

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Tue, May 31, 2022 at 6:50 AM Joachim Schrod <js...@acm.org> wrote:

>
> Hi,
>
> I'm tasked with upgrading an application from Wicket 7 to Wicket 9.
>
> There is one class with a heavy code smell: it relies on a Wicket
> internal realization. (Which promptly doesn't work any more in Wicket
> 9...) This email is part of my search for a better realization method.
>
> The use case:
>  -- There is a form with lots of submit buttons.
>  -- One button realizes a "show as pdf" functionality.
>      -- The PDF shall be shown in a new tab.
>      -- It shall be possible to use the button while still working on
>         the form. This is a form submit -- the PDF shall show the then
>         current content of the page. (Validation is not an issue in
>         this case, the submit and form processing will succeed.)
>  -- After showing a PDF representation of the form, it shall be
>     possible to use the other buttons in this form, which are part of
>     the HTML sequence of pages.
>
> I cannot use Javascript popups, as too many browsers block them. (In
> fact, my own developer browser blocks them. ;-)) So I need to have the
> following functionality for this button:
>  -- Before the submit, a target attribute "_blank" get's added to the
>     form.
>  -- The form is submittet, by this button. (I.e., its onSubmit() must
>     be called.)
>  -- Afterwards, the target attribute is deleted from the form.
>
> The previous programmer in this project simply copied the Javascript
> code for an AjaxSubmitLink from Wicket 7 and enriched it with
> adding/deleting the form attribute. Not the smartest move, indeed; but
> it was working all this time
>
> I'm looking for best practice to achieve that functionality with the
> available Wicket API. I.e., I want to prepend and append Javascript to
> the Wicket-supplied submit functionality of a button or ajax submit
> action. I have looked at Javadoc and source code of the following
> classes (and their superclasses) and didn't found any hook/method
> where I can achieve my desired result:
>  -- AjaxRequestAttributes: No methods to prepend/append JS code.
>

Actually this is the one you need ^^
atrts.getAjaxCallListeners().add(new
AjaxCallListener().onBefore("...").onComplete("..."));

see also onBeforeSend() and onAfter()



>  -- AjaxSubmitLink: No methods to manipulate the emmitted JS code.
>  -- AjaxFormSubmitBehavior: No methods to manipulate the emmitted JS
>     code.
>  -- Button: has getOnClickScript(), but this is empty.
>  -- AjaxButton: doesn't redefine getOnClickScript(), so no gain to be
>     get here either.
>
> FWIW: The application uses getCspSettings().blocking().disabled().
> There's too much JS code in HTML that I don't want to touch in this
> round of update; that's a step after the Wicket 9 migration. Thus,
> currently I have no qualms to add JS code to HTML "onsubmit"
> attributes if that's the way to go at the moment.
>
> I'm looking for something like #prependJavaScript() and
> #appendJavaScript() in AjaxRequestTarget -- but not in the response
> handling, instead for the code that triggers the click event.
>
> tl;dr: How can I specify JS code that's executed before and after a
> (specific) button or ajax submit of a form?
>
> Here's hoping for some tips,
>
>         Joachim
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Joachim Schrod, Roedermark, Germany
> Email: jschrod@acm.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>