You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Wouter Zoons <wz...@brutele.be> on 2004/07/13 23:20:53 UTC

HTML taglib: javascript

Hello,
 
I did not find an answer in the archives and did not spot anything in
CVS that solves the issue I am having.
 
I am one of the AndroMDA developers, I wrote the bpm4struts cartridge
that enables users to generate deployable/running Struts applications
from UML without any manual coding.
 
Bpm4Struts supports AFAIK all of Struts' features, but I am having some
difficulty with at least one of them, I am using a Struts 1.2.1 dev
snapshot. 
 
The problem is in the javascript tag from the html taglib; when
rendering validation routines in XHTML mode you might have some thing
like this (XHTML and cdata="true"):
 
<script type="text/javascript">
<![CDATA[
 
. javascript here
 
]]>
</script>
 
this is all fine for XHTML, but the browser's javascript engine does not
seem to like it.. Firefox complains silently (you can check it on the
Javascript console) and IE shows a dialog (unless you unchecked that
option), the problem is that the CDATA is being interpreted as
javascript
 
to make sure the javascript parser does not try to read the CDATA
element we would need to add it into javascript comment like this:
 
<script type="text/javascript">
//<![CDATA[
 
. javascript here
 
//]]>
</script>
 
 
this works fine on both browser and is backwards compatible with most
earlier version.
 
I have tested this on my own machine but personally I would like to see
this in the actual release because it would save me a lot of hassle.
 
I fixed it by opening the JavascriptValidatorTag.java source code:
Method getJavascriptBegin:
sb.append("<![CDATA[\r\n");
sb.append("//<![CDATA[\r\n");
Method getJavascriptEnd:
sb.append("//]]>\r\n");
sb.append("//]]>\r\n");
 
 
there is of course the alternative of having this fix via a boolean
attribute or something on the javascript element itself . just in case
someone really wants it without the comments
 
can someone please let me know if this can be fixed, do I need to submit
a bug for this or can my issue be resolved otherwise ?
 
many thanks
-- Wouter
 
 

RE: HTML taglib: javascript

Posted by Joe Germuska <Jo...@Germuska.com>.
At 12:24 AM +0200 7/14/04, Wouter Zoons wrote:
>Hi Joe,
>
>Yes the content-type is properly set (after some investigation your
>concern crossed my mind too), but I don't think this is the problem
>anyway...
>
>The purpose of the CDATA is to have the XML parser ignore any escape
>characters such as &amp; but unfortunately the javascript parser pickes
>up that same CDATA item and fails to interpret it (that's why the simple
>solution of having javascript comment to have javascript ignore the
>cdata part), please note we are in a <script>...</script> section
>
>I honestly cannot see how this would work without the comment..

Well, if the browser is truly compliant, then there should be no 
separate "javascript parser" that would be confused by the CDATA; the 
browser would pull the text content of the script element after 
processing it as normal XML, which would mean that the CDATA would 
have "disappeared."

However, I did a little googling and see that there are browsers that 
treat XHTML as if it's really more like a kind of HTML, and therefore 
in some cases the comments strategy you suggest is useful.

I would be ok with adding the javascript comments when CDATA is true, 
but it might be worth waiting a day or two to see if any developers 
would consider that not correctly standards-compliant or something. 
Perhaps you could open a Bugzilla ticket 
(http://issues.apache.org/bugzilla/enter_bug.cgi?product=Struts)


>Best regards
>-- Wouter
>
>>  -----Original Message-----
>>  From: Joe Germuska [mailto:Joe@Germuska.com]
>>  Sent: Wednesday, July 14, 2004 12:02 AM
>>  To: Struts Developers List
>>  Subject: Re: HTML taglib: javascript
>>
>>  >this is all fine for XHTML, but the browser's javascript engine does
>not
>>  >seem to like it.. Firefox complains silently (you can check it on the
>>  >Javascript console) and IE shows a dialog (unless you unchecked that
>>  >option), the problem is that the CDATA is being interpreted as
>>  >javascript
>>
>>  Are you sending your pages to the browser with the right content
>>  type?  I believe it would be "application/xhtml+xml"
>>
>>  If your server is identifying that it's sending "text/html" then the
>>  browser might get confused by CDATA.
>>
>>  I haven't used XHTML very extensively, so I may be off here.
>>
>>  Joe
>>
>>  --
>>  Joe Germuska
>>  Joe@Germuska.com
>>  http://blog.germuska.com
>>  "In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn
>>  back; I'll know I'm in the wrong place."
>>      - Carlos Santana
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>>  For additional commands, e-mail: dev-help@struts.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>For additional commands, e-mail: dev-help@struts.apache.org


-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


RE: HTML taglib: javascript

Posted by Wouter Zoons <wz...@brutele.be>.
Hi Joe,

Yes the content-type is properly set (after some investigation your
concern crossed my mind too), but I don't think this is the problem
anyway...

The purpose of the CDATA is to have the XML parser ignore any escape
characters such as &amp; but unfortunately the javascript parser pickes
up that same CDATA item and fails to interpret it (that's why the simple
solution of having javascript comment to have javascript ignore the
cdata part), please note we are in a <script>...</script> section

I honestly cannot see how this would work without the comment..

Best regards
-- Wouter

> -----Original Message-----
> From: Joe Germuska [mailto:Joe@Germuska.com]
> Sent: Wednesday, July 14, 2004 12:02 AM
> To: Struts Developers List
> Subject: Re: HTML taglib: javascript
> 
> >this is all fine for XHTML, but the browser's javascript engine does
not
> >seem to like it.. Firefox complains silently (you can check it on the
> >Javascript console) and IE shows a dialog (unless you unchecked that
> >option), the problem is that the CDATA is being interpreted as
> >javascript
> 
> Are you sending your pages to the browser with the right content
> type?  I believe it would be "application/xhtml+xml"
> 
> If your server is identifying that it's sending "text/html" then the
> browser might get confused by CDATA.
> 
> I haven't used XHTML very extensively, so I may be off here.
> 
> Joe
> 
> --
> Joe Germuska
> Joe@Germuska.com
> http://blog.germuska.com
> "In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn
> back; I'll know I'm in the wrong place."
>     - Carlos Santana
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: HTML taglib: javascript

Posted by Joe Germuska <Jo...@Germuska.com>.
>this is all fine for XHTML, but the browser's javascript engine does not
>seem to like it.. Firefox complains silently (you can check it on the
>Javascript console) and IE shows a dialog (unless you unchecked that
>option), the problem is that the CDATA is being interpreted as
>javascript

Are you sending your pages to the browser with the right content 
type?  I believe it would be "application/xhtml+xml"

If your server is identifying that it's sending "text/html" then the 
browser might get confused by CDATA.

I haven't used XHTML very extensively, so I may be off here.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org