Posts Tagged validation

Parametrizing custom validator in JSF 2

Tags: , , ,

Writing a custom validator in JSF 2 is not a complicated task. You implement Validator interface, add @FacesValidator annotation and insert validator declaration in faces-config.xml, that’s all. A piece of cake. But let’s consider following scenario:

You need custom date validator, let’s say checking that date from rich:calendar is not in the past. So we place calendar component with validator inside.

    <rich:calendar value="#{fieldValue}" id="dateField" datePattern="yyyy/MM/dd">
        <f:validator validatorId="dateNotInThePast"/>
    </rich:calendar>

Continue reading this post …


Be Sociable, Share!

Wicket Tutorial, part 3 – first form in our application

Tags: , , , , ,

Hello Visitor :) In previous posts we created base project and added common layout to ItemDirectory Wicket application. Today we are going to add first form to allow users to insert some data into our application.

As main feature of ItemDirectory is to manage information where items (books, movies, music, postage stamps) are stored in our home/work, the first data we need to know are locations where we actually can store those things. So we start with adding table, entity and form to manage locations of our precious items.

Database, entity and DAO

First thing we need is locations table in database and entity mapping class:

- sql create table script listing:

create table locations (
	id bigint(20) not null auto_increment,
	name varchar(255) not null,
        PRIMARY KEY (id),
	UNIQUE KEY unique_name (name)
);

- entity class listing:

@javax.persistence.Entity
@Table(name = "locations")
public class Location extends AbstractEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
   @Column(length=255, nullable=false)
    private String name;
        protected Location() {
		super();
	}
	public Location(String name) {
		super();
		this.name = name;
	}
	// getters, setters omitted
}

As you can see, Location class is very simple: only one field, but the only thing we want at the moment from this entity is a name describing where item is stored. Is it “Bookcase in living room, second drawer from the top” or “Cabinet in the saloon, top bookshelf”.

Continue reading this post …


Be Sociable, Share!