2012-11-08 134 views
0

我在JavaScript这样做:JavaScript是否支持<=运算符?

function doClick() { 
    var theValue = document.getElementById("theForm:theField").value; 
    var theLength = theValue.length; 

    if(theLength <= 3) --> Error 
    { 
    alert('Character length too small.'); 
    } 
} 

而且thefield的JSF组件:

<h:form id="theForm"> 
    <h:commandButton id="theField" action="#{theBean.doFunctionA}" onclick="doClick()"/> 

当我使这个在IE中,它告诉我这个错误:

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(theLength == '3' || theLength == '2' || theLength == '1') 

然后一切工作正常。我真的不明白究竟发生了什么?

+0

操作员应该工作得很好。 1.你确定这就是66线上的所有东西吗? 2.是否有隐藏的字符(可能是你在那里复制/粘贴的东西?) – sachleen

+0

如果你这样做会发生什么:'if(theLength =='3'|| theLength =='2'|| theLength =='1 '|| theLength =='0')'? – Sheena

回答

4

提供的错误消息:

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. 

这听起来像它试图解析为XML。你应该在什么逃脱你通常会在JSF需要读了,但的第一件事尝试只是逃避它作为XML:

if (theLength &lt;= 3) 

当诊断错误,但要认识到这是不是很重要实际上击中浏览器的Javascript引擎 - 问题是在生成页面。

+0

哦,伙计!这不是一个笑话。但它的工作! – huahsin68