Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-15617

<st:bind> does not work inside <l:ajax>

    XMLWordPrintable

Details

    Description

      The contents of the bind expression, and any further contents of your <script>, are dumped outside of any script block and appear as plain text in the web page.

      Adding <st:adjunct includes="org.kohsuke.stapler.bind"/> first solves that problem, but now your <script> block is not run at all.

      Attachments

        Issue Links

          Activity

            jglick Jesse Glick added a comment -

            …since as per http://stackoverflow.com/questions/4619668/executing-script-inside-div-retrieved-by-ajax scripts included in dynamically inserted content are not executed. You can work around this in general by using a st:adjunct of your own JavaScript, but this cannot work when st:bind has to produce part of that JavaScript since an adjunct is static.

            jglick Jesse Glick added a comment - …since as per http://stackoverflow.com/questions/4619668/executing-script-inside-div-retrieved-by-ajax scripts included in dynamically inserted content are not executed. You can work around this in general by using a st:adjunct of your own JavaScript, but this cannot work when st:bind has to produce part of that JavaScript since an adjunct is static.
            jglick Jesse Glick added a comment -

            Demo: hpi:run; create job; add demo builder; click Test; nothing happens. Save job (with builder), Configure again; now Test works.

            jglick Jesse Glick added a comment - Demo: hpi:run ; create job; add demo builder; click Test; nothing happens. Save job (with builder), Configure again; now Test works.
            jglick Jesse Glick added a comment -

            The latter problem is not quite true: <script> is run but in a nonglobal context so any definitions must be prefixed with window. in order to be accessible later.

            jglick Jesse Glick added a comment - The latter problem is not quite true: <script> is run but in a nonglobal context so any definitions must be prefixed with window. in order to be accessible later.

            Code changed in jenkins
            User: Kohsuke Kawaguchi
            Path:
            war/src/main/webapp/scripts/hudson-behavior.js
            http://jenkins-ci.org/commit/jenkins/51f508ba371ee222dced304c4a77a9b1b4ca37db
            Log:
            [FIXED JENKINS-15617]

            Evaluate script in global context.
            See http://perfectionkills.com/global-eval-what-are-the-options/ for how
            to evaluate JavaScript in global context.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: war/src/main/webapp/scripts/hudson-behavior.js http://jenkins-ci.org/commit/jenkins/51f508ba371ee222dced304c4a77a9b1b4ca37db Log: [FIXED JENKINS-15617] Evaluate script in global context. See http://perfectionkills.com/global-eval-what-are-the-options/ for how to evaluate JavaScript in global context.
            jglick Jesse Glick added a comment -

            <st:adjunct assumes="org.kohsuke.stapler.framework.prototype.prototype" includes="org.kohsuke.stapler.bind"/> is actually necessary as the workaround for the first part; otherwise you sometimes get errors in the page like Cannot call method 'select' of undefined since Prototype exists but has no member Selector.

            jglick Jesse Glick added a comment - <st:adjunct assumes="org.kohsuke.stapler.framework.prototype.prototype" includes="org.kohsuke.stapler.bind"/> is actually necessary as the workaround for the first part; otherwise you sometimes get errors in the page like Cannot call method 'select' of undefined since Prototype exists but has no member Selector .
            jglick Jesse Glick added a comment -

            Simpler still: <st:adjunct assumes="org.kohsuke.stapler.bind"/>

            jglick Jesse Glick added a comment - Simpler still: <st:adjunct assumes="org.kohsuke.stapler.bind"/>

            Code changed in jenkins
            User: Kohsuke Kawaguchi
            Path:
            war/src/main/webapp/scripts/hudson-behavior.js
            http://jenkins-ci.org/commit/jenkins/5aca73f1831f7895220e7c869cfb13e6c2db131a
            Log:
            JENKINS-15617

            This needs to be eval, not geval.
            Plus I forgot to return the value.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: war/src/main/webapp/scripts/hudson-behavior.js http://jenkins-ci.org/commit/jenkins/5aca73f1831f7895220e7c869cfb13e6c2db131a Log: JENKINS-15617 This needs to be eval, not geval. Plus I forgot to return the value.
            dogfood dogfood added a comment -

            Integrated in jenkins_main_trunk #2029
            [FIXED JENKINS-15617] (Revision 51f508ba371ee222dced304c4a77a9b1b4ca37db)

            Result = UNSTABLE
            kohsuke : 51f508ba371ee222dced304c4a77a9b1b4ca37db
            Files :

            • war/src/main/webapp/scripts/hudson-behavior.js
            dogfood dogfood added a comment - Integrated in jenkins_main_trunk #2029 [FIXED JENKINS-15617] (Revision 51f508ba371ee222dced304c4a77a9b1b4ca37db) Result = UNSTABLE kohsuke : 51f508ba371ee222dced304c4a77a9b1b4ca37db Files : war/src/main/webapp/scripts/hudson-behavior.js
            dogfood dogfood added a comment -

            Integrated in jenkins_main_trunk #2030
            JENKINS-15617 (Revision 5aca73f1831f7895220e7c869cfb13e6c2db131a)

            Result = UNSTABLE
            kohsuke : 5aca73f1831f7895220e7c869cfb13e6c2db131a
            Files :

            • war/src/main/webapp/scripts/hudson-behavior.js
            dogfood dogfood added a comment - Integrated in jenkins_main_trunk #2030 JENKINS-15617 (Revision 5aca73f1831f7895220e7c869cfb13e6c2db131a) Result = UNSTABLE kohsuke : 5aca73f1831f7895220e7c869cfb13e6c2db131a Files : war/src/main/webapp/scripts/hudson-behavior.js
            jglick Jesse Glick added a comment -

            51f508b breaks config page loading in IE 8 on XP.

            jglick Jesse Glick added a comment - 51f508b breaks config page loading in IE 8 on XP.
            jglick Jesse Glick added a comment -
            diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js
            index c88fc9f..4eb41b7 100644
            --- a/war/src/main/webapp/scripts/hudson-behavior.js
            +++ b/war/src/main/webapp/scripts/hudson-behavior.js
            @@ -500,7 +500,7 @@ function isInsideRemovable(e) {
              */
             function renderOnDemand(e,callback,noBehaviour) {
                 if (!e || !Element.hasClassName(e,"render-on-demand")) return;
            -    var proxy = geval(e.getAttribute("proxy"));
            +    var proxy = eval(e.getAttribute("proxy"));
                 proxy.render(function (t) {
                     var contextTagName = e.parentNode.tagName;
                     var c;
            

            seems to fix it. Why is geval being used so widely?

            jglick Jesse Glick added a comment - diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index c88fc9f..4eb41b7 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -500,7 +500,7 @@ function isInsideRemovable(e) { */ function renderOnDemand(e,callback,noBehaviour) { if (!e || !Element.hasClassName(e, "render-on-demand" )) return ; - var proxy = geval(e.getAttribute( "proxy" )); + var proxy = eval(e.getAttribute( "proxy" )); proxy.render(function (t) { var contextTagName = e.parentNode.tagName; var c; seems to fix it. Why is geval being used so widely?

            The idea behind geval is not to let evaluated script to access local in-scope variables as well as letting them put stuff into global scope, so I think it's sound to prefer geval as much as possible.

            Now, it turns out execScript always return null which means it can't be used at all where we need the return value.

            The next step is, who said eval on IE is broken? On my IE8 in the standards mode, "window.eval" seems to work as expected. MSDN backs me up and claims it has been there since IE6.

            kohsuke Kohsuke Kawaguchi added a comment - The idea behind geval is not to let evaluated script to access local in-scope variables as well as letting them put stuff into global scope, so I think it's sound to prefer geval as much as possible. Now, it turns out execScript always return null which means it can't be used at all where we need the return value. The next step is, who said eval on IE is broken? On my IE8 in the standards mode, "window.eval" seems to work as expected. MSDN backs me up and claims it has been there since IE6.

            Code changed in jenkins
            User: Kohsuke Kawaguchi
            Path:
            war/src/main/webapp/scripts/hudson-behavior.js
            http://jenkins-ci.org/commit/jenkins/1c578ab5542bd20904c4a5e4ebcc80b42af31bbb
            Log:
            [FIXED JENKINS-15617]

            execScript cannot return value [1], so I'm restricting its use to where
            we don't care about the return value. See ticket for more discussions

            [1] http://msdn.microsoft.com/en-us/library/ie/ms536420(v=vs.85).aspx

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Kohsuke Kawaguchi Path: war/src/main/webapp/scripts/hudson-behavior.js http://jenkins-ci.org/commit/jenkins/1c578ab5542bd20904c4a5e4ebcc80b42af31bbb Log: [FIXED JENKINS-15617] execScript cannot return value [1] , so I'm restricting its use to where we don't care about the return value. See ticket for more discussions [1] http://msdn.microsoft.com/en-us/library/ie/ms536420(v=vs.85).aspx
            dogfood dogfood added a comment -

            Integrated in jenkins_main_trunk #2037
            [FIXED JENKINS-15617] (Revision 1c578ab5542bd20904c4a5e4ebcc80b42af31bbb)

            Result = UNSTABLE
            kohsuke : 1c578ab5542bd20904c4a5e4ebcc80b42af31bbb
            Files :

            • war/src/main/webapp/scripts/hudson-behavior.js
            dogfood dogfood added a comment - Integrated in jenkins_main_trunk #2037 [FIXED JENKINS-15617] (Revision 1c578ab5542bd20904c4a5e4ebcc80b42af31bbb) Result = UNSTABLE kohsuke : 1c578ab5542bd20904c4a5e4ebcc80b42af31bbb Files : war/src/main/webapp/scripts/hudson-behavior.js

            People

              kohsuke Kohsuke Kawaguchi
              jglick Jesse Glick
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: