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

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

    Details

    • Similar Issues:

      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

            Hide
            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.

            Show
            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.
            Hide
            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.

            Show
            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.
            Hide
            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.

            Show
            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.
            Hide
            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.

            Show
            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.
            Hide
            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.

            Show
            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 .
            Hide
            jglick Jesse Glick added a comment -

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

            Show
            jglick Jesse Glick added a comment - Simpler still: <st:adjunct assumes="org.kohsuke.stapler.bind"/>
            Hide
            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.

            Show
            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.
            Hide
            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
            Show
            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
            Hide
            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
            Show
            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
            Hide
            jglick Jesse Glick added a comment -

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

            Show
            jglick Jesse Glick added a comment - 51f508b breaks config page loading in IE 8 on XP.
            Hide
            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?

            Show
            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?
            Hide
            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.

            Show
            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.
            Hide
            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

            Show
            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
            Hide
            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
            Show
            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

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

                Dates

                • Created:
                  Updated:
                  Resolved: