问题
I'm facing some problems using CDATA blocks inside h:outputscripts with MyFaces 2.0... but I don't know exactly if I should avoid using CDATA with JSF2 or if it is because I do things wrong.
Maybe it is because I use many scripts in many Composite components...
The fact is that when I have some composite components that contain scripts with surrounded by CDATA blocks, other scripts in the page doen't work.
Removing CDATAs solves the issue.
Nevertheless I've had an issue where using CDATA blocks made some of my Composite components bug saying a property of the component can't be found on class NamingContainer when trying to render the component using f:ajax render attribute. Here is the workaround.
Removing the CDATA surrounding my scripts solved the problem.
So my question is : am I the only one having troubles with CDATA blocks and JSF2 (MyFaces) ?
回答1:
This is a known issue. See MYFACES-3339 for details. It was already fixed, so you can try the latest code HERE, and it will be included on 2.1.4 and 2.0.10.
回答2:
I can't answer if you're the only one having problems with it. I can at least answer that having JS code plain in a XML file is a poor practice. JS code is not well formed XML. Fiddling with escaping XML-special characters in JS code or putting JS code in CDATA blocks is plain ugly. That it gives troubles in JSF ajax response is in turn a different story. Technically, that would have been a bug in the JSF implementation used. But from the other side on, you're actually practicing a poor practice.
Just put JS code in its own .js
file which you reference by <h:outputScript>
.
<cc:implementation>
<h:outputScript library="foo" name="js/your-cc-script.js" target="head" />
...
</cc:implementation>
来源:https://stackoverflow.com/questions/7956583/jsf2-myfaces-and-cdata-makes-fajax-render-fail