How set Content-type during runtime in jsf

I need to set Content-type of the output jsp during runtime, because output can be either html or wml and have specific endoding

I tried this way:

// jsf action method

public String showPreview (){

HttpServletResponse response = (HttpServletResponse) getFacesContext().getExternalContext().getResponse();

try{

response.setContentType(getCurrentSite().getContentType());

}catch (CmsOperationException e){

// TODO Auto-generated catch block

e.printStackTrace();

}

return PREVIEW_CASE;

}

but this is overriden later as during execution of the jsp page the response have content-type "text/hml" , which is the default value.

I could probably do it with a scriptlet on the jsp page. Isn't there a more elegant solution?

[1160 byte] By [glowia] at [2007-11-27 2:36:46]
# 1
Don't set the contenttype in the JSP page itself.
BalusCa at 2007-7-12 2:56:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I don't know what you mean exactly. But the output jsp page doesn't contain any page directive that sets content-type.

the jsp page content:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>

<h:outputText escape="false" value="#{livePreviewBean.pageContent}" />

</f:view>

Message was edited by:

glowi

glowia at 2007-7-12 2:56:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...