I am writing my own gadget.
When the user add that gadget, user need to specify some value in that field. My Question is how to valiadte that value before saving the gadget ???
So if the validation fails, then the gadget should again prompt to enter the value ???
Community moderators have prevented the ability to post new answers.
@Path("/validate") @GET @AnonymousAllowed @Produces({MediaType.APPLICATION_JSON}) public Response getPrefsValidation(@QueryParam("input_id") String inputValue,) { if(inputValue.equals("error")){ ErrorCollection errors = new ErrorCollection(); errors.addError("input_id", "validation error!"); return Response.status(Response.Status.BAD_REQUEST).entity(gson.toJson(errors)).build(); } else{ return Response.ok(new TextMessage("No input validation errors found.")).build(); } }
ErrorCollection is my class:
public class ErrorCollection { private Collection<String> errorMessages; private Collection<ValidationError> errors; public ErrorCollection() { errorMessages = new ArrayList<String>(1); errors = new ArrayList<ValidationError>(7); } public Collection<String> getErrorMessages() { return errorMessages; } public void setErrorMessages(Collection<String> errorMessages) { this.errorMessages = errorMessages; } public Collection<ValidationError> getErrors() { return errors; } public void setErrors(Collection<ValidationError> errors) { this.errors = errors; } public void addError(String field, String errorMsg) { errors.add(new ValidationError(field, errorMsg)); } public boolean hasAnyErrors() { return !errors.isEmpty() || !errorMessages.isEmpty(); } public void addErrorMessage(String errorMsg) { errorMessages.add(errorMsg); } public boolean hasErrorForField(String fieldId) { if (errors.isEmpty()) { return false; } else { for (ValidationError error : errors) { if (error.getField().equals(fieldId)) return true; } } return false; } }
Action before fields in javascript:
action: "/rest/[your_project]/1.0/validate",
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.rest.api.util.ValidationError; package for error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm sure it's too late, but probably it'll help you.
https://developer.atlassian.com/display/GADGETS/REST+Resource+for+Validating+Gadget+Configuration
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.