Spring @Autowired into JSF custom validator

Here’s the scenario, create a custom JSF validator, injects a bean via Spring’s @Autowired. UsernameValidator.java – Custom JSF validator package com.mkyong.user; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.Validator; import javax.faces.validator.ValidatorException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import com.mkyong.user.bo.UserService; @Component @Scope("request") @FacesValidator("UsernameValidator") public class UsernameValidator implements Validator { @Autowired UserService userService; @Override public …

Read more

Java regex validate date format examples

This article shows how to use regex + code to validate a date format, support single and leading zero month and day format (1 or 01), check for the 30 or 31 days of the month, and leap year validation. Below are the requirements for a valid date. Year format, 1900, 2099 regex Month format, …

Read more

Java IP Address (IPv4) regex examples

This article focus on how to validate an IP address (IPv4) using regex and Apache Commons Validator. Here is the summary. IPv4 regex explanation. Java IPv4 validator, using regex. Java IPv4 validator, using commons-validator-1.7 JUnit 5 unit tests for the above IPv4 validators. IPv4 regex final version. ^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(?!$)|$)){4}$ # Explanation ( [0-9] # 0-9 | …

Read more

Java regex validate username examples

This article shows how to use regex to validate a username in Java. Username requirements Username consists of alphanumeric characters (a-zA-Z0-9), lowercase, or uppercase. Username allowed of the dot (.), underscore (_), and hyphen (-). The dot (.), underscore (_), or hyphen (-) must not be the first or last character. The dot (.), underscore …

Read more

Java regex validate password examples

This article shows how to use regex to validate a password in Java. Secure Password requirements Password must contain at least one digit [0-9]. Password must contain at least one lowercase Latin character [a-z]. Password must contain at least one uppercase Latin character [A-Z]. Password must contain at least one special character like ! @ …

Read more