You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "R. Müller" <r....@unicomp-berlin.de> on 2008/01/07 11:58:23 UTC

howto put inline javascript rendered by myfaces&tomahawk into CDATA-section

hallo group,

i'm working with myfaces/tomahawk 1.1.5 & facelets 1.1.3 with tomcat 
5.0.28 and mostly firefox-browsers (2.0.x) and trying to serve 
xhtml-compliant pages. i know that myfaces renders 'only' html 4.01. i'm 
forcing contentType 'text/xml' or 'application/xhtml+xml' by adding the 
contentType-attribute to the 'f:view'-tag :

<f:view contentType="application/xhtml+xml">

most stuff works well. but sometimes firefox gets stuck on not 
well-formed parts of the page, mostly because the rendered 
javascript-code from varoius components is not embedded into a 
CDATA-section - just a plain script-tag :

<script type="text/javascript">

so firefox checks this content as well and gets stuck. i.e. :


		if((typeof target!='undefined') && target != null)
-------------------------------------------------^

from 		
		function oamSubmitForm(formName, linkId, target, params)



is there any control on howto render javascript ? is there an easy way 
to put these parts into CDATA-sections to get well-formed xml-pages ?

thanks a lot

regards

ronald


Re: howto put inline javascript rendered by myfaces&tomahawk into CDATA-section

Posted by David Delbecq <de...@oma.be>.
No, the job of facelets manily stops when the components start rendering 
:) FAceLets is a view handler, it doesn't interfer with generated outptu 
from component. The rendering job of facelet is limited to non jsf parts 
of the template.

En l'instant précis du 08/01/08 10:22, R. Müller s'exprimait en ces termes:
> hi,
>
> thanks for your replies. you're right - modifying the tomahawk sources 
> would be the fastest (in terms of rendering-perfomance) and cleanest 
> way, but i don't like 'custom' libraries for future compatibility.
>
> it has to be done by the project, if it is common position.
>
> so as a workaround, i followed your 2nd suggestion to write a filter. 
> propably much slower, but it works for now and is independent from the 
> libraries.
>
> btw: is there a way to do this with facelets? does facelets build a 
> internal dom-tree of the final web-page ? if so, it would be easy to 
> check the script-parts for CDATA-section and if not found to add this.
>
> regards
>
> ronald
>
>
> David Delbecq schrieb:
>> Yes, for tomahawk parts at least. Most tomahawk component makes call 
>> to AddRessource, using methods like 'insertScript(....)', you could 
>> overrride those methods and recompile your tomahawk. As for myfaces, 
>> most javascript rendering routines are in a few helper classes 
>> (you'll have to dig your self). Same rule applie: change the code, 
>> recompile.
>>> is there an easy way to put these parts into CDATA-sections to get 
>>> well-formed xml-pages ?
>> Your could write a filter that convert
>> <script (.*)>(.*)</script>
>> to
>> <script $1><[CDATA[$2]]></script>
>>
>> Or, as mentionned, patch the myfaces/tomhawk code?
>>
>


-- 
http://www.devlog.be (a belgian developer's logs)



Re: howto put inline javascript rendered by myfaces&tomahawk into CDATA-section

Posted by "R. Müller" <r....@unicomp-berlin.de>.
hi,

thanks for your replies. you're right - modifying the tomahawk sources 
would be the fastest (in terms of rendering-perfomance) and cleanest 
way, but i don't like 'custom' libraries for future compatibility.

it has to be done by the project, if it is common position.

so as a workaround, i followed your 2nd suggestion to write a filter. 
propably much slower, but it works for now and is independent from the 
libraries.

btw: is there a way to do this with facelets? does facelets build a 
internal dom-tree of the final web-page ? if so, it would be easy to 
check the script-parts for CDATA-section and if not found to add this.

regards

ronald


David Delbecq schrieb:
> Yes, for tomahawk parts at least. Most tomahawk component makes call to 
> AddRessource, using methods like 'insertScript(....)', you could 
> overrride those methods and recompile your tomahawk. As for myfaces, 
> most javascript rendering routines are in a few helper classes (you'll 
> have to dig your self). Same rule applie: change the code, recompile.
>> is there an easy way to put these parts into CDATA-sections to get 
>> well-formed xml-pages ?
> Your could write a filter that convert
> <script (.*)>(.*)</script>
> to
> <script $1><[CDATA[$2]]></script>
> 
> Or, as mentionned, patch the myfaces/tomhawk code?
> 

-- 
*****************************************************************
*M-UniComp Verkehrssysteme GmbH
*
*Dipl.-Ing. Ronald Müller
*Softwareentwicklung
*
*Plauener Straße 163-165, Haus 11
*13053 Berlin
*
*fon   : +49 ( 0 ) 30  / 98 31 700 70
*fax   : +49 ( 0 ) 30  / 98 31 700 77
*mobil : +49 ( 0 ) 172 / 93 95 004
*email : r.mueller@unicomp-berlin.de
*web   : www.unicomp-berlin.de
*
*Geschaeftsfuehrer: Andreas Dreher
*Sitz der Gesellschaft: Berlin
*Registergericht: Berlin Amtsgericht Charlottenburg, HRB 35329
*****************************************************************

Re: howto put inline javascript rendered by myfaces&tomahawk into CDATA-section

Posted by David Delbecq <de...@oma.be>.
En l'instant précis du 07/01/08 23:05, simon s'exprimait en ces termes:
>> Your could write a filter that convert
>> <script (.*)>(.*)</script>
>> to
>> <script $1><[CDATA[$2]]></script>
>>
>> Or, as mentionned, patch the myfaces/tomhawk code?
>>     
>
> In HTML, script tags are special, and the content within them is
> effectively automatically escaped. A lot of the myfaces/tomahawk
> components were written assuming this.
>
> It does appear that xhtml treats script tags just like any other tag,
> with no special rules, so CDATA really is necessary:
>   http://www.w3.org/TR/xhtml1/#h-4.8
>
> Patches to fix this would be gratefully received.
>
> Regards,
> Simon
>   
Could be, but JSF specs do not mention xhtml, it only mention HTML4.01 
if i remember well. And since HTML 4.01 is not xml, it has no idea what 
<![CDATA[ means. Only solution could be to have following kind of thing 
generated. However, am not sure XHTML allow it :/ (splitting script in 2 
parts)

<script>
// <![CDATA[
....
// ]]!>

-- 
http://www.devlog.be (a belgian developer's logs)



Re: howto put inline javascript rendered by myfaces&tomahawk into CDATA-section

Posted by simon <si...@chello.at>.
On Mon, 2008-01-07 at 12:10 +0100, David Delbecq wrote:
> En l'instant précis du 07/01/08 11:58, R. Müller s'exprimait en ces termes:
> > hallo group,
> >
> > i'm working with myfaces/tomahawk 1.1.5 & facelets 1.1.3 with tomcat 
> > 5.0.28 and mostly firefox-browsers (2.0.x) and trying to serve 
> > xhtml-compliant pages. i know that myfaces renders 'only' html 4.01. 
> > i'm forcing contentType 'text/xml' or 'application/xhtml+xml' by 
> > adding the contentType-attribute to the 'f:view'-tag :
> >
> > <f:view contentType="application/xhtml+xml">
> >
> > most stuff works well. but sometimes firefox gets stuck on not 
> > well-formed parts of the page, mostly because the rendered 
> > javascript-code from varoius components is not embedded into a 
> > CDATA-section - just a plain script-tag :
> >
> > <script type="text/javascript">
> >
> > so firefox checks this content as well and gets stuck. i.e. :
> >
> >
> >         if((typeof target!='undefined') && target != null)
> > -------------------------------------------------^
> >
> > from        
> >         function oamSubmitForm(formName, linkId, target, params)
> >
> >
> >
> > is there any control on howto render javascript ? 
> Yes, for tomahawk parts at least. Most tomahawk component makes call to 
> AddRessource, using methods like 'insertScript(....)', you could 
> overrride those methods and recompile your tomahawk. As for myfaces, 
> most javascript rendering routines are in a few helper classes (you'll 
> have to dig your self). Same rule applie: change the code, recompile.
> > is there an easy way to put these parts into CDATA-sections to get 
> > well-formed xml-pages ?
> Your could write a filter that convert
> <script (.*)>(.*)</script>
> to
> <script $1><[CDATA[$2]]></script>
> 
> Or, as mentionned, patch the myfaces/tomhawk code?

In HTML, script tags are special, and the content within them is
effectively automatically escaped. A lot of the myfaces/tomahawk
components were written assuming this.

It does appear that xhtml treats script tags just like any other tag,
with no special rules, so CDATA really is necessary:
  http://www.w3.org/TR/xhtml1/#h-4.8

Patches to fix this would be gratefully received.

Regards,
Simon


Re: howto put inline javascript rendered by myfaces&tomahawk into CDATA-section

Posted by David Delbecq <de...@oma.be>.
En l'instant précis du 07/01/08 11:58, R. Müller s'exprimait en ces termes:
> hallo group,
>
> i'm working with myfaces/tomahawk 1.1.5 & facelets 1.1.3 with tomcat 
> 5.0.28 and mostly firefox-browsers (2.0.x) and trying to serve 
> xhtml-compliant pages. i know that myfaces renders 'only' html 4.01. 
> i'm forcing contentType 'text/xml' or 'application/xhtml+xml' by 
> adding the contentType-attribute to the 'f:view'-tag :
>
> <f:view contentType="application/xhtml+xml">
>
> most stuff works well. but sometimes firefox gets stuck on not 
> well-formed parts of the page, mostly because the rendered 
> javascript-code from varoius components is not embedded into a 
> CDATA-section - just a plain script-tag :
>
> <script type="text/javascript">
>
> so firefox checks this content as well and gets stuck. i.e. :
>
>
>         if((typeof target!='undefined') && target != null)
> -------------------------------------------------^
>
> from        
>         function oamSubmitForm(formName, linkId, target, params)
>
>
>
> is there any control on howto render javascript ? 
Yes, for tomahawk parts at least. Most tomahawk component makes call to 
AddRessource, using methods like 'insertScript(....)', you could 
overrride those methods and recompile your tomahawk. As for myfaces, 
most javascript rendering routines are in a few helper classes (you'll 
have to dig your self). Same rule applie: change the code, recompile.
> is there an easy way to put these parts into CDATA-sections to get 
> well-formed xml-pages ?
Your could write a filter that convert
<script (.*)>(.*)</script>
to
<script $1><[CDATA[$2]]></script>

Or, as mentionned, patch the myfaces/tomhawk code?

>
> thanks a lot
>
> regards
>
> ronald


-- 
http://www.devlog.be (a belgian developer's logs)