You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jacek Bilski <ja...@gmail.com> on 2009/07/08 15:17:53 UTC

Content type of generated page

Hello,

I have a problem with content type of pages generated by MyFaces. I'm 
struggling with proper "hiding" JavaScript in HTML or XML documents. My 
issue is that MyFaces think (I debugged my application running on Tomcat 
6.0.20), that resulting content type will be text/html, so generated 
code looks like this:

<script type="text/javascript"><!--
something here
//--></script>

But Tomcat itself in HTTP headers returns content type as text/xml. In 
that case code should look like:

<script type="text/javascript"><[CDATA[
something here
//]]></script>

My Firefox (3.0, but i tried that in Opera and Konqueror as well), as it 
sees XML document, treats whole script block as comment, so no 
JavaScript code is being defined. That's why, when I use commandLink I 
get "oamSubmitForm is not defined" error.

While debugging Tomcat I also checked what contentType is being set in 
ServletResponseWrapper, and it is text/xml. Whereas in MyFaces in 
HtmlResponseWriterImpl contentType is always set to text/html.

Is there any way to force MyFaces to always assume contentType to be 
text/xml? Where from Myfaces get this value? Can someone help? I'm 
struggling with it two days already.

Best regards

Jacek Bilski

Re: Content type of generated page

Posted by Jacek Bilski <ja...@gmail.com>.
Hi,

OK, so I debugged some more, and here's what I've found.

MyFaces get content type it should prepare based on what browser sent in 
it's "Accept" HTTP header. In my case that states in first place 
"text/html". In HtmlRendererUtils class in method selectContentType 
MyFaces try to match content types sent by browser with those it 
supports. As it supports "text/html", that one is chosen.

On the other hand my every jspx file begins with those three lines:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

When I look in .java files generated based on my .jspx files I see, that 
the first line is this:

response.setContentType("text/xml;charset=UTF-8");

If I add "<jsp:directive.page contentType="text/html; charset=UTF-8"/>" 
somewhere, then browser gets content type as "text/html".

So my two questions:

1. Is there a method to force MyFaces to use "text/xml" (or some other) 
content type?

2. How it is possible, in the first place, that MyFaces use one content 
type, and then whole page is sent with different content type? Whose 
error is that? Because I assume that situation should never happen, and 
I'm going to file a bug report, but I don't have idea yet who should get it.

Regards

Jacek Bilski

Re: Content type of generated page

Posted by Jacek Bilski <ja...@gmail.com>.
Hi,

Richard Yee wrote:
> What suffix are you using for your pages? .jsp, .jspx, .jsf, or .XHTML? 

My files are .jspx, but are send as .jsf.

> You may need to check to see if the suffix you are using has an entry in 
> the server config file.

Which one are you talking about? You mean tomcat/conf/web.xml and 
mime-mapping entries? I tried that file and web.xml in my application, 
but MyFaces still think, that it should render text/html page.

Regards

Jacek Bilski

Re: Content type of generated page

Posted by Richard Yee <ri...@gmail.com>.
What suffix are you using for your pages? .jsp, .jspx, .jsf,  
or .XHTML? You may need to check to see if the suffix you are using  
has an entry in the server config file.

Richard

Sent from my iPhone

On Jul 8, 2009, at 6:17 AM, Jacek Bilski <ja...@gmail.com> wrote:

> Hello,
>
> I have a problem with content type of pages generated by MyFaces.  
> I'm struggling with proper "hiding" JavaScript in HTML or XML  
> documents. My issue is that MyFaces think (I debugged my application  
> running on Tomcat 6.0.20), that resulting content type will be text/ 
> html, so generated code looks like this:
>
> <script type="text/javascript"><!--
> something here
> //--></script>
>
> But Tomcat itself in HTTP headers returns content type as text/xml.  
> In that case code should look like:
>
> <script type="text/javascript"><[CDATA[
> something here
> //]]></script>
>
> My Firefox (3.0, but i tried that in Opera and Konqueror as well),  
> as it sees XML document, treats whole script block as comment, so no  
> JavaScript code is being defined. That's why, when I use commandLink  
> I get "oamSubmitForm is not defined" error.
>
> While debugging Tomcat I also checked what contentType is being set  
> in ServletResponseWrapper, and it is text/xml. Whereas in MyFaces in  
> HtmlResponseWriterImpl contentType is always set to text/html.
>
> Is there any way to force MyFaces to always assume contentType to be  
> text/xml? Where from Myfaces get this value? Can someone help? I'm  
> struggling with it two days already.
>
> Best regards
>
> Jacek Bilski