On Fri, Nov 14, 2008 at 8:34 AM, jake H <[EMAIL PROTECTED]> wrote:
>
> Hello ,
> I m trying to implement Rest 'commands' , like PUT or DELETE with
> RequestBuilder.
> As much as i read, i saw that we can avoid them by using POST and
> modifying the header. Can someone share an example?

This is what I have:

  private void doPut(String url, String encodedPostData) {
    try {
      RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
url+"?_method=PUT");
      builder.setHeader("Content-Type", FormPanel.ENCODING_URLENCODED);
      DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "progress");
      builder.sendRequest(encodedPostData, this);
    } catch (RequestException e) {
      GWT.log( "error", e);
      e.printStackTrace();
      DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "");
    }
  }


  public void doDelete(String url, RESTRequestCallback restCallback) {
    this.restCallback = restCallback;
    try {
      RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
url+"?_method=DELETE");
      builder.setHeader("Content-Type", FormPanel.ENCODING_URLENCODED);

      /*
       * The foo,bar here is so we don't send an empty POST request. There
       * is a bug in firebug and/or nginx where it responds with a 411
       * when an empty post is sent.
       *
       * I haven't experimented with moving the _method=DELETE into the params
       * or only adding this if the encodedParams array is null. There are
       * probably better ways to fix this, but for now, this works.
       */
      DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "progress");
      builder.sendRequest(encodeParams(new String[] { "foo", "bar"} ), this);
    } catch (RequestException e) {
      GWT.log("error", e);
      e.printStackTrace();
      DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "");
    }
  }

>
> Secondly i came accross with this
>
> public class DeleteRequestBuilder extends RequestBuilder {
>    public DeleteRequestBuilder(String url) {
>     super("DELETE", url);
>
>  }
> }
>
>
> In manning's book GWT in Practice. Any idea how it can be used?
>
> Something like that?
>
> DeleteRequestBuilder requestBuilder = new DeleteRequestBuilder(url);
>    try {
>     //data
>      requestBuilder.sendRequest(data_to_deleted?, new
> ResponseTextHandler());
>   ..
> ....
>
>
>
>
> >
>



-- 
Jim Freeze

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to