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

Peter Muir peter at bleepbleep.org.uk
Thu Mar 22 18:40:01 EDT 2007


  User: pmuir   
  Date: 07/03/22 18:40:01

  Modified:    src/ui/org/jboss/seam/ui  EntityConverter.java
  Log:
  JBSEAM-1057
  
  Revision  Changes    Path
  1.2       +20 -4     jboss-seam/src/ui/org/jboss/seam/ui/EntityConverter.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EntityConverter.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/EntityConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- EntityConverter.java	10 Mar 2007 19:09:35 -0000	1.1
  +++ EntityConverter.java	22 Mar 2007 22:40:01 -0000	1.2
  @@ -12,6 +12,7 @@
   import javax.faces.component.UIComponent;
   import javax.faces.context.FacesContext;
   import javax.faces.convert.ConverterException;
  +import javax.persistence.Entity;
   import javax.persistence.EntityManager;
   import javax.persistence.Id;
   
  @@ -109,10 +110,10 @@
       * @return The ID of the entity as a string or null if unable to determine it
       */
      protected Object getIdFromEntity(UIComponent cmp, FacesContext facesContext,
  -            Object entity)
  +            Object entity, Class entityClass)
      {
         Object id = null;
  -      List<Field> fields = Reflections.getFields(entity.getClass(), Id.class);
  +      List<Field> fields = Reflections.getFields(entityClass, Id.class);
         if (fields.size() == 1)
         {
            Field field = fields.get(0);
  @@ -133,7 +134,7 @@
         }
         else
         {
  -         List<Method> methods = Reflections.getGetterMethods(entity.getClass(), Id.class);
  +         List<Method> methods = Reflections.getGetterMethods(entityClass, Id.class);
            if (methods.size() == 1)
            {
               try
  @@ -160,6 +161,7 @@
      @Transactional
      public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) throws ConverterException
      {
  +      
         if (value == null)
         {
            return null;
  @@ -168,7 +170,21 @@
         {
            return (String) value;
         }
  -      return EntityConverterStore.instance().put(value.getClass(), getIdFromEntity(cmp, facesContext, value)).toString();
  +      Class entityClass = deproxy(value.getClass());
  +      return EntityConverterStore.instance().put(entityClass, getIdFromEntity(cmp, facesContext, value, entityClass)).toString();
  +   }
  +   
  +   // Hibernate Lazy proxies don't copy annotations to proxied methods - why?
  +   private Class deproxy(Class clazz)
  +   {
  +      if (Object.class.equals(clazz) || clazz.isAnnotationPresent(Entity.class))
  +      {
  +         return clazz;
  +      }
  +      else 
  +      {
  +         return deproxy(clazz.getSuperclass());
  +      }
      }
   
      @Transactional
  
  
  



More information about the jboss-cvs-commits mailing list