Ben Ripkens created JENKINS-12802:
-------------------------------------
Summary: Initial select box validation fails when default value is
provided.
Key: JENKINS-12802
URL: https://issues.jenkins-ci.org/browse/JENKINS-12802
Project: Jenkins
Issue Type: Bug
Components: jenkins-plugin-runtime, plugin
Affects Versions: current
Environment: Jenkins version 1.451.
Jenkins run through mvn hpi:run.
See system info in attachment for further information.
Browser: Google Chrome 17 and Firefox 10
Reporter: Ben Ripkens
Assignee: Jørgen Tjernø
Attachments: systeminfo.pdf
When defining a select box like this:
{code:xml}
<f:entry title="Version Control System type"
field="vcs">
<f:select/>
</f:entry>
{code}
and validating the value through a
{code:java}
int i = 0;
public FormValidation doCheckVcs(@QueryParameter String value) {
System.out.println(i + ": value: " + value);
i++;
try {
VersionControlSystem.valueOf(value);
return FormValidation.ok();
} catch (IllegalArgumentException ex) {
return FormValidation.error("Please select one of the Version Control
Systems.");
}
}
{code}
method, it can be observed that the validation method is called two times when
opening the configuration menu (http://localhost:8080/configure). The first
time, the correct default value, i.e., the selected item's value, is passed to
the validation method. The second time, no data is passed in (see following
code listing for output).
{code}
0: value: MERCURIAL
1: value:
{code}
The code is additionally available on GitHub:
Descriptor:
https://github.com/bripkens/janus-plugin/blob/389833439d11cc4daf5666c1ac7fb98ecad28471/src/main/java/de/codecentric/janus/plugin/Root.java
Jelly:
https://github.com/bripkens/janus-plugin/blob/389833439d11cc4daf5666c1ac7fb98ecad28471/src/main/resources/de/codecentric/janus/plugin/Root/global.jelly
Data is provided in the following way:
{code:java}
public ListBoxModel doFillVcsItems() {
ListBoxModel m = new ListBoxModel();
m.add("Please select", "");
for (VersionControlSystem vcs : VersionControlSystem.values()) {
if (this.vcs == vcs) {
m.add(new ListBoxModel.Option(vcs.name(), vcs.name(),
true));
} else {
m.add(vcs.name());
}
}
return m;
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jenkins-ci.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira