How can i validate UserPref in gadget??? I want to validate userpref value before saving the gadget???

SJ March 28, 2014

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 ???

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Igor Guzenko July 9, 2014

 






1 vote
Igor Guzenko July 9, 2014
@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",
Igor Guzenko July 9, 2014

import com.atlassian.jira.rest.api.util.ValidationError; package for error

0 votes
carlos.fernandez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2014
0 votes
SJ March 31, 2014

Can please anyone help ??

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events