private URL personalSite;
// Getter/setter methods omitted
public String toString() {
return "First name: " + getFirstName()
+ " - Last name: " + getLastName()
+ " - Birth date: " + getBirthDate()
+ " - Personal site: " + getPersonalSite();
}
}
As shown in Listing 14-1, for the birth date attribute, we use JodaTime's DateTime class. In addition,
there is a URL type field that indicates the contact's personal web site if applicable.
Now suppose we want to construct Contact objects in Spring's ApplicationContext, with values
stored either in Spring's configuration file or in a properties file. Listing 14-2 shows the Spring XML
configuration file (prop-editor-app-context.xml).
Listing 14-2. Spring Configuration for Property Editor
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config/>
<context:property-placeholder
location="classpath:application.properties"/>
<bean id="dateTimeEditor"
class="com.apress.prospring3.ch14.pe.editor.DateTimeEditor">
<constructor-arg value="${date.format.pattern}"/>
</bean>
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="org.joda.time.DateTime">
<ref local="dateTimeEditor" />
</entry>
</map>
</property>
</bean>
<bean id="clarence" class="com.apress.prospring3.ch14.domain.Contact"
p:firstName="Clarence"
p:lastName="Ho"
p:birthDate="1970-12-31"
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home