You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Whitehurst <dl...@gmail.com> on 2009/05/13 02:22:53 UTC

Using PUT with REST Plugin

Can someone show me using my example of how to use the PUT feature of
the REST Plugin.  I'll provide my example that doesn't work.  I need
to know if I'm setting this up correctly using GWT.  I can't get it to
work.  The Confluence showed id=Thrillers so I've also tried
&id=customers and that didn't work either.  I'm using the REST Plugin
on top of AppFuse for DAO and service managers.  I use RequestBuilder
in a static class to GET and POST.  The GET part works fine.

private static String EDIT_CUSTOMER_URL =
"http://localhost/service/json/customers/";

private void postEdit() {
        formCustomer.setId(CustomerTable.getSelectedCustomer().getId());
        String url = EDIT_CUSTOMER_URL;
        //url = url.concat(formCustomer.getId());

        StringBuffer postData = new StringBuffer();

        postData.append("_method=").append(URL.encodeComponent("put"));
        postData.append("&id").append(URL.encodeComponent(formCustomer.getId()));

        postData.append("&name=");
        postData.append(URL.encodeComponent(formCustomer.getName()));

        postData.append("&phone=");
        postData.append(URL.encodeComponent(formCustomer.getPhone()));

        Window.alert("Getting ready to post: " + postData.toString() +
" " + url );

        // POST
        RequestUtils.submitPost(url, postData);
        restoreCustomerDetailPanel();
    }

Thanks

David

--
David L. Whitehurst
http://www.capehenrytech.com … Providing software instruction through
a sea of Technology.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts 2] Disabled fields are not posted on form submission

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Are you sure that you really want to disable it? Can you use a hidden
field, or hide the field with css, if you're just trying to hide it
from the user?

Nils-H

On Wed, May 13, 2009 at 11:28 AM, Fernandes Celinio
<cf...@sopragroup.com> wrote:
> Hi,
>
> Disabled fields by W3 specifications will not get posted on form
> submission (http://www.w3.org/TR/html4/interact/forms.html#h-17.12.1).
>
>        <s:textfield
>                        key="Label_DateCreation"
>                        id="dateCreation"
>                        name="dateCreation"
>                        labelposition="left"
>                        maxlength="30"
>                        required="true"
>                        disabled="%{fieldDisabled}"
>        />
>
> In my case, the textfield "dateCreation" has a "disabled" attribute set
> to true (fieldDisabled is set to true).
>
> How do i submit the value of a disabled text field ?
> Is there an interceptor that already takes care of it in Struts 2 ?
>
> Thanks for helping.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts 2] Disabled fields are not posted on form submission

Posted by Dale Newfield <da...@newfield.org>.
Or just create an onsubmit function that de-disables the appropriate 
fields before submission.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts 2] Disabled fields are not posted on form submission

Posted by Dave Newton <ne...@yahoo.com>.
Fernandes Celinio wrote:
> I wanted to know if a built-in solution existed with Struts 2.

Nope, nothing in Struts 2 will change the HTML spec or how browsers are 
implemented.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [Struts 2] Disabled fields are not posted on form submission

Posted by Fernandes Celinio <cf...@sopragroup.com>.
Ok, thanks.
I was thinking about using hidden fields indeed. I wanted to know if a built-in solution existed with Struts 2.

-----Message d'origine-----
De : Lukasz Lenart [mailto:lukasz.lenart@googlemail.com] 
Envoyé : mercredi 13 mai 2009 11:55
À : Struts Users Mailing List
Objet : Re: [Struts 2] Disabled fields are not posted on form submission

2009/5/13 Fernandes Celinio <cf...@sopragroup.com>:
> How do i submit the value of a disabled text field ?
> Is there an interceptor that already takes care of it in Struts 2 ?

By HTML spec, disabled fields aren't send to a server, it isn't Struts issue but general rule. You can consider to use readOnly attribute or use hidden fields


Regards
--
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts 2] Disabled fields are not posted on form submission

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/13 Fernandes Celinio <cf...@sopragroup.com>:
> How do i submit the value of a disabled text field ?
> Is there an interceptor that already takes care of it in Struts 2 ?

By HTML spec, disabled fields aren't send to a server, it isn't Struts
issue but general rule. You can consider to use readOnly attribute or
use hidden fields


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[Struts 2] Disabled fields are not posted on form submission

Posted by Fernandes Celinio <cf...@sopragroup.com>.
Hi,

Disabled fields by W3 specifications will not get posted on form
submission (http://www.w3.org/TR/html4/interact/forms.html#h-17.12.1). 

	<s:textfield
			key="Label_DateCreation"
			id="dateCreation"
			name="dateCreation"
			labelposition="left"
			maxlength="30"
			required="true"
			disabled="%{fieldDisabled}"
	/>

In my case, the textfield "dateCreation" has a "disabled" attribute set
to true (fieldDisabled is set to true).

How do i submit the value of a disabled text field ?
Is there an interceptor that already takes care of it in Struts 2 ?

Thanks for helping.




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Using PUT with REST Plugin

Posted by Stuart Ellidge <st...@adaptris.com>.
Hi David,

Here is how we construct a URL in our JSP:

<form action="${basketDetailUrl}/${status.index}?_method=PUT" method="post">

So the key differences are:

 *   ID is part of the main body of the URL - not a parameter
 *   we use PUT as opposed to "put" (not sure it makes any difference, but haven't tested lowercase)
 *   _method is a URL parameter - not a form object

I'm guessing in your instance you will need something along the lines of:

http://localhost/service/json/customers/id?_method=PUT

This type of URL works nicely for us with JSON urls too (I noticed that your URL contains a JSON context):

${pageContext.request.contextPath}/product-quantity/" + friendlyCode + ".json?_method=PUT

Regards
Stuart

On 13/05/2009 01:22, "David Whitehurst" <dl...@gmail.com> wrote:

Can someone show me using my example of how to use the PUT feature of
the REST Plugin.  I'll provide my example that doesn't work.  I need
to know if I'm setting this up correctly using GWT.  I can't get it to
work.  The Confluence showed id=Thrillers so I've also tried
&id=customers and that didn't work either.  I'm using the REST Plugin
on top of AppFuse for DAO and service managers.  I use RequestBuilder
in a static class to GET and POST.  The GET part works fine.

private static String EDIT_CUSTOMER_URL =
"http://localhost/service/json/customers/";

private void postEdit() {
        formCustomer.setId(CustomerTable.getSelectedCustomer().getId());
        String url = EDIT_CUSTOMER_URL;
        //url = url.concat(formCustomer.getId());

        StringBuffer postData = new StringBuffer();

        postData.append("_method=").append(URL.encodeComponent("put"));
        postData.append("&id").append(URL.encodeComponent(formCustomer.getId()));

        postData.append("&name=");
        postData.append(URL.encodeComponent(formCustomer.getName()));

        postData.append("&phone=");
        postData.append(URL.encodeComponent(formCustomer.getPhone()));

        Window.alert("Getting ready to post: " + postData.toString() +
" " + url );

        // POST
        RequestUtils.submitPost(url, postData);
        restoreCustomerDetailPanel();
    }

Thanks

David

--
David L. Whitehurst
http://www.capehenrytech.com ... Providing software instruction through
a sea of Technology.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org