You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by sadko <sa...@gmail.com> on 2011/01/16 22:06:19 UTC

Automatic Ajax after page load and redirect to PageExpiredErrorPage

Hi there,
I'm struggling with this half a day already and don't know how to fix. I
have some Facebook javascript SDK calls on a page to get current user's
facebook id. This calls are of course asynchronous and on completion they
call my wicket callbacks automatically to process the data. Beside that I
have a BookmarkablePageLink on the page targeting the home page (logo that
takes you always home).

The problem is following. If I am on the home page and click the
Bookmarkable link before the ajax calls are finished the home page is
refreshed with new page id but the ajax calls returnes following response:
<ajax-response><redirect>../en/?wicket:bookmarkablePage=:org.apache.wicket.markup.html.pages.PageExpiredErrorPage</redirect></ajax-response>

What results in redirect to PageExpired page.

The URL for ajax calls looks like this:
https://localhost:8443/my-app/en/?wicket:interface=:31:authPanel:notLoggedLoginPanel:signInContainer:signInPanel:communityLoginContainer:communityLoginItems:0:communityLoginItem::IActivePageBehaviorListener:1:1&wicket:ignoreIfNotActive=true&fbid=xxx&fbsessid=xxx&fbaccesstoken=xxx&random=0.9877056940825386

Does anyone know what's wrong and what could I do about it? Any help would
be appreciated.

Thanks,
Martin
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Automatic-Ajax-after-page-load-and-redirect-to-PageExpiredErrorPage-tp3220405p3220405.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Automatic Ajax after page load and redirect to PageExpiredErrorPage

Posted by sadko <sa...@gmail.com>.
I don't know but for me it seems some kind of other problem. If I understand
right the veil it should be used to avoid the double clicks and the problems
like that. However what I'm dealing with is that somehow the unfinished ajax
call or the new page call that occurs before its end mess up the page
numbers. If I try to change the number to one lower the link works. So for
page:
https://localhost:8443/my-app/en/home.31

doesn't work link:
https://localhost:8443/my-app/en/?wicket:interface=:31:authPanel:notLoggedLoginPanel:signInContainer:signInPanel:communityLoginContainer:communityLoginItems:0:communityLoginItem::IActivePageBehaviorListener:1:1&wicket:ignoreIfNotActive=true&fbid=xxx&fbsessid=xxx&fbaccesstoken=xxx&random=0.9877056940825386

but works link:

https://localhost:8443/my-app/en/?wicket:interface=:30:authPanel:notLoggedLoginPanel:signInContainer:signInPanel:communityLoginContainer:communityLoginItems:0:communityLoginItem::IActivePageBehaviorListener:1:1&wicket:ignoreIfNotActive=true&fbid=xxx&fbsessid=xxx&fbaccesstoken=xxx&random=0.9877056940825386


By works/doesnt work I mean when I call the link in browser in other tab it
returns some normal response instead of redirect response.

Any suggestions now?
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Automatic-Ajax-after-page-load-and-redirect-to-PageExpiredErrorPage-tp3220405p3221117.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Automatic Ajax after page load and redirect to PageExpiredErrorPage

Posted by sadko <sa...@gmail.com>.
Hi guys,
thanks for answers. The solution to disable links until the ajax is finished
don't seems right to me. The links can be spread through different
components so I don't want to create unnecessary dependencies between these
unless there is one general method that disables all links everywhere at
once and I don't know about it.

I tried the veil, but it doesn't work. Maybe I made something wrong but I
proceeded exactly as in this article:
http://wicketinaction.com/2008/12/preventing-double-ajax-requests-in-3-lines-of-code/#more-302

The method getAjaxIndicatorMarkupId was at lest called to get the ID,
however no positive result. Afterwards I tried to implement the
IAjaxIndicatorAware in Panel and after that even in Behaviors themselves. On
behaviors the getAjaxIndicatorMarkupId wasn't even called. My example
implementation looked like this.

private class AutoLoginBehavior extends AbstractDefaultAjaxBehavior
implements IAjaxIndicatorAware{
	@Override
	public String getAjaxIndicatorMarkupId() {
		return "fb-autologin-veil";
	}

	@Override
	protected void respond(AjaxRequestTarget target) {
		Map<String, String[]> map = ((WebRequestCycle)
RequestCycle.get()).getRequest().getParameterMap();
		
		String uid = map.get("fbid")[0];
		String sessionId = map.get("fbsessid")[0];
		String accessToken = map.get("fbaccesstoken")[0];
		autologin(target, Long.parseLong(uid), sessionId, accessToken);
	}
}

and in markup for Panel I included following:

<div id="fb-autologin-veil"
style="display:none;position:absolute;top:0;left:0;z-index=99999;background-color:black;width:100%;height:100%;color:white">
<h1>Can't touch this</h1>
</div>

The whole block of markup with veils and javascript that calls behaviors is
hidden using css (is part of generated markup, it is just not visible to
user), but I guess that should not be a problem, right?

Any suggestions why the "veil" doesn't work?

Thanks in advance.
Martin
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Automatic-Ajax-after-page-load-and-redirect-to-PageExpiredErrorPage-tp3220405p3220933.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Automatic Ajax after page load and redirect to PageExpiredErrorPage

Posted by sadko <sa...@gmail.com>.
Hi,
so after some time I came down to the problem. And that is the
replaceSession() call before try to login user using his facebook
identification data. Problem occures just when there more then one automatic
Ajax calls on the page and the redirect to PageExpiredErrorPage occures only
when the page reloads after the refresh. The refresh has to abort the first
Ajax call.

If anyone can help I will appreciate, for now I'm leaving this, cause I
cannot find solution, maybe later I'll find something out. The test code
that has worked for me to show the issue is following:

public class Test3Page extends WebPage{
	private final String JAVASCRIPT_TEMPLATE = "function
test${id}(){wicketAjaxGet('${loginCallbackUrl}', function() { }, function()
{ });}; setTimeout(test${id},${timeout});";
	private AbstractDefaultAjaxBehavior ajaxBehavior1;
	private AbstractDefaultAjaxBehavior ajaxBehavior2;
	private WebMarkupContainer mc;
	public Test3Page() {
		mc = new WebMarkupContainer("container");
		add(mc);
		add(JavascriptPackageResource.getHeaderContribution(new
JQueryResourceReference()));
		mc.add(ajaxBehavior1 = new AbstractDefaultAjaxBehavior() {
			
			@Override
			protected void respond(AjaxRequestTarget target) {
				getSession().replaceSession();
			}
		});
		
		mc.add(ajaxBehavior2 = new AbstractDefaultAjaxBehavior() {
			
			@Override
			protected void respond(AjaxRequestTarget target) {}
		});

		add(new BookmarkablePageLink("bookmarkableRefreshLink", Test3Page.class));
		setStatelessHint(true);
	}
	
	@Override
	protected void onBeforeRender() {
		Map<String, String> variables = new HashMap<String, String>();
		variables.put("loginCallbackUrl",
ajaxBehavior1.getCallbackUrl().toString());
		variables.put("id", "1");
		variables.put("timeout", "300");
		String javascript =
MapVariableInterpolator.interpolate(JAVASCRIPT_TEMPLATE, variables);
		Label jsLabel = new Label("automaticAjaxCall1", javascript);
		jsLabel.setEscapeModelStrings(false);
		mc.addOrReplace(jsLabel);
		
		variables = new HashMap<String, String>();
		variables.put("loginCallbackUrl",
ajaxBehavior2.getCallbackUrl().toString());
		variables.put("id", "2");
		variables.put("timeout", "350");
		javascript = MapVariableInterpolator.interpolate(JAVASCRIPT_TEMPLATE,
variables);
		jsLabel = new Label("automaticAjaxCall2", javascript);
		jsLabel.setEscapeModelStrings(false);
		mc.addOrReplace(jsLabel);
		super.onBeforeRender();
	}
}


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.sourceforge.net/">
	<body>
		<wicket:container wicket:id="container">
			<script wicket:id="automaticAjaxCall1" type="text/javascript"></script>
			<script wicket:id="automaticAjaxCall2" type="text/javascript"></script>
		</wicket:container>
		 # refresh link 
		<script type="text/javascript">
		
setTimeout(function(){window.location=jQuery("#refreshLink").attr("href");},320);
		</script>
	</body>
</html>
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Automatic-Ajax-after-page-load-and-redirect-to-PageExpiredErrorPage-tp3220405p3223898.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Automatic Ajax after page load and redirect to PageExpiredErrorPage

Posted by James Carman <ja...@carmanconsulting.com>.
On Sun, Jan 16, 2011 at 11:36 PM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
>
> Could you disable the links until the AJAX is finished?

Or use a veil?

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


Re: Automatic Ajax after page load and redirect to PageExpiredErrorPage

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Sun, Jan 16, 2011 at 3:06 PM, sadko <sa...@gmail.com> wrote:

>
> Hi there,
> I'm struggling with this half a day already and don't know how to fix. I
> have some Facebook javascript SDK calls on a page to get current user's
> facebook id. This calls are of course asynchronous and on completion they
> call my wicket callbacks automatically to process the data. Beside that I
> have a BookmarkablePageLink on the page targeting the home page (logo that
> takes you always home).
>
> The problem is following. If I am on the home page and click the
> Bookmarkable link before the ajax calls are finished the home page is
> refreshed with new page id but the ajax calls returnes following response:
>
> <ajax-response><redirect>../en/?wicket:bookmarkablePage=:org.apache.wicket.markup.html.pages.PageExpiredErrorPage</redirect></ajax-response>
>
> What results in redirect to PageExpired page.
>
> The URL for ajax calls looks like this:
>
> https://localhost:8443/my-app/en/?wicket:interface=:31:authPanel:notLoggedLoginPanel:signInContainer:signInPanel:communityLoginContainer:communityLoginItems:0:communityLoginItem::IActivePageBehaviorListener:1:1&wicket:ignoreIfNotActive=true&fbid=xxx&fbsessid=xxx&fbaccesstoken=xxx&random=0.9877056940825386
>
> Does anyone know what's wrong and what could I do about it? Any help would
> be appreciated.
>
> Thanks,
> Martin
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Automatic-Ajax-after-page-load-and-redirect-to-PageExpiredErrorPage-tp3220405p3220405.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Could you disable the links until the AJAX is finished?

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*