Re: Javascript confirm with condition before submit

2013-06-24 Thread Marios Skounakis
Yeah, my example is wicket 6. I believe (I may be wrong though) that the
logic is the same in 1.5.7 you just need to adapt the method calls.


On Mon, Jun 24, 2013 at 11:06 AM, grignette  wrote:

> It doesn't work.
>
> You call commitBehavior.getCallbackScript() but :
>
> Multiple markers at this line
> - The method add(Component...) in the type AjaxRequestTarget is not
> applicable for the arguments
>  (CharSequence)
> - The method getCallbackScript() from the type
> AbstractDefaultAjaxBehavior
> is not visible
>
> I use Wicket 1.5.7. Do you think that is the problem ?
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659722.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Javascript confirm with condition before submit

2013-06-24 Thread grignette
It doesn't work. 

You call commitBehavior.getCallbackScript() but :

Multiple markers at this line
- The method add(Component...) in the type AjaxRequestTarget is not
applicable for the arguments 
 (CharSequence)
- The method getCallbackScript() from the type 
AbstractDefaultAjaxBehavior
is not visible

I use Wicket 1.5.7. Do you think that is the problem ? 



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659722.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: Javascript confirm with condition before submit

2013-06-22 Thread grignette
Thanks Marios ! I will test that Monday 



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659695.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: Javascript confirm with condition before submit

2013-06-21 Thread Marios Skounakis
Here is the basic solution. I believe you can expand on this.

public class ServerSideConfirmationExamplePage extends WebPage {

Person person; // needs to be serializable

public ServerSideConfirmationExamplePage() {
this(new Person());
}

public ServerSideConfirmationExamplePage(Person p) {
person = p;
Form form = new Form("form",
new CompoundPropertyModel(person));
add(form);
form.add(new TextField("firstName", String.class)
.setRequired(true));
form.add(new TextField("lastName", String.class)
.setRequired(true));

final AbstractDefaultAjaxBehavior commitBehavior = new
AbstractDefaultAjaxBehavior() {

@Override
protected void respond(AjaxRequestTarget target) {
// user has confirmed (see below onSubmit)
try {
// here we would update the database, e.g.
// personManager.update(person);
target.appendJavaScript("alert('Person "
+ person.getFirstName() + " "
+ person.getLastName() + " saved!');");
// or perhaps, setResponsePage(...)
} catch (Exception e) {
// show exception message here
// perhaps
// form.error("Unexpected error");
// or target.appendJavascript("alert('unexpected
error');");
}
}
};
add(commitBehavior);

form.add(new AjaxButton("submit") {
@Override
public void onSubmit(AjaxRequestTarget target, Form frm) {
// validations have run and person has been updated with
the user's input
// we show the confirmation now
// and call the commitBehavior's callback script upon user
confirmation
target.appendJavaScript("if (confirm('are you sure you want
to save "
+ person.getFirstName()
+ " "
+ person.getLastName()
+ "?')) {" + commitBehavior.getCallbackScript() +
"}");
}
});
}
}


On Sat, Jun 22, 2013 at 12:55 AM, grignette  wrote:

> I like your solution with 3 issues :
>
> /Usually I override onSubmit (either on the form or the ajax button) and
> return the confirmation there. If the user confirms, I follow up with
> another ajax call which actually commits the data./
>
> If you can give me more details, i will be verry happy !
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659688.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Javascript confirm with condition before submit

2013-06-21 Thread grignette
I like your solution with 3 issues :

/Usually I override onSubmit (either on the form or the ajax button) and
return the confirmation there. If the user confirms, I follow up with
another ajax call which actually commits the data./

If you can give me more details, i will be verry happy ! 




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659688.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: Javascript confirm with condition before submit

2013-06-21 Thread Marios Skounakis
Also this approach assumes that your form is not using a
LoadableDetachableModel but it's using a serializable domain object which
can be used to store the data the user posted via the form between the
first ajax call (submit) and the second ajax call (confirmation) which
needs to save them to the db.

Perhaps if you use an AjaxFormSubmitBehavior instead of an
AbstractDefaultAjaxBehavior you can repost the form data after user
confirmation and avoid the need to store them in a serializable domain
object. I haven't tried this.


On Sat, Jun 22, 2013 at 12:46 AM, Marios Skounakis  wrote:

> I personally like server side confirmations because they can be customized
> based on the submitted data and you can use the model to customize the
> confirmation. If you do it client side you need to do it in javascript and
> using the component's values which is in my opinion ugly.
>
> Usually I override onSubmit (either on the form or the ajax button) and
> return the confirmation there. If the user confirms, I follow up with
> another ajax call which actually commits the data.
>
> This method has the following issues which you must take into
> consideration:
> 1. Because the confirmation is shown onSubmit, all validations happen
> before the confirmation. If a component is invalid, processing stops before
> the confirmation is shown. Also the form model has been updated. This may
> or may not be a problem. If you are in a regular database app, this is okay
> as long as your don't actually update the database.
> 2. Triggering a second ajax call after the user confirms is a bit tricky.
> You need to add an AbstractDefaultAjaxBehavior to the page and call it's
> getCallbackScript() if the user confirms. Then do the actual commit (e.g.
> store to the db) in it's respond() method.
> 3. Also this approach requires an extra ajax call to actually commit the
> form.
>
> I sometimes do confirmations using wicket's ModalWindow (or my own
> alternative JQuery-based implementation). This allows me to have a
> consistent presentation for all modal dialogs, be it confirmation,
> information or input dialogs. Also, using a ModalWindow allows for easier
> implementation of issue (2) above as instead of using an
> AbstractDefaultAjaxBehavior you can use the ModalWindow's CloseCallback to
> do the actual commit.
>
> There are other ways to do (2) above, such as having an extra ajax
> button/link that you trigger by javascript if the user confirms and use
> it's onSubmit method to actually commit the form.
>
> The above is a rather condensed version of what you need to do, let me
> know if you are interested and I can provide more details.
>
>
> On Sat, Jun 22, 2013 at 12:06 AM, grignette wrote:
>
>> Thanks for your answer.
>>
>> I'am sorry but I don't like the first solution. The second is better I
>> think
>> but I have 6 or 7 rules to implement like that. So it can be difficult.
>>
>> Someone have an other idea ? If no, I will try to implement the second
>> solution...
>>
>>
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659682.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>


Re: Javascript confirm with condition before submit

2013-06-21 Thread Marios Skounakis
I personally like server side confirmations because they can be customized
based on the submitted data and you can use the model to customize the
confirmation. If you do it client side you need to do it in javascript and
using the component's values which is in my opinion ugly.

Usually I override onSubmit (either on the form or the ajax button) and
return the confirmation there. If the user confirms, I follow up with
another ajax call which actually commits the data.

This method has the following issues which you must take into consideration:
1. Because the confirmation is shown onSubmit, all validations happen
before the confirmation. If a component is invalid, processing stops before
the confirmation is shown. Also the form model has been updated. This may
or may not be a problem. If you are in a regular database app, this is okay
as long as your don't actually update the database.
2. Triggering a second ajax call after the user confirms is a bit tricky.
You need to add an AbstractDefaultAjaxBehavior to the page and call it's
getCallbackScript() if the user confirms. Then do the actual commit (e.g.
store to the db) in it's respond() method.
3. Also this approach requires an extra ajax call to actually commit the
form.

I sometimes do confirmations using wicket's ModalWindow (or my own
alternative JQuery-based implementation). This allows me to have a
consistent presentation for all modal dialogs, be it confirmation,
information or input dialogs. Also, using a ModalWindow allows for easier
implementation of issue (2) above as instead of using an
AbstractDefaultAjaxBehavior you can use the ModalWindow's CloseCallback to
do the actual commit.

There are other ways to do (2) above, such as having an extra ajax
button/link that you trigger by javascript if the user confirms and use
it's onSubmit method to actually commit the form.

The above is a rather condensed version of what you need to do, let me know
if you are interested and I can provide more details.


On Sat, Jun 22, 2013 at 12:06 AM, grignette  wrote:

> Thanks for your answer.
>
> I'am sorry but I don't like the first solution. The second is better I
> think
> but I have 6 or 7 rules to implement like that. So it can be difficult.
>
> Someone have an other idea ? If no, I will try to implement the second
> solution...
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659682.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Javascript confirm with condition before submit

2013-06-21 Thread grignette
Thanks for your answer.

I'am sorry but I don't like the first solution. The second is better I think
but I have 6 or 7 rules to implement like that. So it can be difficult. 

Someone have an other idea ? If no, I will try to implement the second
solution...



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659682.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: Javascript confirm with condition before submit

2013-06-21 Thread Bertrand Guay-Paquet

Hi!

Are you on Wicket 6? If so, here's how I do my confirmation popup for an 
ajaxlink (should work for ajaxbutton too):


@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
String confirmJs = "if (!confirm('Please confirm')) return false;"
AjaxCallListener listener = new AjaxCallListener();
listener.onPrecondition(confirmJs);
attributes.getAjaxCallListeners().add(listener);
}

Of course, in your case, you need to write more complicated javascript 
to read form values and such. This solution all happens client-side.


You could also do it more server side by preventing default form submit 
behavior for the ajaxbutton. When the user clicks the button, you show a 
panel via ajax which asks for confirmation and that second button really 
sends the form.


Personally, I think I'd go for the first option but it depends on your 
requirements.


Bertrand



On 21/06/2013 11:36 AM, grignette wrote:

Hi !

I have an issue with a confirm Javascript message. I have a form. When the
user fills the form and  when he tries to submit (AjaxButton), I want to
provide confirm message based on the details filled by user. So the confrm
message may or maynot be present always

I tried to use method getOnClickScript of the Ajax Button. The code in the
getOnClickScript is translate in javascript by wicket on the onload of the
page. So my condition IF is always wrong, because the form is not completed
by the user yet.

I tried to add my condition just before my update, in the submit method with
this :

/target.appendJavaScript("confirm('"+getString("messageConfirm") + "')");/

The message is display just after the update... So to late !

Do you have any idea how I can display this confirm message ?

Thanks for your attention

Gaëlle





--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672.html
Sent from the Users forum mailing list archive at Nabble.com.

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





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



Javascript confirm with condition before submit

2013-06-21 Thread grignette
Hi !

I have an issue with a confirm Javascript message. I have a form. When the
user fills the form and  when he tries to submit (AjaxButton), I want to
provide confirm message based on the details filled by user. So the confrm
message may or maynot be present always

I tried to use method getOnClickScript of the Ajax Button. The code in the
getOnClickScript is translate in javascript by wicket on the onload of the
page. So my condition IF is always wrong, because the form is not completed
by the user yet.

I tried to add my condition just before my update, in the submit method with
this :

/target.appendJavaScript("confirm('"+getString("messageConfirm") + "')");/

The message is display just after the update... So to late !

Do you have any idea how I can display this confirm message ?

Thanks for your attention 

Gaëlle





--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672.html
Sent from the Users forum mailing list archive at Nabble.com.

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