You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by msalman <mo...@yahoo.com> on 2014/10/21 07:37:19 UTC
Re: Handling page refresh or redirect when the server reboots
Sebastian, thanks for your response and idea.
Taking your idea myproject.zip
<http://apache-wicket.1842946.n4.nabble.com/file/n4667990/myproject.zip> I
am trying to use the following javascript code in wicket:
Http.Get = function(theUrl)
{
var xmlHttp = null;
try
{
xmlHttp = new XMLHttpRequest();
return xmlHttp.open("GET", theUrl, true );
xmlHttp.send();
return xmlHttp.statusText;
//return xmlHttp.responseText;
}
catch (error)
{
return 'error in my code: ' + error;
}
}
The above code is called via:
add(new AjaxLink("link")
{
@Override
public void onClick(AjaxRequestTarget target)
{
target.add(testLabel);
}
@Override
protected IAjaxCallDecorator getAjaxCallDecorator()
{
return new IAjaxCallDecorator()
{
private static final long serialVersionUID = 1L;
public CharSequence decorateScript(
Component component,
CharSequence script)
{
return "document.getElementById('testlabel').innerHTML = 'plain ' +
Http.Get('http://www.cnn.com') ;" + script;
}
public CharSequence decorateOnSuccessScript(
Component component,
CharSequence script)
{
return "document.getElementById('testlabel').innerHTML = 'on success '
+ Http.Get('http://www.cnn.com') ;" + script;
}
public CharSequence decorateOnFailureScript(
Component component,
CharSequence script)
{
return "document.getElementById('testlabel').innerHTML = 'on Failure '
+ Http.Get('http://www.cnn.com') ;" + script;
}
};
}
});
The problem is that when I use it in wicket the xmlHttp.statusText or
xmlHttp.responseText returns nothing.
Can any one please tell me what I might be doing wrong?
Does the code or calling it even makes sense?
I am attaching quickstart project. Please see:
com.mytest.javascript.*
Thanks.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465p4667990.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: Handling page refresh or redirect when the server reboots
Posted by msalman <mo...@yahoo.com>.
myproject.zip
<http://apache-wicket.1842946.n4.nabble.com/file/n4668210/myproject.zip>
I finally got it working. And just in case some one needs to do something
similar I am attaching the proof of concept project. Any feedback would be
highly appreciated.
Thanks to Sebastian and Martin for their inputs.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465p4668210.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: Handling page refresh or redirect when the server reboots
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
HttpXmlRequest is asynchronous by default.
It is not finished by the time you return from your function.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Tue, Oct 21, 2014 at 8:37 AM, msalman <mo...@yahoo.com> wrote:
> Sebastian, thanks for your response and idea.
>
>
> Taking your idea myproject.zip
> <http://apache-wicket.1842946.n4.nabble.com/file/n4667990/myproject.zip>
> I
> am trying to use the following javascript code in wicket:
>
>
>
> Http.Get = function(theUrl)
> {
> var xmlHttp = null;
> try
> {
> xmlHttp = new XMLHttpRequest();
> return xmlHttp.open("GET", theUrl, true );
> xmlHttp.send();
> return xmlHttp.statusText;
> //return xmlHttp.responseText;
> }
> catch (error)
> {
> return 'error in my code: ' + error;
> }
> }
>
>
> The above code is called via:
>
> add(new AjaxLink("link")
> {
>
>
> @Override
> public void onClick(AjaxRequestTarget target)
> {
> target.add(testLabel);
> }
>
>
> @Override
> protected IAjaxCallDecorator getAjaxCallDecorator()
> {
> return new IAjaxCallDecorator()
> {
> private static final long
> serialVersionUID = 1L;
>
> public CharSequence decorateScript(
> Component component,
> CharSequence script)
> {
> return
> "document.getElementById('testlabel').innerHTML = 'plain ' +
> Http.Get('http://www.cnn.com') ;" + script;
> }
>
>
> public CharSequence
> decorateOnSuccessScript(
> Component component,
> CharSequence script)
> {
> return
> "document.getElementById('testlabel').innerHTML = 'on success '
> + Http.Get('http://www.cnn.com') ;" + script;
> }
>
>
> public CharSequence
> decorateOnFailureScript(
> Component component,
> CharSequence script)
> {
> return
> "document.getElementById('testlabel').innerHTML = 'on Failure '
> + Http.Get('http://www.cnn.com') ;" + script;
> }
> };
> }
>
> });
>
>
> The problem is that when I use it in wicket the xmlHttp.statusText or
> xmlHttp.responseText returns nothing.
> Can any one please tell me what I might be doing wrong?
> Does the code or calling it even makes sense?
>
> I am attaching quickstart project. Please see:
> com.mytest.javascript.*
>
>
> Thanks.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Handling-page-refresh-or-redirect-when-the-server-reboots-tp4667465p4667990.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
>
>