I am doing this in JavaScript:
function doClick() {
var theValue = document.getElementById("theForm:theField").value;
var theLength = theValue.length;
if( theLength <= 3 ) --> Error
{
alert('Character length too small.');
}
}
And thefield is a JSF component:
<h:form id="theForm">
<h:commandButton id="theField" action="#{theBean.doFunctionA}" onclick="doClick()"/>
When I render this in IE, it show me this error:
Caused by: javax.faces.view.facelets.FaceletException: Error Parsing /viewMetadata/pages/thePage.xhtml: Error Traced[line: 66] The content of elements must consist of well-formed character data or markup.
at org.apache.myfaces.view.facelets.compiler.SAXCompiler.doCompileViewMetadata(SAXCompiler.java:716)
at org.apache.myfaces.view.facelets.compiler.Compiler.compileViewMetadata(Compiler.java:126)
at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory._createViewMetadataFacelet(DefaultFaceletFactory.java:311)
at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.getViewMetadataFacelet(DefaultFaceletFactory.java:394)
at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.getViewMetadataFacelet(DefaultFaceletFactory.java:376)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage._getViewMetadataFacelet(FaceletViewDeclarationLanguage.java:1940)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.access$000(FaceletViewDeclarationLanguage.java:129)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage$FaceletViewMetadata.createMetadataView(FaceletViewDeclarationLanguage.java:2049)
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:161)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
... 52 more
If I replace the error line with this:
if( theLength == '3' || theLength == '2' || theLength == '1')
Then everything is working fine. I don’t really understand what is actually happen?
Given the error message:
It sounds like it’s trying to parse it as XML. You should read up on what escaping you would usually need in JSF, but the first thing to try is just escaping it as XML:
When diagnosing the error, it’s important to realise that this isn’t actually hitting the browser’s Javascript engine – the problem is in generating the page.