[jboss-cvs] jboss-seam/examples/ui/src/org/jboss/seam/example/ui ...
Peter Muir
peter at bleepbleep.org.uk
Sat Feb 24 19:42:33 EST 2007
User: pmuir
Date: 07/02/24 19:42:33
Modified: examples/ui/src/org/jboss/seam/example/ui Country.java
Continent.java Converters.java Person.java
Added: examples/ui/src/org/jboss/seam/example/ui
Factories.java
Log:
JBSEAM-880
Revision Changes Path
1.2 +5 -4 jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Country.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Country.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Country.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Country.java 29 Jan 2007 23:52:49 -0000 1.1
+++ Country.java 25 Feb 2007 00:42:33 -0000 1.2
@@ -1,13 +1,14 @@
package org.jboss.seam.example.ui;
+import java.io.Serializable;
+
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.ManyToOne;
@Entity
-public class Country
+public class Country implements Serializable
{
@Id @GeneratedValue
@@ -15,7 +16,7 @@
private String name;
- @Enumerated(EnumType.STRING)
+ @ManyToOne
private Continent continent;
public Continent getContinent()
1.2 +40 -12 jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Continent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Continent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Continent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Continent.java 29 Jan 2007 23:52:49 -0000 1.1
+++ Continent.java 25 Feb 2007 00:42:33 -0000 1.2
@@ -1,19 +1,42 @@
package org.jboss.seam.example.ui;
-public enum Continent
+import java.io.Serializable;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+ at Entity
+public class Continent implements Serializable
{
- ANTARTICA("Antarctica"),
- SOUTH_AMERICA("South America"),
- NORTH_AMERICA("North America"),
- EUROPE("Europe"),
- ASIA("Asia"),
- AFRICA("Africa"),
- AUSTRALASIA("Australasia");
+ @Id @GeneratedValue
+ private Integer id;
private String name;
- Continent(String name) {
- this.name = name;
+ @OneToMany(mappedBy="continent")
+ private List<Country> countries;
+
+ public List<Country> getCountries()
+ {
+ return countries;
+ }
+
+ public void setCountries(List<Country> countries)
+ {
+ this.countries = countries;
+ }
+
+ public Integer getId()
+ {
+ return id;
+ }
+
+ public void setId(Integer id)
+ {
+ this.id = id;
}
public String getName()
@@ -21,4 +44,9 @@
return name;
}
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
}
1.3 +34 -0 jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Converters.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Converters.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Converters.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Converters.java 31 Jan 2007 20:06:22 -0000 1.2
+++ Converters.java 25 Feb 2007 00:42:33 -0000 1.3
@@ -66,4 +66,38 @@
};
}
+ @Transactional
+ public Converter getContinentConverter() {
+ return new Converter() {
+
+ @Transactional
+ public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException
+ {
+ if (arg2 == null) {
+ return null;
+ }
+ try {
+ return ((EntityManager) Component.getInstance("entityManager")).find(Continent.class, Integer.valueOf(arg2));
+ } catch (NumberFormatException e) {
+ throw new ConverterException("Cannot find selected continent", e);
+ }
+ }
+
+ @Transactional
+ public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException
+ {
+ if (arg2 instanceof Continent)
+ {
+ Continent continent = (Continent) arg2;
+ return continent.getId().toString();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ };
+ }
+
}
1.3 +53 -1 jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Person.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Person.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Person.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Person.java 31 Jan 2007 20:06:22 -0000 1.2
+++ Person.java 25 Feb 2007 00:42:33 -0000 1.3
@@ -1,14 +1,40 @@
package org.jboss.seam.example.ui;
+import java.io.Serializable;
+
import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
-public class Person
+public class Person implements Serializable
{
+ public enum Honorific {
+
+ MR("Mr."),
+ MRS("Mrs."),
+ MISS("Miss."),
+ MS("Ms."),
+ DOCTOR("Dr.");
+
+ private String label;
+
+ Honorific(String label)
+ {
+ this.label = label;
+ }
+
+ public String getLabel()
+ {
+ return label;
+ }
+
+ }
+
@Id @GeneratedValue
private Integer id;
@@ -17,6 +43,12 @@
@ManyToOne
private Country country;
+ @ManyToOne
+ private Continent continent;
+
+ @Enumerated(EnumType.STRING)
+ private Honorific honorific;
+
private int age;
public Country getCountry()
@@ -58,4 +90,24 @@
{
this.age = age;
}
+
+ public Continent getContinent()
+ {
+ return continent;
+ }
+
+ public void setContinent(Continent continent)
+ {
+ this.continent = continent;
+ }
+
+ public Honorific getHonorific()
+ {
+ return honorific;
+ }
+
+ public void setHonorific(Honorific honorific)
+ {
+ this.honorific = honorific;
+ }
}
1.1 date: 2007/02/25 00:42:33; author: pmuir; state: Exp;jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Factories.java
Index: Factories.java
===================================================================
package org.jboss.seam.example.ui;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.example.ui.Person.Honorific;
@Name("factories")
public class Factories
{
@Factory("honorifics")
public Honorific[] getHonorifics() {
return Honorific.values();
}
}
More information about the jboss-cvs-commits
mailing list