diff --git a/core/pom.xml b/core/pom.xml index 29f777bab8..e8cf323005 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -382,7 +382,7 @@ THE SOFTWARE. org.kohsuke.stapler stapler-jelly - 1.155 + 1.157 commons-jelly diff --git a/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/JavaScriptProxy.java b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/JavaScriptProxy.java new file mode 100644 index 0000000000..33a90f6d54 --- /dev/null +++ b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/JavaScriptProxy.java @@ -0,0 +1,32 @@ +package hudson.plugins.ui_samples; + +import hudson.Extension; +import org.kohsuke.stapler.bind.JavaScriptMethod; + +/** + * "Export" Java objects to JavaScript in the browser as a proxy object, so that + * you can make ajax-calls to the server later. + * + * @author Kohsuke Kawaguchi + */ +@Extension +public class JavaScriptProxy extends UISample { + private int i; + + @Override + public String getDescription() { + return "Use JavaScript proxy objects to access server-side Java objects from inside the browser."; + } + + /** + * The annotation exposes this method to JavaScript proxy. + */ + @JavaScriptMethod + public int increment(int n) { + return i+=n; + } + + @Extension + public static final class DescriptorImpl extends UISampleDescriptor { + } +} diff --git a/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/JavaScriptProxy/index.jelly b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/JavaScriptProxy/index.jelly new file mode 100644 index 0000000000..7192bbca48 --- /dev/null +++ b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/JavaScriptProxy/index.jelly @@ -0,0 +1,45 @@ + + + + +

+ In Jenkins, you can export arbitrary server-side Java object to JavaScript via a proxy, + then invoke their methods from JavaScript. See the Wiki for more details. + In this sample, we call a method on the server to increment a counter. This object is a singleton, + so you'll see the same counter value across all the browsers. +

+ + + +
+ + +