Button onclick change value of <h1> on Jelly Action

65 views
Skip to first unread message

Nozim Islamov

unread,
Jun 22, 2022, 1:44:38 AM6/22/22
to Jenkins Developers
Greetings everyone,
I want to create a button where whenever it clicks it takes the value of dropdown that I have and set it as <h1> on the same page, can anyone help with this one?
Action class code:

package io.jenkins.plugins.sample;

import hudson.model.Run;
import hudson.util.ListBoxModel;
import jenkins.model.RunAction2;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

public class PipelinePromotionAction implements RunAction2 {

private transient Run r;
private String status;

@DataBoundConstructor
public PipelinePromotionAction(String status) {
this.status = status;
}

public String getStatus() {
return status;
}

@DataBoundSetter
public void setStatus(String status) {
this.status = status;
}

@Override
public void onAttached(Run<?, ?> r) {
this.r = r;
}

@Override
public void onLoad(Run<?, ?> r) {
this.r = r;
}

public Run getR() {
return r;
}

@Override
public String getIconFileName() {
return "star.png";
}

@Override
public String getDisplayName() {
return "Manual Promotion";
}

@Override
public String getUrlName() {
return "promotion";
}
}

And here is the jelly code:

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<l:layout title="Promotions tab">
<l:side-panel>
<st:include page="sidepanel.jelly" it="${it.r}" optional="true" />
</l:side-panel>
<l:main-panel>
<h1 id="header_status">
Status: ${it.status}
</h1>
<div>
<f:entry title="Choose promotion status" field="status">
<select name="status">
<option value="promoted">Promoted</option>
<option value="not_promoted">Not promoted</option>
</select>
</f:entry>
<button>Click me</button>
</div>
</l:main-panel>
</l:layout>
</j:jelly>

Gavin Mogan

unread,
Jun 22, 2022, 2:57:04 AM6/22/22
to Jenkins Developers
Can't you make the dropdown and button (though switch it to an input type=button) and wrap them both in a form. Then you don't need to do any onclick and JavaScript stuff.

Otherwise you want document.queryElement("some selector that targets your button").addEventListener("click"...)

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/ef12d8a7-b242-413f-90b8-6148f150f343n%40googlegroups.com.

Nozim Islamov

unread,
Jun 22, 2022, 11:31:53 AM6/22/22
to Jenkins Developers
Also a quick question, is there any possibility to call Java method, on that click listener? And how it would be possible to do?
Reply all
Reply to author
Forward
0 new messages