You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Garret Wilson <ga...@globalmentor.com> on 2014/10/30 17:57:56 UTC

simple confirmation on button/link

All,

I've created a simple confirmation link based on Sven Meier's 
ConfirmationLink code <https://cwiki.apache.org/confluence/x/X4U> on 
Confluence. For the most part it works, but...

...but if I'm on an upload form, then an an Ajax link won't work because 
I need to actually submit the multipart information.

The theory behind Sven's code should work the same with or without an 
Ajax link. Wicket's AjaxLink simply provides an easy way to inject the 
confirmation JavaScript without having to wire the event handling 
manually. You'll see on the same page listed above other examples that 
do this wiring manually, and do it in a way that is decidedly "not 
correct" (replacing the onclick attribute) according to today's modern 
JavaScript best practices (and frankly hasn't been correct for almost a 
decade).

There is some discussion of this sort on that page, with a bit of 
back-and-forth about wanting a general, reusable solution, but in the 
end only giving an example of "something in that fashion" and with 
another contributor noting that their solution "isn't working and I need 
to figure out why". And now we're at Wicket 7 and even the incomplete 
examples on this page don't work anymore because the underlying classes 
have been removed.

(On that page the idea of Ed Eustace is also mentioned, namely to use 
Component.replaceWith() to have an embedded confirmation panel that 
appears when needed. But it's as usually a completely do-it-yourself 
project.)

So, friends, does the latest version of Wicket have an easy way to make 
a confirmation dialog? If not, does it have an easy way for me to inject 
JavaScript using best-practice DOM event binding?

Garret

Re: simple confirmation on button/link

Posted by Andrea Del Bene <an...@gmail.com>.
Probably there was a misunderstanding :). I saw Garret Wilson searching 
for a behavior to inject "submission" and "confirmation" into various 
components. I just pointed out that actually we have a special behavior 
for AJAX (AbstractDefaultAjaxBehavior) that can be used to factorize 
custom Ajax request attributes and apply them when needed instead of 
repeating code in various subclasses. Of course with this solution you 
have to manually add you custom behavior and is not powerful as an Ajax 
listener as you suggested.
> Unless you use a more powerful language than Java that provides something
> like Scala's Trait I don't see how you could implement your solution
> without re-implementing the standard Ajax links.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Fri, Oct 31, 2014 at 5:33 PM, Andrea Del Bene <an...@gmail.com>
> wrote:
>


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


Re: simple confirmation on button/link

Posted by Martin Grigorov <mg...@apache.org>.
Unless you use a more powerful language than Java that provides something
like Scala's Trait I don't see how you could implement your solution
without re-implementing the standard Ajax links.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Oct 31, 2014 at 5:33 PM, Andrea Del Bene <an...@gmail.com>
wrote:

> You are suggesting something like we see in GlobalUpdateAjaxAttributesTest,
> right? What I was thinking of was a less powerful solution suited to
> decorate standard AJAX links only in few cases you might need confirmation.
>
>  You have to refresh your knowledge about the related code.
>>
>> Or I should ...
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Fri, Oct 31, 2014 at 3:54 PM, Andrea Del Bene <an...@gmail.com>
>> wrote:
>>
>>  You have to add it explicitly with the usual way. This is more desirable
>>> if you don't want to apply it to every Ajax behavior as you suggested.
>>>
>>>  @Andrea: how would you share this behavior between ConfirmingAjaxLink
>>>> and
>>>> ConfirmingAjaxSubmitLink ?
>>>>
>>>> Martin Grigorov
>>>> Wicket Training and Consulting
>>>> https://twitter.com/mtgrigorov
>>>>
>>>> On Fri, Oct 31, 2014 at 2:56 PM, Andrea Del Bene <an...@gmail.com>
>>>> wrote:
>>>>
>>>>   you can also use behavior AbstractDefaultAjaxBehavior which has
>>>>
>>>>> updateAjaxAttributes(AjaxRequestAttributes attributes), so you can
>>>>> share
>>>>> confirmation code among different components.
>>>>>
>>>>>    Hi,
>>>>>
>>>>>
>>>>>  ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: simple confirmation on button/link

Posted by Andrea Del Bene <an...@gmail.com>.
You are suggesting something like we see in 
GlobalUpdateAjaxAttributesTest, right? What I was thinking of was a less 
powerful solution suited to decorate standard AJAX links only in few 
cases you might need confirmation.
> You have to refresh your knowledge about the related code.
>
> Or I should ...
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Fri, Oct 31, 2014 at 3:54 PM, Andrea Del Bene <an...@gmail.com>
> wrote:
>
>> You have to add it explicitly with the usual way. This is more desirable
>> if you don't want to apply it to every Ajax behavior as you suggested.
>>
>>> @Andrea: how would you share this behavior between ConfirmingAjaxLink and
>>> ConfirmingAjaxSubmitLink ?
>>>
>>> Martin Grigorov
>>> Wicket Training and Consulting
>>> https://twitter.com/mtgrigorov
>>>
>>> On Fri, Oct 31, 2014 at 2:56 PM, Andrea Del Bene <an...@gmail.com>
>>> wrote:
>>>
>>>   you can also use behavior AbstractDefaultAjaxBehavior which has
>>>> updateAjaxAttributes(AjaxRequestAttributes attributes), so you can share
>>>> confirmation code among different components.
>>>>
>>>>    Hi,
>>>>
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>


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


Re: simple confirmation on button/link

Posted by Martin Grigorov <mg...@apache.org>.
You have to refresh your knowledge about the related code.

Or I should ...

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Oct 31, 2014 at 3:54 PM, Andrea Del Bene <an...@gmail.com>
wrote:

> You have to add it explicitly with the usual way. This is more desirable
> if you don't want to apply it to every Ajax behavior as you suggested.
>
>> @Andrea: how would you share this behavior between ConfirmingAjaxLink and
>> ConfirmingAjaxSubmitLink ?
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Fri, Oct 31, 2014 at 2:56 PM, Andrea Del Bene <an...@gmail.com>
>> wrote:
>>
>>  you can also use behavior AbstractDefaultAjaxBehavior which has
>>> updateAjaxAttributes(AjaxRequestAttributes attributes), so you can share
>>> confirmation code among different components.
>>>
>>>   Hi,
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: simple confirmation on button/link

Posted by Andrea Del Bene <an...@gmail.com>.
You have to add it explicitly with the usual way. This is more desirable 
if you don't want to apply it to every Ajax behavior as you suggested.
> @Andrea: how would you share this behavior between ConfirmingAjaxLink and
> ConfirmingAjaxSubmitLink ?
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Fri, Oct 31, 2014 at 2:56 PM, Andrea Del Bene <an...@gmail.com>
> wrote:
>
>> you can also use behavior AbstractDefaultAjaxBehavior which has
>> updateAjaxAttributes(AjaxRequestAttributes attributes), so you can share
>> confirmation code among different components.
>>
>>   Hi,
>>


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


Re: simple confirmation on button/link

Posted by Martin Grigorov <mg...@apache.org>.
@Andrea: how would you share this behavior between ConfirmingAjaxLink and
ConfirmingAjaxSubmitLink ?

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Oct 31, 2014 at 2:56 PM, Andrea Del Bene <an...@gmail.com>
wrote:

> you can also use behavior AbstractDefaultAjaxBehavior which has
> updateAjaxAttributes(AjaxRequestAttributes attributes), so you can share
> confirmation code among different components.
>
>  Hi,
>>
>> On Thu, Oct 30, 2014 at 11:57 PM, Garret Wilson <ga...@globalmentor.com>
>> wrote:
>>
>>  Andrea, thanks for jolting my brain; I was a little sleepy this morning.
>>>
>>> I was using a subclass of AjaxLink that added confirmation JavaScript as
>>> I
>>> outlined below. My original HTML was:
>>>
>>>      <button wicket:id="foo" type="submit">
>>>
>>> The root of the problem is that Wicket kept turning that into:
>>>
>>>      <button wicket:id="foo" type="button" id="foo7">
>>>
>>> Thus even though I got a confirmation dialog, the FileUpload was never
>>> being populated because the form was never being submitted.
>>>
>>> It turns out that apparently I have to use a subclass of AjaxSubmitLink
>>> rather than AjaxLink if I want the form to actually be submitted, even
>>> though I specified type="submit" in the HTML. So my immediate problem is
>>> solved.
>>>
>>> On a higher level, though, it means that I now have to go create a
>>> ConfirmationAjaxSubmitLink along with my ConfirmationAjaxLink. I would
>>> have
>>> thought/hoped that things like "submission" and "confirmation" were
>>> something that could be injected to various components using behaviors
>>> rather that subclassing all over the place.
>>>
>>>  There is a way to provide a global #updateAjaxAttributes() that is
>> called
>> for each and every Ajax
>> behavior: org.apache.wicket.ajax.AjaxRequestTarget.IListener#
>> updateAjaxAttributes
>>
>> With
>> https://git-wip-us.apache.org/repos/asf?p=wicket.git;a=commit;h=d1caec5e
>> I've improved it so there is no need to cast it
>> to AbstractDefaultAjaxBehavior in the application code. You can use
>> AbstractDefaultAjaxBehavior#getComponent() to check whether you should
>> contribute to the ajax attributes or nor.
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: simple confirmation on button/link

Posted by Andrea Del Bene <an...@gmail.com>.
you can also use behavior AbstractDefaultAjaxBehavior which has 
updateAjaxAttributes(AjaxRequestAttributes attributes), so you can share 
confirmation code among different components.
> Hi,
>
> On Thu, Oct 30, 2014 at 11:57 PM, Garret Wilson <ga...@globalmentor.com>
> wrote:
>
>> Andrea, thanks for jolting my brain; I was a little sleepy this morning.
>>
>> I was using a subclass of AjaxLink that added confirmation JavaScript as I
>> outlined below. My original HTML was:
>>
>>      <button wicket:id="foo" type="submit">
>>
>> The root of the problem is that Wicket kept turning that into:
>>
>>      <button wicket:id="foo" type="button" id="foo7">
>>
>> Thus even though I got a confirmation dialog, the FileUpload was never
>> being populated because the form was never being submitted.
>>
>> It turns out that apparently I have to use a subclass of AjaxSubmitLink
>> rather than AjaxLink if I want the form to actually be submitted, even
>> though I specified type="submit" in the HTML. So my immediate problem is
>> solved.
>>
>> On a higher level, though, it means that I now have to go create a
>> ConfirmationAjaxSubmitLink along with my ConfirmationAjaxLink. I would have
>> thought/hoped that things like "submission" and "confirmation" were
>> something that could be injected to various components using behaviors
>> rather that subclassing all over the place.
>>
> There is a way to provide a global #updateAjaxAttributes() that is called
> for each and every Ajax
> behavior: org.apache.wicket.ajax.AjaxRequestTarget.IListener#updateAjaxAttributes
>
> With
> https://git-wip-us.apache.org/repos/asf?p=wicket.git;a=commit;h=d1caec5e
> I've improved it so there is no need to cast it
> to AbstractDefaultAjaxBehavior in the application code. You can use
> AbstractDefaultAjaxBehavior#getComponent() to check whether you should
> contribute to the ajax attributes or nor.
>
>


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


Re: simple confirmation on button/link

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

On Thu, Oct 30, 2014 at 11:57 PM, Garret Wilson <ga...@globalmentor.com>
wrote:

> Andrea, thanks for jolting my brain; I was a little sleepy this morning.
>
> I was using a subclass of AjaxLink that added confirmation JavaScript as I
> outlined below. My original HTML was:
>
>     <button wicket:id="foo" type="submit">
>
> The root of the problem is that Wicket kept turning that into:
>
>     <button wicket:id="foo" type="button" id="foo7">
>
> Thus even though I got a confirmation dialog, the FileUpload was never
> being populated because the form was never being submitted.
>
> It turns out that apparently I have to use a subclass of AjaxSubmitLink
> rather than AjaxLink if I want the form to actually be submitted, even
> though I specified type="submit" in the HTML. So my immediate problem is
> solved.
>
> On a higher level, though, it means that I now have to go create a
> ConfirmationAjaxSubmitLink along with my ConfirmationAjaxLink. I would have
> thought/hoped that things like "submission" and "confirmation" were
> something that could be injected to various components using behaviors
> rather that subclassing all over the place.
>

There is a way to provide a global #updateAjaxAttributes() that is called
for each and every Ajax
behavior: org.apache.wicket.ajax.AjaxRequestTarget.IListener#updateAjaxAttributes

With
https://git-wip-us.apache.org/repos/asf?p=wicket.git;a=commit;h=d1caec5e
I've improved it so there is no need to cast it
to AbstractDefaultAjaxBehavior in the application code. You can use
AbstractDefaultAjaxBehavior#getComponent() to check whether you should
contribute to the ajax attributes or nor.


>
> But for now the program is working. Thanks again, Andrea, for asking the
> right question that made me investigate further in the right spot.
>
> Garret
>
>
> On 10/30/2014 1:14 PM, Andrea Del Bene wrote:
>
>> On 30/10/14 17:57, Garret Wilson wrote:
>>
>>> All,
>>>
>>> I've created a simple confirmation link based on Sven Meier's
>>> ConfirmationLink code <https://cwiki.apache.org/confluence/x/X4U> on
>>> Confluence. For the most part it works, but...
>>>
>>> ...but if I'm on an upload form, then an an Ajax link won't work because
>>> I need to actually submit the multipart information.
>>>
>>>
>>>  Hi,
>>
>> not sure I've got your problem. Are you submitting a form using a Ajax
>> link?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: simple confirmation on button/link

Posted by Garret Wilson <ga...@globalmentor.com>.
Andrea, thanks for jolting my brain; I was a little sleepy this morning.

I was using a subclass of AjaxLink that added confirmation JavaScript as 
I outlined below. My original HTML was:

     <button wicket:id="foo" type="submit">

The root of the problem is that Wicket kept turning that into:

     <button wicket:id="foo" type="button" id="foo7">

Thus even though I got a confirmation dialog, the FileUpload was never 
being populated because the form was never being submitted.

It turns out that apparently I have to use a subclass of AjaxSubmitLink 
rather than AjaxLink if I want the form to actually be submitted, even 
though I specified type="submit" in the HTML. So my immediate problem is 
solved.

On a higher level, though, it means that I now have to go create a 
ConfirmationAjaxSubmitLink along with my ConfirmationAjaxLink. I would 
have thought/hoped that things like "submission" and "confirmation" were 
something that could be injected to various components using behaviors 
rather that subclassing all over the place.

But for now the program is working. Thanks again, Andrea, for asking the 
right question that made me investigate further in the right spot.

Garret

On 10/30/2014 1:14 PM, Andrea Del Bene wrote:
> On 30/10/14 17:57, Garret Wilson wrote:
>> All,
>>
>> I've created a simple confirmation link based on Sven Meier's 
>> ConfirmationLink code <https://cwiki.apache.org/confluence/x/X4U> on 
>> Confluence. For the most part it works, but...
>>
>> ...but if I'm on an upload form, then an an Ajax link won't work 
>> because I need to actually submit the multipart information.
>>
>>
> Hi,
>
> not sure I've got your problem. Are you submitting a form using a Ajax 
> link?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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


Re: simple confirmation on button/link

Posted by Andrea Del Bene <an...@gmail.com>.
On 30/10/14 17:57, Garret Wilson wrote:
> All,
>
> I've created a simple confirmation link based on Sven Meier's 
> ConfirmationLink code <https://cwiki.apache.org/confluence/x/X4U> on 
> Confluence. For the most part it works, but...
>
> ...but if I'm on an upload form, then an an Ajax link won't work 
> because I need to actually submit the multipart information.
>
>
Hi,

not sure I've got your problem. Are you submitting a form using a Ajax link?


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