firing httprequest multiple times

80 views
Skip to first unread message

karun

unread,
Dec 22, 2011, 6:04:17 PM12/22/11
to Google Web Toolkit
Hi

I have popup panel and it contains 1 hyper link, clicking on hyperlink
i am sending http post request to jsp / servlet in the handler
function of hyperlink.

the problem i am facing is described below,

step 1. suppose i click on hyper link, it sends http post request, i
get the expected result.

step 2. after step 1, if i again click on hyper link 1, it sends 2
http post request at a time and it increases for every click on hyper
link.

once i refresh the page the count begins from 1.

how to over come step 2 behaviour and send only one http request for
every click.

below is the code sample.

hyplink.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
String url = "http://sample.com/some.jsp"
data = "name:name1"
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
URL.encode(url));
builder.setHeader("Content-Type", "application/json");
try {
builder.sendRequest(data, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert("Request Builder Failed");
}
public void onResponseReceived(Request request, Response response)
{
Window.alert("Request Builder succeeded");
}
});
}
catch (RequestException e) {

e.printStackTrace();
}
}
});

NOTE: if sample code contains any syntax error ignore it, every thing
is working fine in actual code.

Thanks
karun

Ed

unread,
Dec 22, 2011, 7:10:39 PM12/22/11
to google-we...@googlegroups.com
> how to over come step 2 behaviour and send only one http request for every click. 
Disable the widget during processing (which sinks/unsinks the click event). 
Hyperlink doesn't have this functionality per default, but you can use an other widget like a button that does have this.
You could extend the HyperLink widget and add a enabled property.
Almost all my widgets implement a HasEnabled interface that have this enabled property per default.

In the OnClick you will call widget.setEnabled(false)
In the OnResponseReceived call you will call setEnabled(true).

Jens

unread,
Dec 22, 2011, 8:26:21 PM12/22/11
to google-we...@googlegroups.com
If you only click once but your code gets executed twice, then you have added two ClickHandler accidently. Probably the method that contains hyperlink.addClickHandler() gets called twice. Put a logging statement before hyperlink.addClickHandler() to see if you accidently attach more than one handler.

-- J.

karun

unread,
Dec 23, 2011, 2:02:37 AM12/23/11
to Google Web Toolkit
Hi Jens,

i have veryfied your suggestion, the logging statement, which is there
in onResponseReceived() gets logged multiple times but the statement
in addClickHandler() gets logged only once.

Thanks
karun

karun

unread,
Dec 23, 2011, 7:37:10 AM12/23/11
to Google Web Toolkit
Hi Ed,

as per your suggestion, i replaced the hyperlink with button. i
disabled it in onclick() and enabled it in OnResponseReceived().

but still the problem persists.

one more thing

there is timer with in the OnResponseReceived() as shown below. which
executes every minutes and calls one more method.
is the timer culprit over here

public void onResponseReceived(Request request, Response response){

Window.alert("Request Builder
succeeded");
t = new Timer(){
public void run()
{
pollBuilder(data,url);
}
};
t.schedule(1000);
}

Thanks
karun

Ed Bras

unread,
Dec 23, 2011, 7:39:43 AM12/23/11
to google-we...@googlegroups.com
Put some breakpoints and you find out where the double action behavior comes from.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


karun

unread,
Dec 23, 2011, 7:42:50 AM12/23/11
to Google Web Toolkit
Hi Ed,

as per your suggestion, i replaced the hyperlink with button. i
disabled it in onclick() and enabled it in OnResponseReceived().

but still the problem persists.

one more thing

there is timer with in the OnResponseReceived() as shown below. which
executes every minutes and calls one more method.
is the timer culprit over here

public void onResponseReceived(Request request, Response response){

Window.alert("Request Builder
succeeded");
t = new Timer(){
public void run()
{
pollBuilder(data,url);
}
};
t.schedule(1000);
}

Thanks
karun

On Dec 23, 5:10 am, Ed <post2edb...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages