Skip to main content

Posts

Showing posts from 2010

Using of Collections.emptyList() the right way in Java 1.5+

It is little strange that no one really uses emptyList like he should in Java. So this is small post showing how to use the emptyList method in the Collections class. Question: How to create an empty list ? lets assume that we have a class Book with multiple titles. So the class in our examples will be: import java.util.List; public class Book {       private List<String> titles ;       public void setTitles(List<String> titles) {             this . titles = titles;       }       public List<String> getTitles() {             return titles ;       } } Lets say that in our snippet we have something like :   Book myCrazyBook= new Book(); and we want to assign an empty list to the titles in this book. This is a common scenario if you want to set something to be emptyList in specific case instead of null. So of course your first try will be something like:

Spring MVC, Spring Bean Validation Framework and validating confirm password / confirm email fields.

How to write validation like confirm password, confirm email and etc in Spring MVC. NOTE: To make bean validation to work its nice to read this tutorial: <a href=" http://wheelersoftware.com/articles/spring-bean-validation-framework.html" ></a> Today I was busy making some validations and implementations on very common scenario: change email and password. So we have a new password AND a new email also for both of them we have a confirm email/password field. And we want to validate everything nicely and to show to the user the real validation message if there is some error. So ... I've to use a form which already uses some annotations like @NoBlank and etc I think everyone of you is using annotations framework if you don't use it SHAME ON YOU !:) Anyway so I've added some fields to existing form bean: private String newPassword; private String confirmNewPassword; private String newEmail; private String confirmNewEmail; Bas