On 2014-07-11 22:28, Mike McNally wrote:
> I'm noticing that I can't set HTTP response headers from code that's 
> in a <layout-defiinition> when it's invoked. Debugging a little (I 
> wrote a little tag class to experiment) I note that I can successfully 
> call "setHeader" or "setContentType", but they have no apparent 
> effect; immediately calling "getContentType" on the Response object 
> returns a different string than passed to "setContentType".
>
> When that code runs, it's using a wrapped version of the 
> ServletResponse. From outside the context of a Stripes layout, that 
> test tag works just fine.
>
> Is this a situation that I should expect? Is there any way around 
> that? I need to set the content type inside a layout because that's 
> where the need for it is determined (it's deciding between JSON and HTML).
>

Rewrite your code so you decide the content type in your ActionBean. In 
the MVC model the view (resolution) should only display your model, the 
controller (actionbean) should decide which view to use.

For JSON I usually return a Resolution like:

   new StreamingResolution("application/json", new 
StringReader(json.toString(4)));

Matthijs


------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck&#174;
Code Sight&#153; - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to