Spring MVC Bean Validation with Annotations

Input data validation is a critical piece of functionality in any web application because we cannot always rely on users to enter valid data. We need to safeguard our data-stores and business processes against both malformed as well as malicious data.

Based on my experience with Spring, I thought of writing a series of tutorials on different methods of validating form input when working with Spring MVC.

This is the first part of that series, and I will be focusing on basic form data (i.e. data submitted by the user) validation in Spring MVC 3 using declarative annotations. In the future, I am hoping to touch on more advanced topics such as:

  1. Displaying custom messages for validation errors
  2. Writing custom annotations to validate view models (or fields)
  3. Using JSR 303 groups to perform conditional validations
  4. Validation using Spring’s Validator interface
  5. Comparison of different validation methods in Spring MVC (pros, cons and when to use them)

Hopefully by the end of the series, you will have a good idea about Spring validation mechanisms, and be able to pick the best option(s) for a particular problem.

Continue on to learn how to perform basic annotation-based validations in your Spring MVC 3.x web applications.

Continue reading

Log4j property file examples

There aren’t too many clear examples of log4j.properties configuration examples around on the net. So, I thought of compiling a list of sample configurations to help anyone who might be looking to configure log4j.

In this article I will be covering the following scenarios with examples:

  1. Logging to Console
  2. Logging to a File
  3. Logging to multiple Appenders (or log files)
  4. Restricting logging levels by package name
  5. Having multiple appenders with different log levels
  6. Logging the output of a specific class or a package to a specific Appender

Continue reading

How to Configure Maven to work with NTLM proxies

I recently installed Maven at a client site that had a NTLM proxy, and ran into issues because it was failing to download maven dependencies. I was following the instructions provided by Maven to correctly setup my proxy settings, without any luck!

I kept getting the following error when attempting to run mvn install goal to set up the project:

C:Dev\MavenTest> mvn clean install
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifa
escriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-pl
:pom:2.4.1 from/to central (http://repo.maven.apache.org/maven2): Not authorized by proxy, ReasonPhrase:Proxy Authentication Required (
ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ). -> [Help 1]

After few hours of Googling and trial and error, I finally found two methods of getting Maven to work with NTLM proxies.

Continue reading

How to check network connectivity in Android

This tutorial shows how to check whether your Android phone is currently connected to a network or not (e.g. Wi-Fi, 3G etc.).

A while back, I wrote a tutorial on how to dynamically monitor network connectivity in Android. However, sometimes all you want is to check if your phone has an active network connection at any given time (i.e. not to constantly monitor its status).

Continue reading

Introduction to working with kSOAP2 in Android

This is an introductory tutorial showing how to consume SOAP-based web services in Android using the kSOAP2 library.

How to use kSOAP2 library in Android

Despite rising popularity of RESTful services, there are still a significant number of SOAP-based web services around that are being consumed by mobile applications; specially when working in the enterprise world. Android does not have native support for web service consumption, and this handy light-weight library called kSOAP2 allows Android applications to easily and efficiently consume SOAP-based web services.

In this tutorial I will show you how to use kSOAP2 in Android to consume a publicly available SOAP-based web service. A fully working example of an Android project illustrating the use of kSOAP2 can be found at GitHub.

Continue reading

Unveiling Bazaarfind NZ: A Price comparison site for sports supplements

Over the weekend I released my latest web site: BazaarFind Supplements.

BazaarFind New Zealand

Bazaarfind is a price comparison site for sports and nutritional supplements. Currently the comparison data is sourced from stores within New Zealand. Give it a go next time you happen to be in the online market to purchase supplements!

We are hard at work to add new features, and I would greatly appreciate if you can take few minutes to checkout the site and give me your feedback :)

If you like what you see, and want to be kept up to date of the site’s progress and latest deals:

  1. Like us on Facebook at http://www.facebook.com/BazaarFindNZ, and/or
  2. Follow us on Google+

Feel free to share the news with your friends and family!

How to Root HTC One X

Following on from the last article on what does it mean to root your Android phone, I thought of providing a step-by-step guide to root a HTC One X phone.

Continue reading

Rooting your Android phone: The Basics

If you own an Android phone, chances are that you’ve heard of rooting. However, most of us are bit reluctant to tinker too much with our phones because of the risks involved and are not 100% sure exactly what we are getting into by rooting android phones.

Android Rooting Basics

I thought of answering some basic questions such as what exactly is “Rooting”?, and what benefits do you get by rooting your phone? Hopefully this will clear some misconceptions floating around and give you a clearer picture about what rooting is all about.

Continue reading

How to manually disable WordPress plugins

I recently tried to update one of my WordPress plugins that somehow managed to bring my whole site down. I was unable to go to wp-admin to disable the plugin. I had to first disable all the WordPress plugins manually (through phpMyAdmin on my server) so I can get to wp-admin page, and then reinstall the plugin that caused the problem.

The best thing about this approach is that you don’t lose your existing configuration settings for the WordPress plugins (except for the one that caused issues in the first place).

Here are the detailed steps on how I went about getting my site back up.
Continue reading

How to prevent screen timeout in Android

There are several mechanisms available for Android applications to stop the phone’s screen from being turned off. These methods override the default ‘screen timeout’ behaviour of your phone (typically found under Settings -> Display), and will keep the screen on while your application is running.

I will be introducing two methods to stop the screen from being dimmed. The two methods provide means of accomplishing this depending on the current state of your application; i.e. whether it has an Activity on the foreground (visible on screen) or running on the background (as a Service).

  1. Use of FLAG_KEEP_SCREEN_ON option for your Activity.
  2. Use of a WakeLock.

Continue reading