You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Khalid EL BOUKHARI <el...@gmail.com> on 2010/11/08 11:36:46 UTC

Do a post with Tapestry and Link

Hi,
I need to do POST in Tapestry for example :

<form method=*"POST"* Action=*"*MyURL*"* name=*"name"*>

            <input type=*HIDDEN* name=*"FirstParam"* id=*"IdFirstParam"*value=
*"*Value*FrstParam"*/>

            <input type=*HIDDEN* name=*"SndParam"* id=*"IdSndParam"* value=*
"*Value*SndParam"*/>

</form>


When I try :


String data = URLEncoder.encode("*FirstParam*", "UTF-8") + "=" +
URLEncoder.encode("*FirstParam*", "UTF-8");
                    data += "&" + URLEncoder.encode("*SndParam*", "UTF-8") +
"=" + URLEncoder.encode("*SndParam"*, "UTF-8");
// Send data
URL url = new URL(*MyURL*);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

But Tapestry tell me that I must use :
java.net.URL, org.apache.tapestry5.Link, org.apache.tapestry5.
StreamResponse

Any one know how to do ?

Thanks in advance

*Khalid.*

Re: Do a post with Tapestry and Link

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 08 Nov 2010 08:36:46 -0200, Khalid EL BOUKHARI  
<el...@gmail.com> wrote:

> Hi,

Hi!

> I need to do POST in Tapestry for example :

Tapestry handles request, doesn't makes them. Use HttpClient for that.


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Do a post with Tapestry and Link

Posted by Khalid EL BOUKHARI <el...@gmail.com>.
Thank you
I'll try that.

Re: Do a post with Tapestry and Link

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 08 Nov 2010 11:01:31 -0200, Khalid EL BOUKHARI  
<el...@gmail.com> wrote:

> Thank you Joost and Thiago,

:)

> May be may question wasn't clear. So what I need that a method return an
> object that make a post with the previous params.

My interpretation was correct. Tapestry (and any other web framwork) don't  
do POST requests, they handle them. You'll need to use HttpClient to do  
that or rethink the logic you're trying to implement.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Do a post with Tapestry and Link

Posted by Khalid EL BOUKHARI <el...@gmail.com>.
Thank you Joost and Thiago,
May be may question wasn't clear. So what I need that a method return an
object that make a post with the previous params.

I hope that is more clear now.

Cheers,
Khalid.

Re: Do a post with Tapestry and Link

Posted by "Joost Schouten (ml)" <jo...@jsportal.com>.
  If I read this correctly you are using an external java program to 
post to a tapestry page. Correct?

The error you are refering to is usually associated with the required 
return type from an event method which you have not shown in your post.

Can you post the page code handeling the POST request? For refference, 
below you will find the onActivate code of a page I use to handle 
external XML POST requests.

Cheers,
Joost

---------- a POST handling page ----------
@OnEvent(value = EventConstants.ACTIVATE)
     private Object activate() throws Exception {

         HttpServletRequest httpServletRequest = 
requestGlobals.getHTTPServletRequest();
         ServletInputStream inputStream = 
httpServletRequest.getInputStream();

         SAXBuilder builder = new SAXBuilder();
         Document xmlRequest = builder.build(inputStream);

         String response = ... build the response xml Document ....


         final ByteArrayInputStream output = new 
ByteArrayInputStream(response.getBytes());

         final StreamResponse streamResponse = new StreamResponse() {

             public String getContentType() {
                 return "text/xml";
             }

             public InputStream getStream() throws IOException {
                 return output;
             }

             public void prepareResponse(Response response) {
             }
         };
         return streamResponse;
     }


On 8/11/10 11:36 AM, Khalid EL BOUKHARI wrote:
> Hi,
> I need to do POST in Tapestry for example :
>
> <form method=*"POST"* Action=*"*MyURL*"* name=*"name"*>
>
>              <input type=*HIDDEN* name=*"FirstParam"* id=*"IdFirstParam"*value=
> *"*Value*FrstParam"*/>
>
>              <input type=*HIDDEN* name=*"SndParam"* id=*"IdSndParam"* value=*
> "*Value*SndParam"*/>
>
> </form>
>
>
> When I try :
>
>
> String data = URLEncoder.encode("*FirstParam*", "UTF-8") + "=" +
> URLEncoder.encode("*FirstParam*", "UTF-8");
>                      data += "&" + URLEncoder.encode("*SndParam*", "UTF-8") +
> "=" + URLEncoder.encode("*SndParam"*, "UTF-8");
> // Send data
> URL url = new URL(*MyURL*);
> URLConnection conn = url.openConnection();
> conn.setDoOutput(true);
> OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
> wr.write(data);
> wr.flush();
>
> But Tapestry tell me that I must use :
> java.net.URL, org.apache.tapestry5.Link, org.apache.tapestry5.
> StreamResponse
>
> Any one know how to do ?
>
> Thanks in advance
>
> *Khalid.*
>


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