You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Shahid Shaikh <ss...@yahoo.com.INVALID> on 2014/07/22 18:38:48 UTC

Tapestry AJAX call on submit

Fellow Tapestry Users,

I have a form that when submitted needs to
 make a call to an external service (calling a URL that will return a 
value of type string) which i will then add to the form data and do the 
actual submit.
What is the best way to handle this in Tapestry?

So for e.g

    @Log
    Object onSubmitFromTestForm() {

//need to make some form of AJAX or javascript call here to the URL provided
//that will return a value

String key = $.ajax... //not sure how to call the URL in tapestry that will get me the value

.. continue with regular process with key obtained and do the submit

return ConfirmedPage.class;
}

Thanks for your help!

Re: Tapestry AJAX call on submit

Posted by Geoff Callender <ge...@gmail.com>.
Try a Tapestry AJAX Form with two Submits: one visible and one hidden. Add JavaScript that listens to the click of the visible submit, stops the event propagating, does the call to the external service and, on success, sets the value of the form field (which might be a hidden field) and clicks the hidden submit.

Here's a standard AJAX Form:

	T5.4: http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/form
	T5.3: http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/form

Here's some JavaScript that listens to something:

	T5.4: http://jumpstart.doublenegative.com.au/jumpstart7/examples/javascript/robust
	T5.3: http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/robust

Geoff

On 23 Jul 2014, at 2:38 am, Shahid Shaikh <ss...@yahoo.com.INVALID> wrote:

> Fellow Tapestry Users,
> 
> I have a form that when submitted needs to
> make a call to an external service (calling a URL that will return a 
> value of type string) which i will then add to the form data and do the 
> actual submit.
> What is the best way to handle this in Tapestry?
> 
> So for e.g
> 
>     @Log
>     Object onSubmitFromTestForm() {
> 
> //need to make some form of AJAX or javascript call here to the URL provided
> //that will return a value
> 
> String key = $.ajax... //not sure how to call the URL in tapestry that will get me the value
> 
> .. continue with regular process with key obtained and do the submit
> 
> return ConfirmedPage.class;
> }
> 
> Thanks for your help!


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


Re: Tapestry AJAX call on submit

Posted by Geoff Callender <ge...@gmail.com>.
Did you miss my response? Much better than trying to handle the final submit yourself. Here it is again...

Try a Tapestry AJAX Form with two Submits: one visible and one hidden. Add JavaScript that listens to the click of the visible submit, stops the event propagating, does the call to the external service and, on success, sets the value of the form field (which might be a hidden field) and clicks the hidden submit.

Here's a standard AJAX Form:

	T5.4: http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/form
	T5.3: http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/form

Here's some JavaScript that listens to something:

	T5.4: http://jumpstart.doublenegative.com.au/jumpstart7/examples/javascript/robust
	T5.3: http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/robust

Geoff

On 23 Jul 2014, at 11:43 pm, Shahid Shaikh <ss...@yahoo.com.INVALID> wrote:

> Thank you for that clarification again.
> 
> So just to be clear, once i have javascript handle the call to the external url, and process the data. Once i do form.submit() in javascript, my OnSubmitForm event in Tapestry will still get triggered?
> 
> 
> 
> ________________________________
> From: Thiago H de Paula Figueiredo [via Apache Tapestry Mailing List Archives] <ml...@n5.nabble.com>
> To: shahidsan <ss...@yahoo.com> 
> Sent: Wednesday, July 23, 2014 9:33 AM
> Subject: Re: Tapestry AJAX call on submit
> 
> 
> 
> On Tue, 22 Jul 2014 23:04:56 -0300, Shahid <[hidden email]>   
> wrote: 
> 
>> Sorry about the confusion and I appreciate your feedback . 
>> I would like to invoke the external URL as part of the onSubmit event.   
>> So before the form is submitted . 
> 
> You're still confused here. The Tapestry submit event is triggered by the   
> web server receiving the form submission, so you do *not* want to invoke   
> the external URL as part of the Tapestry submit event. You want to do   
> stuff *before* the form submission, so before the Tapestry submit event. 
> 
>> So was looking for a way using AJAX and JavaScript to do it. 
> 
> So you're asking in the wrong place. This is a Tapestry mailing list and   
> your question isn't Tapestry-related. It's a pure JavaScript question. 
> 
> -- 
> Thiago H. de Paula Figueiredo 
> Tapestry, Java and Hibernate consultant and developer 
> http://machina.com.br
> 
> --------------------------------------------------------------------- 
> To unsubscribe, e-mail: [hidden email] 
> For additional commands, e-mail: [hidden email] 
> 
> 
> 
> ________________________________
> 
> If you reply to this email, your message will be added to the discussion below:http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Tapestry-AJAX-call-on-submit-tp5727687p5727697.html 
> 
> 
> To unsubscribe from Apache Tapestry Mailing List Archives, click here.
> NAML


Re: Tapestry AJAX call on submit

Posted by Shahid Shaikh <ss...@yahoo.com.INVALID>.
Thank you for that clarification again.

So just to be clear, once i have javascript handle the call to the external url, and process the data. Once i do form.submit() in javascript, my OnSubmitForm event in Tapestry will still get triggered?



________________________________
 From: Thiago H de Paula Figueiredo [via Apache Tapestry Mailing List Archives] <ml...@n5.nabble.com>
To: shahidsan <ss...@yahoo.com> 
Sent: Wednesday, July 23, 2014 9:33 AM
Subject: Re: Tapestry AJAX call on submit
 


On Tue, 22 Jul 2014 23:04:56 -0300, Shahid <[hidden email]>   
wrote: 

> Sorry about the confusion and I appreciate your feedback . 
> I would like to invoke the external URL as part of the onSubmit event.   
> So before the form is submitted . 

You're still confused here. The Tapestry submit event is triggered by the   
web server receiving the form submission, so you do *not* want to invoke   
the external URL as part of the Tapestry submit event. You want to do   
stuff *before* the form submission, so before the Tapestry submit event. 

> So was looking for a way using AJAX and JavaScript to do it. 

So you're asking in the wrong place. This is a Tapestry mailing list and   
your question isn't Tapestry-related. It's a pure JavaScript question. 

-- 
Thiago H. de Paula Figueiredo 
Tapestry, Java and Hibernate consultant and developer 
http://machina.com.br

--------------------------------------------------------------------- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 



________________________________
 
If you reply to this email, your message will be added to the discussion below:http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Tapestry-AJAX-call-on-submit-tp5727687p5727697.html 


To unsubscribe from Apache Tapestry Mailing List Archives, click here.
NAML 

Re: Tapestry AJAX call on submit

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 22 Jul 2014 23:04:56 -0300, Shahid <ss...@yahoo.com.invalid>  
wrote:

> Sorry about the confusion and I appreciate your feedback .
> I would like to invoke the external URL as part of the onSubmit event.  
> So before the form is submitted .

You're still confused here. The Tapestry submit event is triggered by the  
web server receiving the form submission, so you do *not* want to invoke  
the external URL as part of the Tapestry submit event. You want to do  
stuff *before* the form submission, so before the Tapestry submit event.

> So was looking for a way using AJAX and JavaScript to do it.

So you're asking in the wrong place. This is a Tapestry mailing list and  
your question isn't Tapestry-related. It's a pure JavaScript question.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Tapestry AJAX call on submit

Posted by Shahid <ss...@yahoo.com.INVALID>.
Sorry about the confusion and I appreciate your feedback .

I would like to invoke the external URL as part of the onSubmit event. So before the form is submitted . So was looking for a way using AJAX and JavaScript to do it.



> On Jul 22, 2014, at 5:18 PM, Shahid <ss...@yahoo.com> wrote:
> 
> Sorry about the confusion and I appreciate your feedback .
> 
> I would like to invoke the external URL as part of the onSubmit event. So before the form is submitted . So was looking for a way using AJAX and JavaScript to do it
> 
> Shahid Shaikh
> 
>> On Jul 22, 2014, at 5:12 PM, "Thiago H de Paula Figueiredo [via Apache Tapestry Mailing List Archives]" <ml...@n5.nabble.com> wrote:
>> 
>> On Tue, 22 Jul 2014 13:38:48 -0300, Shahid Shaikh   
>> <[hidden email]> wrote: 
>> 
>> > Fellow Tapestry Users, 
>> 
>> Hi! 
>> 
>> > 
>> > I have a form that when submitted needs to 
>> >  make a call to an external service (calling a URL that will return a 
>> > value of type string) which i will then add to the form data and do the 
>> > actual submit. 
>> > What is the best way to handle this in Tapestry? 
>> 
>> In the same way you'd do without Tapestry: using some JavaScript to make   
>> the call to the external service, then changing some field values to   
>> reflect the result, them programatically submitting the form. 
>> 
>> > So for e.g 
>> > 
>> >     @Log 
>> >     Object onSubmitFromTestForm() { 
>> > 
>> > //need to make some form of AJAX or javascript call here to the URL   
>> > provided 
>> > //that will return a value 
>> 
>> I'm confused: do you want to call the external service before the form   
>> submission, through AJAX and JavaScript or after (onSubmit is after the   
>> form submission, looking at the HTML side, as it's processing the form   
>> submission), server-side. If after (server-side), just use something like   
>> Apache HttpClient to do the request. This isn't affected by being done in   
>> a Tapestry page or component class at all. 
>> 
>> > String key = $.ajax... //not sure how to call the URL in tapestry that   
>> > will get me the value 
>> 
>> This is just about jQuery, not being related to Tapestry at all. 
>> 
>> -- 
>> Thiago H. de Paula Figueiredo 
>> Tapestry, Java and Hibernate consultant and developer 
>> http://machina.com.br
>> 
>> --------------------------------------------------------------------- 
>> To unsubscribe, e-mail: [hidden email] 
>> For additional commands, e-mail: [hidden email] 
>> 
>> 
>> 
>> If you reply to this email, your message will be added to the discussion below:
>> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Tapestry-AJAX-call-on-submit-tp5727687p5727688.html
>> To unsubscribe from Apache Tapestry Mailing List Archives, click here.
>> NAML

Re: Tapestry AJAX call on submit

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 22 Jul 2014 13:38:48 -0300, Shahid Shaikh  
<ss...@yahoo.com.invalid> wrote:

> Fellow Tapestry Users,

Hi!

>
> I have a form that when submitted needs to
>  make a call to an external service (calling a URL that will return a
> value of type string) which i will then add to the form data and do the
> actual submit.
> What is the best way to handle this in Tapestry?

In the same way you'd do without Tapestry: using some JavaScript to make  
the call to the external service, then changing some field values to  
reflect the result, them programatically submitting the form.

> So for e.g
>
>     @Log
>     Object onSubmitFromTestForm() {
>
> //need to make some form of AJAX or javascript call here to the URL  
> provided
> //that will return a value

I'm confused: do you want to call the external service before the form  
submission, through AJAX and JavaScript or after (onSubmit is after the  
form submission, looking at the HTML side, as it's processing the form  
submission), server-side. If after (server-side), just use something like  
Apache HttpClient to do the request. This isn't affected by being done in  
a Tapestry page or component class at all.

> String key = $.ajax... //not sure how to call the URL in tapestry that  
> will get me the value

This is just about jQuery, not being related to Tapestry at all.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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