Quantcast

Struts 2 - Action writing to response output stream

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Struts 2 - Action writing to response output stream

Sarr, Nathan
 

Hello,

 

   We are using some actions to write directly to the stream for some
ajax based functionality.  To do this I wrote a

NoOp result type that does nothing.  

 

[code]

public class NoOp extends StrutsResultSupport {

 

 

    public NoOp() {

        super();

    }

 

    protected void doExecute(String finalLocation, ActionInvocation
invocation) throws Exception {

        //no op    

    }

}

 

[/code]

 

 

 

 

This allows the action to write the content using:

 

    response.getOutputStream().write(contents)

 

 

I am looking for best practices.  Is this an acceptable way to do this
or is there a better way to allow an action to return content that I
would like placed as only part of the page?

 

Thanks for the help,

Nathan Sarr

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Struts 2 - Action writing to response output stream

Musachy Barroso
You can just write to the outputstream, and return null from execute, and
you won't need a NoOp result. I also wrote my own NoOp result when i started
using S2 ;). Maybe this should be on the FAQs.

musachy

On 3/30/07, Sarr, Nathan <[hidden email]> wrote:

>
>
>
> Hello,
>
>
>
>    We are using some actions to write directly to the stream for some
> ajax based functionality.  To do this I wrote a
>
> NoOp result type that does nothing.
>
>
>
> [code]
>
> public class NoOp extends StrutsResultSupport {
>
>
>
>
>
>     public NoOp() {
>
>         super();
>
>     }
>
>
>
>     protected void doExecute(String finalLocation, ActionInvocation
> invocation) throws Exception {
>
>         //no op
>
>     }
>
> }
>
>
>
> [/code]
>
>
>
>
>
>
>
>
>
> This allows the action to write the content using:
>
>
>
>     response.getOutputStream().write(contents)
>
>
>
>
>
> I am looking for best practices.  Is this an acceptable way to do this
> or is there a better way to allow an action to return content that I
> would like placed as only part of the page?
>
>
>
> Thanks for the help,
>
> Nathan Sarr
>
>
>
>


--
"Hey you! Would you help me to carry the stone?" Pink Floyd
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Struts 2 - Action writing to response output stream

Sarr, Nathan
Excellent,

   Thanks for the help musachy - much appreciated.

-Nate

-----Original Message-----
From: Musachy Barroso [mailto:[hidden email]]
Sent: Friday, March 30, 2007 10:27 AM
To: Struts Users Mailing List
Subject: Re: Struts 2 - Action writing to response output stream

You can just write to the outputstream, and return null from execute,
and
you won't need a NoOp result. I also wrote my own NoOp result when i
started
using S2 ;). Maybe this should be on the FAQs.

musachy

On 3/30/07, Sarr, Nathan <[hidden email]> wrote:

>
>
>
> Hello,
>
>
>
>    We are using some actions to write directly to the stream for some
> ajax based functionality.  To do this I wrote a
>
> NoOp result type that does nothing.
>
>
>
> [code]
>
> public class NoOp extends StrutsResultSupport {
>
>
>
>
>
>     public NoOp() {
>
>         super();
>
>     }
>
>
>
>     protected void doExecute(String finalLocation, ActionInvocation
> invocation) throws Exception {
>
>         //no op
>
>     }
>
> }
>
>
>
> [/code]
>
>
>
>
>
>
>
>
>
> This allows the action to write the content using:
>
>
>
>     response.getOutputStream().write(contents)
>
>
>
>
>
> I am looking for best practices.  Is this an acceptable way to do this
> or is there a better way to allow an action to return content that I
> would like placed as only part of the page?
>
>
>
> Thanks for the help,
>
> Nathan Sarr
>
>
>
>


--
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Struts 2 - Action writing to response output stream

new2you
Exactly what I was looking for...
returning null was a good practice in Struts 1 when there were no resulttypes, dunno if there's not a better way to do it in S2... One thing one could do is write a null-return method for each kind of byte-result which can be placed in the ActionSupport class so that all the actions can pass a byte-array and/or resulttype to this supporter-method.
On the other hand, this is pretty much what the struts 2 reults do... but the trouble here is passing parameters.
Theoretically speaking(havent tried it yet) I would think that a <Striing, byte[]>-Map in the actionsupport class could be very handy. This way you'd just have to pass a String-key to the result(hardcoded  in the struts.xml), the result gets the actioncontext, gets the Map and eventually the byte[].


Sarr, Nathan wrote
Excellent,

   Thanks for the help musachy - much appreciated.

-Nate

-----Original Message-----
From: Musachy Barroso [mailto:musachy@gmail.com]
Sent: Friday, March 30, 2007 10:27 AM
To: Struts Users Mailing List
Subject: Re: Struts 2 - Action writing to response output stream

You can just write to the outputstream, and return null from execute,
and
you won't need a NoOp result. I also wrote my own NoOp result when i
started
using S2 ;). Maybe this should be on the FAQs.

musachy

On 3/30/07, Sarr, Nathan <nsarr@ur.rochester.edu> wrote:
>
>
>
> Hello,
>
>
>
>    We are using some actions to write directly to the stream for some
> ajax based functionality.  To do this I wrote a
>
> NoOp result type that does nothing.
>
>
>
> [code]
>
> public class NoOp extends StrutsResultSupport {
>
>
>
>
>
>     public NoOp() {
>
>         super();
>
>     }
>
>
>
>     protected void doExecute(String finalLocation, ActionInvocation
> invocation) throws Exception {
>
>         //no op
>
>     }
>
> }
>
>
>
> [/code]
>
>
>
>
>
>
>
>
>
> This allows the action to write the content using:
>
>
>
>     response.getOutputStream().write(contents)
>
>
>
>
>
> I am looking for best practices.  Is this an acceptable way to do this
> or is there a better way to allow an action to return content that I
> would like placed as only part of the page?
>
>
>
> Thanks for the help,
>
> Nathan Sarr
>
>
>
>


--
"Hey you! Would you help me to carry the stone?" Pink Floyd

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