Java 类javax.validation.executable.ExecutableType 实例源码

项目:ozark    文件:FormControllerProperty.java   
@POST
@ValidateOnExecution(type = ExecutableType.NONE)
public Response formPost(@Valid @BeanParam FormDataBean form) {
    final BindingResult vr = getVr();
    if (vr.isFailed()) {
        ValidationError validationError = vr.getAllValidationErrors().iterator().next();
        final ConstraintViolation<?> cv = validationError.getViolation();
        final String property = cv.getPropertyPath().toString();
        error.setProperty(property.substring(property.lastIndexOf('.') + 1));
        error.setValue(cv.getInvalidValue());
        error.setMessage(cv.getMessage());
        error.setParam(validationError.getParamName());
        return Response.status(BAD_REQUEST).entity("error.jsp").build();
    }
    return Response.status(OK).entity("data.jsp").build();
}
项目:ozark    文件:FormController.java   
@POST
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
public Response formPost(@Valid @BeanParam FormDataBean form) {
    if (br.isFailed()) {
        ValidationError validationError = br.getAllValidationErrors().iterator().next();
        final ConstraintViolation<?> cv = validationError.getViolation();
        final String property = cv.getPropertyPath().toString();
        error.setProperty(property.substring(property.lastIndexOf('.') + 1));
        error.setValue(cv.getInvalidValue());
        error.setMessage(cv.getMessage());
        error.setParam(validationError.getParamName());
        return Response.status(BAD_REQUEST).entity("error.jsp").build();
    }
    return Response.status(OK).entity("data.jsp").build();
}
项目:mvc-demo    文件:PersonController.java   
@POST
@Path("/person")
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String addPerson(@BeanParam @Valid Person person) {

    if (bindingResult.isFailed()) {
        models.put("messages", bindingResult.getAllMessages());
    } else {
        dataStore.addPerson(person);
    }

    List<Person> personList = dataStore.getPersonList();
    models.put("personList", personList);

    return "person.jsp";
}
项目:javaee-mvc-spring    文件:HelloController.java   
@POST
@ValidateOnExecution(type = ExecutableType.NONE)
public Response formPost(@Valid @BeanParam HelloBean form) {

   if (validationResult.isFailed()) {

      validationResult.getAllViolations().stream()
              .forEach(v -> {
                 final String p = v.getPropertyPath().toString();
                 models.put(p.substring(p.lastIndexOf('.') + 1), v.getMessage());
              });

      models.put("form", form);

      return Response.status(BAD_REQUEST).entity("form.jsp").build();
   }

   models.put("name", form.getFirstName() + " " + form.getLastName());

   return Response.status(OK).entity("hello.jsp").build();
}
项目:tomee    文件:ValidatorBuilder.java   
public OpenEjbBootstrapConfig(final String providerClassName,
                              final String constraintFactoryClass,
                              final String messageInterpolatorClass,
                              final String traversableResolverClass,
                              final String parameterNameProviderClass,
                              final Set<String> constraintMappings,
                              final boolean executableValidationEnabled,
                              final Set<ExecutableType> validatedTypes,
                              final Map<String, String> props) {
    this.providerClassName = providerClassName;
    this.constraintFactoryClass = constraintFactoryClass;
    this.messageInterpolatorClass = messageInterpolatorClass;
    this.traversableResolverClass = traversableResolverClass;
    this.parameterNameProviderClass = parameterNameProviderClass;
    this.constraintMappings = constraintMappings;
    this.executableValidationEnabled = executableValidationEnabled;
    this.validatedTypes = validatedTypes;
    this.props = props;
}
项目:syndesis    文件:ValidatorContextResolver.java   
@Override
public GeneralValidator getContext(final Class<?> type) {
    final ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator("messages");
    final MessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator);
    final Configuration<?> config = Validation.byDefaultProvider().configure()
        .messageInterpolator(messageInterpolator);
    final BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
    final boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
    final Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration
        .getDefaultValidatedExecutableTypes();

    return new GeneralValidatorImpl(validatorFactory, isExecutableValidationEnabled,
        defaultValidatedExecutableTypes);
}
项目:JPA-Modeler-Examples    文件:ProductController.java   
@POST
@Path("new")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String createProduct(@Valid
        @BeanParam Product entity) {
    if (validationResult.isFailed()) {
        return ValidationUtil.getResponse(validationResult, error);
    }
    facade.create(entity);
    return "redirect:product/list";
}
项目:JPA-Modeler-Examples    文件:ProductController.java   
@POST
@Path("update")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String updateProduct(@Valid
        @BeanParam Product entity) {
    if (validationResult.isFailed()) {
        return ValidationUtil.getResponse(validationResult, error);
    }
    facade.edit(entity);
    return "redirect:product/list";
}
项目:JPA-Modeler-Examples    文件:ProductOrderController.java   
@POST
@Path("new")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String createProductOrder(@Valid
        @BeanParam ProductOrder entity) {
    if (validationResult.isFailed()) {
        return ValidationUtil.getResponse(validationResult, error);
    }
    facade.create(entity);
    return "redirect:productOrder/list";
}
项目:JPA-Modeler-Examples    文件:ProductOrderController.java   
@POST
@Path("update")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String updateProductOrder(@Valid
        @BeanParam ProductOrder entity) {
    if (validationResult.isFailed()) {
        return ValidationUtil.getResponse(validationResult, error);
    }
    facade.edit(entity);
    return "redirect:productOrder/list";
}
项目:JPA-Modeler-Examples    文件:CustomerController.java   
@POST
@Path("new")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String createCustomer(@Valid
        @BeanParam Customer entity) {
    if (validationResult.isFailed()) {
        return ValidationUtil.getResponse(validationResult, error);
    }
    facade.create(entity);
    return "redirect:customer/list";
}
项目:JPA-Modeler-Examples    文件:CustomerController.java   
@POST
@Path("update")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfValid
public String updateCustomer(@Valid
        @BeanParam Customer entity) {
    if (validationResult.isFailed()) {
        return ValidationUtil.getResponse(validationResult, error);
    }
    facade.edit(entity);
    return "redirect:customer/list";
}
项目:ee8-sandbox    文件:TaskController.java   
@POST
@CsrfValid
@ValidateOnExecution(type = ExecutableType.NONE)
public Response save(@Valid @BeanParam TaskForm form) {
    log.log(Level.INFO, "saving new task @{0}", form);

    if (validationResult.isFailed()) {
        AlertMessage alert = AlertMessage.danger("Validation voilations!");
        validationResult.getAllViolations()
                .stream()
                .forEach((ConstraintViolation t) -> {
                    String path = t.getPropertyPath().toString();
                    alert.addError(path.substring(path.lastIndexOf(".") + 1), "", t.getMessage());
                });
        models.put("errors", alert);
        return Response.status(BAD_REQUEST).entity("add.jspx").build();
    }

    Task task = new Task();
    task.setName(form.getName());
    task.setDescription(form.getDescription());
    task.setDueDate(form.getDueDate());

    taskRepository.save(task);

    flashMessage.notify(Type.success, "Task was created successfully!");
    //models.put("flashMessage", flashMessage);

    return Response.ok("redirect:tasks").build();
}
项目:ee8-sandbox    文件:TaskController.java   
@POST
//@CsrfValid
@ValidateOnExecution(type = ExecutableType.NONE)
public Response save(@Valid @BeanParam TaskForm form) {
    log.log(Level.INFO, "saving new task @{0}", form);

    if (validationResult.isFailed()) {
        AlertMessage alert = AlertMessage.danger("Validation voilations!");
        validationResult.getAllViolations()
                .stream()
                .forEach((ConstraintViolation t) -> {
                    String path = t.getPropertyPath().toString();
                    alert.addError(path.substring(path.lastIndexOf(".") + 1), "", t.getMessage());
                });
        models.put("errors", alert);
        return Response.status(BAD_REQUEST).entity("add.xhtml").build();
    }

    Task task = new Task();
    task.setName(form.getName());
    task.setDescription(form.getDescription());

    taskRepository.save(task);

    flashMessage.notify(Type.success, "Task was created successfully!");
    //models.put("flashMessage", flashMessage);

    return Response.ok("redirect:tasks").build();
}
项目:syndesis-rest    文件:ValidatorContextResolver.java   
@Override
public GeneralValidator getContext(final Class<?> type) {
    final ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator("messages");
    final MessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator);
    final Configuration<?> config = Validation.byDefaultProvider().configure()
        .messageInterpolator(messageInterpolator);
    final BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
    final boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
    final Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration
        .getDefaultValidatedExecutableTypes();

    return new GeneralValidatorImpl(validatorFactory, isExecutableValidationEnabled,
        defaultValidatedExecutableTypes);
}
项目:tomee    文件:ValidatorBuilder.java   
public static ValidationInfo getInfo(final ValidationConfigType config) {
    final ValidationInfo info = new ValidationInfo();
    if (config != null) {
        info.version = config.getVersion();
        info.providerClassName = config.getDefaultProvider();
        info.constraintFactoryClass = config.getConstraintValidatorFactory();
        info.traversableResolverClass = config.getTraversableResolver();
        info.messageInterpolatorClass = config.getMessageInterpolator();
        info.parameterNameProviderClass = config.getParameterNameProvider();

        final ExecutableValidationType executableValidation = config.getExecutableValidation();
        if (executableValidation != null) {
            info.executableValidationEnabled = executableValidation.getEnabled();
            final DefaultValidatedExecutableTypesType executableTypes = executableValidation.getDefaultValidatedExecutableTypes();
            if (executableTypes != null) {
                for (final ExecutableType type : executableTypes.getExecutableType()) {
                    info.validatedTypes.add(type.name());
                }
            }
        }
        for (final PropertyType p : config.getProperty()) {
            info.propertyTypes.put(p.getName(), p.getValue());
        }
        for (final String element : config.getConstraintMapping()) {
            info.constraintMappings.add(element);
        }
    }
    return info;
}
项目:ozark    文件:ValidationController.java   
@POST
@ValidateOnExecution(type = ExecutableType.NONE)
public String post(@Valid @BeanParam FormBean form) {

    if (bindingResult.isFailed()) {

        List<String> errors = bindingResult.getAllValidationErrors().stream()
                .map(ValidationError::getMessage)
                .collect(Collectors.toList());

        models.put("errors", errors);

    }

    return "form.jsp";

}
项目:tomee    文件:Adapter1.java   
public ExecutableType unmarshal(String value) {
    return (javax.validation.executable.ExecutableType.valueOf(value));
}
项目:tomee    文件:Adapter1.java   
public String marshal(ExecutableType value) {
    if (value == null) {
        return null;
    }
    return value.toString();
}
项目:tomee    文件:ValidatorBuilder.java   
@Override
public Set<ExecutableType> getDefaultValidatedExecutableTypes() {
    return validatedTypes;
}
项目:tomee    文件:DefaultValidatedExecutableTypesType.java   
/**
 * Gets the value of the executableType property.
 * 
 * <p>
 * This accessor method returns a reference to the live list,
 * not a snapshot. Therefore any modification you make to the
 * returned list will be present inside the JAXB object.
 * This is why there is not a <CODE>set</CODE> method for the executableType property.
 * 
 * <p>
 * For example, to add a new item, do as follows:
 * <pre>
 *    getExecutableType().add(newItem);
 * </pre>
 * 
 * 
 * <p>
 * Objects of the following type(s) are allowed in the list
 * {@link String }
 * 
 * 
 */
public List<ExecutableType> getExecutableType() {
    if (executableType == null) {
        executableType = new ArrayList<ExecutableType>();
    }
    return this.executableType;
}