Custom JSF component: Using "startElement" with "script" results in a comment -


i'm rendering custom jsf component. in method encodebegin want include java script.

public void encodebegin(facescontext context) throws ioexception {    responsewriter writer = context.getresponsewriter();    writer.startelement("script", this);    writer.writeattribute("type", "text/javascript", null);    writer.writetext("var width=400",null);    writer.endelement("script"); } 

when rendering component content of script tag commented out.

<script type="text/javascript"><!-- var width=400; //--></script> 

can explain why comment appears , how rid of it?

thanks in advance!

this specific myfaces implementation, not jsf specification. mojarra implementation doesn't that.

this approach of putting javascript body in html comment leftover of html prehistory when browsers existed doesn't support <script> elements. html comments hides javascript content prevent ancient html parsers interpreting , displaying javascript code plain text.

see mozilla developer network - writing javascript xhtml:

this common practice in html, hide scripts browsers not capable of js. in age of xml comments intended: comments. before processing file, comments stripped document, enclosing script in them throwing lunch in piranha pool. moreover, there's no point commenting out scripts -- no browser written in last ten years display code on page.

note last sentence, true, no single browser developed in last decade anymore. myfaces apparently bit overzealously assuming 1 still using such prehistoric browser nowadays.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -