Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-2650

chaining ajax onchange with existing onchange creates syntax error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-beta-3
    • Fix Version/s: 2.0.0
    • Component/s: JSR-314
    • Labels:
      None
    • Environment:
      Javascript

      Description

      combining onchange="alert('test') and <f:ajax render="myTest2" /> creates "missing ) after argument list" when onchagne is triggered

      example:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
      <h:head></h:head>
      <h:body>
      <h:form id="myForm">
      <h:inputText id="myTest1" value="#

      {myBean.test}" onchange="alert('test')">
      <f:ajax render="myTest2" />
      </h:inputText>
      <h:inputText value="#{myBean.test}

      " id="myTest2" />
      </h:form>
      </h:body>
      </html>

      1. MyFaces_Test.war
        2.70 MB
        Ganesh Jung

        Activity

        Hide
        ganesh.jung Ganesh Jung added a comment -

        test case

        Show
        ganesh.jung Ganesh Jung added a comment - test case
        Hide
        werpu Werner Punz added a comment -

        this is clearly a bug in f:ajax, the generated code is:
        jsf.util.chain(document.getElementById('myForm:myTest1'), event,'alert('test')', 'jsf.ajax.request(\'myForm:myTest1\',event,

        {render:\'myForm:myTest2\',\'javax.faces.behavior.event\':\'valueChange\'}

        )');

        it simply does not take into consideration that 'alert('test')' can have single quotes due to embedding javascript for the function here, the quotes need to be javascript escaped by the renderer.

        Show
        werpu Werner Punz added a comment - this is clearly a bug in f:ajax, the generated code is: jsf.util.chain(document.getElementById('myForm:myTest1'), event,'alert('test')', 'jsf.ajax.request(\'myForm:myTest1\',event, {render:\'myForm:myTest2\',\'javax.faces.behavior.event\':\'valueChange\'} )'); it simply does not take into consideration that 'alert('test')' can have single quotes due to embedding javascript for the function here, the quotes need to be javascript escaped by the renderer.
        Hide
        jakobkorherr Jakob Korherr added a comment -

        This issue is fixed. I just added escaping in buildBehaviorChain() to the userEventCode.

        However this problem brought me to another issue: double escaping! Things like this won't work: new Function('myFunc', 'alert(\'test\');'). I'll create a new issue for this!

        Show
        jakobkorherr Jakob Korherr added a comment - This issue is fixed. I just added escaping in buildBehaviorChain() to the userEventCode. However this problem brought me to another issue: double escaping! Things like this won't work: new Function('myFunc', 'alert(\'test\');'). I'll create a new issue for this!

          People

          • Assignee:
            jakobkorherr Jakob Korherr
            Reporter:
            ganesh.jung Ganesh Jung
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development