Friday, September 30, 2016

Angular2 Typescript Webpack Quickstart

Get started quickly with Angular2 Typescript and Webpack: A skeleton / seed Angular2 application that was created by following the official WEBPACK: AN INTRODUCTION on I have built this small seed project to get better understanding of the Webpack mechanics as I have never worked with this tool before. I suggest reading the original article, but if you look to start quickly you can use the code and start your own seed project immediately.

Saturday, September 17, 2016

Wednesday, September 14, 2016

Injecting authenticated user into Spring MVC @Controllers

Injecting injecting authenticated user into Spring MVC handler method can be done with @AuthenticationPrincipal annotation and AuthenticationPrincipalArgumentResolver that is an implementation of Spring MVS MethodArgumentResolver. AuthenticationPrincipalArgumentResolver is registered by default with web security configuration (e.g. when you enable security with @EnableWebSecurity).

Saturday, May 14, 2016

Thymeleaf 3 - Get Started Quickly with Thymeleaf 3 and Spring MVC

Thymeleaf 3 release arrived. The new version brings plenty of new features like HTML5 support as well as Text templates support with no markup - [# th:utext="${thymeleaf.version}" /] , improved inline capabilities - <p>Thymeleaf [[${thymeleaf.version}]] is great!</p>, performence improvements and much more.

Thursday, April 7, 2016

Spring MVC: Trgger manual validation of a form object

Sometimes it may be needed to use manual validation in Spring MVC @Controller. This is very simple with Spring’s org.springframework.validation.ValidationUtils class. Learn how to invoke a validator in two different scenarios.

Scenario 1 - invoke validation

In this scenario, I have a user form with username field. Username field is validated with custom validator in order to verify the existance in e.g. database.

public class User {

    private String username;


In controller class I have a method that handles POST method of that object:

private org.springframework.validation.Validator validator;

@RequestMapping(value = "/user", method = RequestMethod.POST)
public String validate(@ModelAttribute User user, Errors errors) {

    ValidationUtils.invokeValidator(validator, user, errors);

    if (errors.hasErrors()) {
        // error, show errors to the user

    // success, form is valid!

org.springframework.validation.ValidationUtils is a class for invoking a org.springframework.validation.Validator.

Please note that user parameter is followed by org.springframework.validation.Errors object. Spring initializes this object but it is empty and can be be passed to a invokeValidator method.

Scenario 2 - invoke validation with hints

In this scenario, user form gets a bit more complicated:

@GroupSequence(value = {ValidationOrder.First.class, ValidationOrder.Second.class})
interface ValidationOrder {
    interface First {}
    interface Second {}

public class User {

    @UserExists(groups = ValidationOrder.First.class)
    @UserIsEntitledToDiscount(groups = ValidationOrder.Second.class)
    private String username;


Thanks to @GroupSequence I could decide about the order of validation. To trigger validation I need to pass an additional argument to invokeValidator method so the groups are correctly used:

ValidationUtils.invokeValidator(validator, user, errors, ValidationOrder.class);

Source code

The source code contains all three approaches, so that you can quickly compare them:

Similar articles

In case you find this article interesting, have a look at my other blog posts:

Friday, March 4, 2016

Thursday, March 3, 2016