[jboss-cvs] jboss-seam/examples/ui/src/org/jboss/seam/example/ui ...

Peter Muir peter at bleepbleep.org.uk
Mon Jan 29 18:52:49 EST 2007


  User: pmuir   
  Date: 07/01/29 18:52:49

  Added:       examples/ui/src/org/jboss/seam/example/ui     Continent.java
                        Person.java Country.java Converters.java
  Log:
  Add ui example.  Example of s:selectItems included
  
  Revision  Changes    Path
  1.1      date: 2007/01/29 23:52:49;  author: pmuir;  state: Exp;jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Continent.java
  
  Index: Continent.java
  ===================================================================
  package org.jboss.seam.example.ui;
  
  public enum Continent
  {
     ANTARTICA("Antarctica"),
     SOUTH_AMERICA("South America"),
     NORTH_AMERICA("North America"),
     EUROPE("Europe"), 
     ASIA("Asia"),
     AFRICA("Africa"),
     AUSTRALASIA("Australasia");
     
     private String name;
  
     Continent(String name) {
        this.name = name;
     }
     
     public String getName()
     {
        return name;
     }
  
  }
  
  
  
  1.1      date: 2007/01/29 23:52:49;  author: pmuir;  state: Exp;jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Person.java
  
  Index: Person.java
  ===================================================================
  package org.jboss.seam.example.ui;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.ManyToOne;
  
  @Entity
  public class Person
  {
     
     @Id @GeneratedValue
     private Integer id;
     
     private String name;
     
     @ManyToOne
     private Country country;
  
     public Country getCountry()
     {
        return country;
     }
  
     public void setCountry(Country country)
     {
        this.country = country;
     }
  
     public Integer getId()
     {
        return id;
     }
  
     public void setId(Integer id)
     {
        this.id = id;
     }
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
     
     
  
  }
  
  
  
  1.1      date: 2007/01/29 23:52:49;  author: pmuir;  state: Exp;jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Country.java
  
  Index: Country.java
  ===================================================================
  package org.jboss.seam.example.ui;
  
  import javax.persistence.Entity;
  import javax.persistence.EnumType;
  import javax.persistence.Enumerated;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  @Entity
  public class Country
  {
     
     @Id @GeneratedValue
     private Integer id;
     
     private String name;
     
     @Enumerated(EnumType.STRING)
     private Continent continent;
  
     public Continent getContinent()
     {
        return continent;
     }
  
     public void setContinent(Continent continent)
     {
        this.continent = continent;
     }
  
     public Integer getId()
     {
        return id;
     }
  
     public void setId(Integer id)
     {
        this.id = id;
     }
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
     
     
  
  }
  
  
  
  1.1      date: 2007/01/29 23:52:49;  author: pmuir;  state: Exp;jboss-seam/examples/ui/src/org/jboss/seam/example/ui/Converters.java
  
  Index: Converters.java
  ===================================================================
  package org.jboss.seam.example.ui;
  
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.convert.Converter;
  import javax.faces.convert.ConverterException;
  import javax.persistence.EntityManager;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Transactional;
  
  @Name("converters")
  public class Converters
  {
     
     
     @Transactional
     public Converter getCountryConverter() {
        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(Country.class, Integer.valueOf(arg2));
              } catch (NumberFormatException e) {
                throw new ConverterException("Cannot find selected country", e);
              }
           }
  
           @Transactional
           public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException
           {
             if (arg2 instanceof Country)
              {
                 Country country = (Country) arg2;
                 return country.getId().toString();
              }
             else
             {
                return null;
             }
           }
           
        };
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list