You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by stuffhere <st...@gamesys.co.uk> on 2008/05/07 17:29:04 UTC
Problem with form submission with callback
Hi All
I'm trying to submit a form then do a callback to a javascript function, but
the form appears to be submitted twice.
The tapestry form is for login and has a couple of textfields with a
t:submit button
<t:submit class="submit" t:id="login_submit" t:value="Login" />
Abridged Java class
@Mixins("t5components/OnEvent")
@Component(id = "loginForm", parameters={"event=submit",
"onCompleteCallback=completeLogin"})
@Persist
private Form loginForm;
public JSONObject onSubmitFromLoginForm() {
System.out.println("\n\n----logging in member ");
JSONObject json = new JSONObject();
String isLoginSuccessful = "false";
LoginDto login = new LoginDto();
login.setUserName(getUserName());
login.setPassword(getPassword());
try {
System.out.println("----logging in member " + login.getUserName());
loginService.login(login);
securityToken = login.getSecurityToken();
isLoginSuccessful = "true";
} catch (ServiceFaultException e) {
json.put("message", "Login details are incorrect");
}
System.out.println("----login is successful " + isLoginSuccessful);
json.put("isLoginSuccessful", isLoginSuccessful);
return json;
}
----------------------------
The javascript function gets called, but is always passed false for
isLoginSuccessful. When I submit the form (with testuser and password for
the input) I get the following output:
----logging in member
----logging in member null
[DEBUG] HydraService ---------------------------- logging in member in
service
----login is successful false
127.0.0.1 - - [07/May/2008:15:24:50 +0000] "POST
/home.landingpage.loginwidget.loginform:submit HTTP/1.1" 200 69 "-"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404
Firefox/2.0.0.14"
----logging in member
----logging in member testuser
[DEBUG] HydraService ---------------------------- logging in member in
service
*******creating token********
----login is successful true
127.0.0.1 - - [07/May/2008:15:24:50 +0000] "POST
/home.landingpage.loginwidget.loginform HTTP/1.1" 200 30 "-" "Mozilla/5.0
(Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404
Firefox/2.0.0.14"
This is the javascript:
function completeLogin(response){
var json = response.evalJSON();
alert(json.isLoginSuccessful);
if (json != null && json.isLoginSuccessful.toString() == 'true') {
gotoHomePage();
}else{
showLoginError();
}
}
Does anyone have any ideas why this is submitting twice. The first time
doesn't appear to be a proper submit as none of the form fields are being
passed through.
Any help would be greatly appreciated!
--
View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17106416.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with form submission with callback
Posted by Chris Lewis <ch...@bellsouth.net>.
The issues with JS get harrier when you mix AJAX (zones) and components
or mixins that use external JS or CSS. Essentially, they won't be
included unless they were already included on the page. A ticket (with a
patch) is open for this issue:
https://issues.apache.org/jira/browse/TAPESTRY-2390
Josh Canfield wrote:
> Right now, in 5.0.11, there are some holes in the client side events
> and callbacks. You can get something to work, it requires a bit of
> wiring. You'll also want to know a bit about Zones and read
> tapestry.js to get a handle on what's going on.
>
> If you attach your form to a zone, then when the form is submitted it
> uses AJAX to post the values to your component. When the ajax call
> returns it updates the linked zone with the results and will run the
> javascript included as a property of the JSON response. It does not
> run the javascript elements in the returned block (not sure if this is
> a bug, perhaps zones should be using prototype's update facility
> instead of innerHTML directly). You can get script into the response
> by including a component that uses PageRenderSupport.addScript in your
> Block that you return from your form submit handler. If the form is in
> the zone that is rendered you will get the t:errors updated with your
> form errors.
>
> There is no error handling in the tapestry client side form processing
> yet (no timeout for instance). I expect that before Tapestry 1.0 we'll
> get better client side javascript support.
>
> It helps me to have a second experimental project which contains a
> place to practice with these techniques without all the overhead of my
> full application (hibernate, service startup, etc.)
>
> Josh
>
>
> On Thu, May 8, 2008 at 2:14 AM, stuffhere <st...@gamesys.co.uk> wrote:
>
>> It was the only way I could think to do the javascript callback - using
>> onCompleteCallback. I'm pretty new to Tapestry, so most of what I've done
>> has been trial and error, is there a better way to do the callback?
>>
>>
>> --
>> View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17123069.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
>
--
http://thegodcode.net
Re: Problem with form submission with callback
Posted by Josh Canfield <jo...@thedailytube.com>.
Right now, in 5.0.11, there are some holes in the client side events
and callbacks. You can get something to work, it requires a bit of
wiring. You'll also want to know a bit about Zones and read
tapestry.js to get a handle on what's going on.
If you attach your form to a zone, then when the form is submitted it
uses AJAX to post the values to your component. When the ajax call
returns it updates the linked zone with the results and will run the
javascript included as a property of the JSON response. It does not
run the javascript elements in the returned block (not sure if this is
a bug, perhaps zones should be using prototype's update facility
instead of innerHTML directly). You can get script into the response
by including a component that uses PageRenderSupport.addScript in your
Block that you return from your form submit handler. If the form is in
the zone that is rendered you will get the t:errors updated with your
form errors.
There is no error handling in the tapestry client side form processing
yet (no timeout for instance). I expect that before Tapestry 1.0 we'll
get better client side javascript support.
It helps me to have a second experimental project which contains a
place to practice with these techniques without all the overhead of my
full application (hibernate, service startup, etc.)
Josh
On Thu, May 8, 2008 at 2:14 AM, stuffhere <st...@gamesys.co.uk> wrote:
>
> It was the only way I could think to do the javascript callback - using
> onCompleteCallback. I'm pretty new to Tapestry, so most of what I've done
> has been trial and error, is there a better way to do the callback?
>
>
> --
> View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17123069.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with form submission with callback
Posted by Sven Homburg <ho...@googlemail.com>.
ofcourse
2008/5/8 lebenski <be...@gamesys.co.uk>:
>
> By using a vanilla Ajax Request wouldn't you be bypassing all the benefits
> you get from the Tapestry Form Event lifecycle and Tesptry forms in
> general?
>
>
> Sven Homburg wrote:
> >
> > if your requirement is a login without a page refresh
> > the using of OnEvent is in this case not the right way
> > because OnEvent doesnt know anything about the username and password
> > values.
> >
> > i think the best way is, write your own Ajax.Request script
> > that submits the form values to tapestry
> >
> >
> > 2008/5/8 stuffhere <st...@gamesys.co.uk>:
> >
> >>
> >> It was the only way I could think to do the javascript callback - using
> >> onCompleteCallback. I'm pretty new to Tapestry, so most of what I've
> >> done
> >> has been trial and error, is there a better way to do the callback?
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17123069.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > with regards
> > Sven Homburg
> > http://tapestry5-components.googlecode.com
> >
> >
> > -----
> > best regards
> > Sven
> >
>
> --
> View this message in context:
> http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17125082.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
with regards
Sven Homburg
http://tapestry5-components.googlecode.com
Re: Problem with form submission with callback
Posted by lebenski <be...@gamesys.co.uk>.
By using a vanilla Ajax Request wouldn't you be bypassing all the benefits
you get from the Tapestry Form Event lifecycle and Tesptry forms in general?
Sven Homburg wrote:
>
> if your requirement is a login without a page refresh
> the using of OnEvent is in this case not the right way
> because OnEvent doesnt know anything about the username and password
> values.
>
> i think the best way is, write your own Ajax.Request script
> that submits the form values to tapestry
>
>
> 2008/5/8 stuffhere <st...@gamesys.co.uk>:
>
>>
>> It was the only way I could think to do the javascript callback - using
>> onCompleteCallback. I'm pretty new to Tapestry, so most of what I've
>> done
>> has been trial and error, is there a better way to do the callback?
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17123069.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> with regards
> Sven Homburg
> http://tapestry5-components.googlecode.com
>
>
> -----
> best regards
> Sven
>
--
View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17125082.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with form submission with callback
Posted by Sven Homburg <ho...@googlemail.com>.
if your requirement is a login without a page refresh
the using of OnEvent is in this case not the right way
because OnEvent doesnt know anything about the username and password values.
i think the best way is, write your own Ajax.Request script
that submits the form values to tapestry
2008/5/8 stuffhere <st...@gamesys.co.uk>:
>
> It was the only way I could think to do the javascript callback - using
> onCompleteCallback. I'm pretty new to Tapestry, so most of what I've done
> has been trial and error, is there a better way to do the callback?
>
>
> --
> View this message in context:
> http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17123069.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
with regards
Sven Homburg
http://tapestry5-components.googlecode.com
Re: Problem with form submission with callback
Posted by stuffhere <st...@gamesys.co.uk>.
It was the only way I could think to do the javascript callback - using
onCompleteCallback. I'm pretty new to Tapestry, so most of what I've done
has been trial and error, is there a better way to do the callback?
--
View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17123069.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with form submission with callback
Posted by Sven Homburg <ho...@googlemail.com>.
what is your reason to attach the OnEvent Mixin to the Login form ?
2008/5/7 stuffhere <st...@gamesys.co.uk>:
>
> Ok, I've put some prints in the setters and the form event methods, this
> is
> what I get out:
>
> ----logging in member
> 127.0.0.1 - - [07/May/2008:17:00:29 +0000] "POST
> /home.landingpage.loginwidget.loginform:submit HTTP/1.1" 200 2 "-"
> "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14)
> Gecko/20080404
> Firefox/2.0.0.14"
> ------validate null
> ------setusername null
> ------validate null
> ------setpassword null
> ------successful null
> ----logging in member
> 127.0.0.1 - - [07/May/2008:17:00:29 +0000] "POST
> /home.landingpage.loginwidget.loginform HTTP/1.1" 200 4 "-" "Mozilla/5.0
> (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404
> Firefox/2.0.0.14"
>
> So it appears that the onsubmit method is being called twice, but the form
> is only being properly submitted once. I think the first time the submit
> function is called is when I get the javascript callback, which is why I'm
> always returned false - the form fields (username and password) are not
> being set that time around. Does anyone know why this is, or how I can
> fix
> it?
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17109977.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
with regards
Sven Homburg
http://tapestry5-components.googlecode.com
Re: Problem with form submission with callback
Posted by stuffhere <st...@gamesys.co.uk>.
Ok, I've put some prints in the setters and the form event methods, this is
what I get out:
----logging in member
127.0.0.1 - - [07/May/2008:17:00:29 +0000] "POST
/home.landingpage.loginwidget.loginform:submit HTTP/1.1" 200 2 "-"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404
Firefox/2.0.0.14"
------validate null
------setusername null
------validate null
------setpassword null
------successful null
----logging in member
127.0.0.1 - - [07/May/2008:17:00:29 +0000] "POST
/home.landingpage.loginwidget.loginform HTTP/1.1" 200 4 "-" "Mozilla/5.0
(Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404
Firefox/2.0.0.14"
So it appears that the onsubmit method is being called twice, but the form
is only being properly submitted once. I think the first time the submit
function is called is when I get the javascript callback, which is why I'm
always returned false - the form fields (username and password) are not
being set that time around. Does anyone know why this is, or how I can fix
it?
--
View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17109977.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Problem with form submission with callback
Posted by stuffhere <st...@gamesys.co.uk>.
P.S. I think this is a problem with the onevent stuff - if I just do a normal
submit, the onSubmitFromLoginForm function only gets called once.
--
View this message in context: http://www.nabble.com/Problem-with-form-submission-with-callback-tp17106416p17106419.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org