2012-11-08 75 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