Call JAVA method from Jelly

802 views
Skip to first unread message

Tomasz Szandała

unread,
Aug 8, 2014, 2:51:03 AM8/8/14
to jenkin...@googlegroups.com
Greetings,
I'm working on jenkins plugin nad now encountered a problem:
I've inserted a picture to my GUI (using jelly) and now I want to invoke method on click.
Best would be if I can pass an argument to it, for example:
my method:
public void setOwner(String owner)
and I have picture:

<img src="/plugin/PluginForJenkins/images/claim.png"/>
how can I make this picture clickable?

Stephen Connolly

unread,
Aug 8, 2014, 8:51:08 AM8/8/14
to jenkin...@googlegroups.com
wrap it in a <a> or add a javascript onclick event handler


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tomasz Szandała

unread,
Aug 8, 2014, 9:18:09 AM8/8/14
to jenkin...@googlegroups.com


W dniu piątek, 8 sierpnia 2014 14:51:08 UTC+2 użytkownik Stephen Connolly napisał:
wrap it in a <a> or add a javascript onclick event handler

Thank you, but could you, please, give me an example of using <a> tag? I need to pass a string argument to it.
Spent whole day today working on it, but... failed in it 

Robert Sandell

unread,
Aug 8, 2014, 4:23:49 PM8/8/14
to jenkinsci-dev
Roughly like so:

In YourBackendClass.java

    @JavaScriptMethod
    public void setOwner(String owner) {
      this.owner = owner;
    }

In the.jelly

    <st:bind var="${theInstanceOfYourBackendClass}" var="backend"/>
    <script>
        function setOwner(owner) {
          backend.setOwner(owner, function(t) {
            //Handle the response
          });
        }
    </script>
   ....
   <img src="/plugin/PluginForJenkins/images/claim.png" onClick="setOwner('theOwner')"/>



/B
Message has been deleted

Tomasz Szandała

unread,
Aug 11, 2014, 4:14:20 AM8/11/14
to jenkin...@googlegroups.com
OK it works, I solved the problem. Odd: it was in deleting cookies O_o
Thanks for help ;-)

W dniu poniedziałek, 11 sierpnia 2014 09:50:16 UTC+2 użytkownik Tomasz Szandała napisał:

So I have Java class: PublishingAction:
public class PublishingAction implements Action, ProminentProjectAction {
...
@JavaScriptMethod
 
public void lockMismatch(int hashCode){
 
 
for(MismatchesContainer mc: allMismatches){
   
for(Mismatch msm: mc.getMismatchesList()){
   
if(msm.hashCode()==hashCode){
     msm
.lock("Claimer", "reason");
   
}
   
}
 
}
}


And in jelly:

 <script>
     
var myAction= <st:bind value="${it}" />
     
function lockMismatch(mismatchHash) {
             myAction
.lockMismatch(mismatchHash);
       
}
 
</script>
...
<img src="/plugin/PluginForJenkins/images/claim.png" onClick="javascript:lockMismatch(${instanceSecond.hashCode})"/>

Now I'm getting error (visible through GoogleChrome):

  1. POST http://localhost:8080/$stapler/bound/c1678e1a-fc77-44d9-b212-2d73bc6e7b80/lockMismatch 413 (FULL head) prototype.js:1585
    1. Ajax.Request.Class.create.requestprototype.js:1585
    2. Ajax.Request.Class.create.initializeprototype.js:1550
    3. (anonymous function)prototype.js:452
    4. proxy.(anonymous function)bind.js:51
    5. lockMismatch(index):107
    6. onclick

There seems to be 2 reasons:
-somehow I'm passing too much data (how?!)
- more possible: I'm doing something wrong ;-(

Could you aid me, please?
Reply all
Reply to author
Forward
0 new messages