下面列出了怎么用hudson.model.Descriptor.FormException的API类实例代码及写法,或者点击链接到github查看源代码。
@RequirePOST
public void doPurgeSubmit(final StaplerRequest req, StaplerResponse res)
throws IOException, ServletException, FormException {
checkPermission(Jenkins.ADMINISTER);
Connection conn = null;
Statement stat = null;
conn = DBConnection.getConnection();
try {
assert conn != null;
stat = conn.createStatement();
stat.execute("TRUNCATE TABLE env_dashboard");
} catch (SQLException e) {
System.out.println("E15: Could not truncate table env_dashboard.\n" + e.getMessage());
} finally {
DBConnection.closeConnection();
}
res.forwardToPreviousPage(req);
}
@Override
protected void submit(StaplerRequest req) throws ServletException, IOException, FormException {
super.submit(req);
JSONObject json = req.getSubmittedForm();
synchronized (this) {
String requestedOrdering = req.getParameter("order");
title = req.getParameter("title");
currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true));
currentConfig().setBuildFailureAnalyzerDisplayedField(req.getParameter("buildFailureAnalyzerDisplayedField"));
try {
currentConfig().setOrder(orderIn(requestedOrdering));
} catch (Exception e) {
throw new FormException("Can't order projects by " + requestedOrdering, "order");
}
}
}
@Override
public AbstractFolderProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws FormException {
if (form == null) {
return null;
}
// ignore modifications silently and return the unmodified object if the user
// does not have the ADMINISTER Permission
if (!userHasAdministerPermission()) {
return this;
}
try {
Set<String> inheritedGrants = new HashSet<>();
collectAllowedClouds(inheritedGrants, getOwner().getParent());
Set<String> permittedClouds = new HashSet<>();
JSONArray names = form.names();
if (names != null) {
for (Object name : names) {
String strName = (String) name;
if (strName.startsWith(PREFIX_USAGE_PERMISSION) && form.getBoolean(strName)) {
String cloud = StringUtils.replaceOnce(strName, PREFIX_USAGE_PERMISSION, "");
if (isUsageRestrictedKubernetesCloud(Jenkins.get().getCloud(cloud))
&& !inheritedGrants.contains(cloud)) {
permittedClouds.add(cloud);
}
}
}
}
this.permittedClouds.clear();
this.permittedClouds.addAll(permittedClouds);
} catch (JSONException e) {
LOGGER.log(Level.SEVERE, e, () -> "reconfigure failed: " + e.getMessage());
}
return this;
}
/**
* Custom specified ID. When editing existed UI entry, UI sends it back.
*/
public DockerSlaveTemplate(@Nonnull String id) throws FormException {
super(id);
if (isNull(id)) {
throw new FormException("Hidden id must not be null", "id");
}
}
/**
* FIXME DescribableList doesn't work with DBS https://gist.github.com/KostyaSha/3414f4f453ea7c7406b4
*/
@DataBoundConstructor
public DockerSlaveTemplate(@Nonnull String id, List<NodeProperty<?>> nodeProperties)
throws FormException {
this(id);
setNodeProperties(nodeProperties);
}
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
envOrder = formData.getString("envOrder");
compOrder = formData.getString("compOrder");
deployHistory = formData.getString("deployHistory");
save();
return super.configure(req, formData);
}
public PretendSlave(String name, String remoteFS, int numExecutors, Mode mode, String labelString, ComputerLauncher launcher, FakeLauncher faker) throws IOException, FormException {
super(name, "pretending a slave", remoteFS, String.valueOf(numExecutors), mode, labelString, launcher, RetentionStrategy.NOOP, Collections.emptyList());
this.faker = faker;
}
public PretendSlave(String name, String remoteFS, String labelString, ComputerLauncher launcher, FakeLauncher faker) throws IOException, FormException {
this(name, remoteFS, 1, Mode.NORMAL, labelString, launcher, faker);
}
@Override
protected void submit(final StaplerRequest req) throws IOException, ServletException, FormException {
req.bindJSON(this, req.getSubmittedForm());
}
@Override
protected void submit(final StaplerRequest req) throws IOException, ServletException, FormException {
// noop
}
@Override
protected void submit(final StaplerRequest req) throws IOException, ServletException, FormException {
throw new UnsupportedOperationException();
}
@Override
protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
}