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

Gavin King gavin.king at jboss.com
Mon Mar 19 23:41:50 EDT 2007


  User: gavin   
  Date: 07/03/19 23:41:50

  Modified:    src/ui/org/jboss/seam/ui      HtmlMessageDecoration.java
                        UIDecorate.java
  Added:       src/ui/org/jboss/seam/ui      HtmlLabelDecoration.java
  Removed:     src/ui/org/jboss/seam/ui      UIAbstractDecorate.java
                        UIDecorateAll.java
  Log:
  remove s:decorateAll and add support for facelets templating to s:decorate
  
  Revision  Changes    Path
  1.4       +39 -6     jboss-seam/src/ui/org/jboss/seam/ui/HtmlMessageDecoration.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HtmlMessageDecoration.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/HtmlMessageDecoration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- HtmlMessageDecoration.java	18 Mar 2007 04:22:28 -0000	1.3
  +++ HtmlMessageDecoration.java	20 Mar 2007 03:41:50 -0000	1.4
  @@ -1,5 +1,6 @@
   package org.jboss.seam.ui;
   
  +import javax.faces.component.EditableValueHolder;
   import javax.faces.component.UIComponent;
   import javax.faces.component.html.HtmlMessage;
   
  @@ -8,20 +9,52 @@
   {
      public static final String COMPONENT_TYPE = "org.jboss.seam.ui.HtmlMessageDecoration";
   
  -   private String getFor(UIComponent component)
  +   /**
  +    * A depth-first search for an EditableValueHolder
  +    */
  +   protected static UIComponent getEditableValueHolder(UIComponent component)
  +   {
  +      if (component instanceof EditableValueHolder)
      {
  -      if (component instanceof UIDecorate) 
  +         return component.isRendered() ? component : null;
  +      }
  +      for (Object child: component.getChildren())
         {
  -         return UIDecorate.getInputId(component);
  +         if (child instanceof UIComponent)
  +         {
  +            UIComponent evh = getEditableValueHolder( (UIComponent) child );
  +            if (evh!=null) return evh;
  +         }
         }
  -      else if ( component.getParent() instanceof UIDecorateAll )
  +      return null;
  +   }
  +
  +   private static String getInputId(UIComponent cmp)
         {
  -         return UIDecorate.getInputId(component);
  +      String forId = cmp instanceof UIDecorate ?
  +               ( (UIDecorate) cmp ).getFor() : null;
  +      if (forId==null)
  +      {
  +         UIComponent evh = getEditableValueHolder(cmp);
  +         return evh==null ? null : evh.getId();
         }
  -      else if ( component.getParent()==null )
  +      else
  +      {
  +         return forId;
  +      }
  +   }
  +   
  +   private String getFor(UIComponent component)
  +   {
  +      
  +      if ( component.getParent()==null )
         {
            return null;
         }
  +      else if (component instanceof UIDecorate) 
  +      {
  +         return getInputId(component);
  +      }
         else
         {
            return getFor( component.getParent() );
  
  
  
  1.15      +210 -24   jboss-seam/src/ui/org/jboss/seam/ui/UIDecorate.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIDecorate.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/UIDecorate.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- UIDecorate.java	18 Mar 2007 04:22:28 -0000	1.14
  +++ UIDecorate.java	20 Mar 2007 03:41:50 -0000	1.15
  @@ -2,11 +2,14 @@
   
   import java.io.IOException;
   
  +import javax.faces.component.EditableValueHolder;
   import javax.faces.component.UIComponent;
  +import javax.faces.component.UIComponentBase;
   import javax.faces.context.FacesContext;
  -import javax.faces.context.ResponseWriter;
   
  -public class UIDecorate extends UIAbstractDecorate
  +import org.jboss.seam.contexts.Contexts;
  +
  +public class UIDecorate extends UIComponentBase
   {
   
      public static final String COMPONENT_TYPE = "org.jboss.seam.ui.UIDecorate";
  @@ -15,22 +18,127 @@
      private String forId;
      
      @Override
  -   public void startElement(ResponseWriter writer) throws IOException
  +   public String getFamily()
      {
  -      writer.startElement("span", this);
  -      writer.writeAttribute("id", getClientId( getFacesContext() ), "id");
  +      return COMPONENT_FAMILY;
      }
      
  -   @Override
  -   public void endElement(ResponseWriter writer) throws IOException
  +   protected static boolean hasMessage(UIComponent component, FacesContext context)
  +   {
  +      if ( !component.isRendered() ) return false;
  +      
  +      /*Iterator<FacesMessage> iter = context.getMessages( component.getClientId(context) );
  +      if ( iter.hasNext() )
  +      {
  +         return true;
  +      }*/
  +      
  +      if ( component instanceof EditableValueHolder )
  +      {
  +         if ( ! ( (EditableValueHolder) component ).isValid() ) return true;
  +      }
  +
  +      for (Object child: component.getChildren())
  +      {
  +         if (child instanceof UIComponent)
  +         {
  +            boolean message = hasMessage( (UIComponent) child, context );
  +            if (message) return true;
  +         }
  +      }
  +      return false;
  +   }
  +
  +   protected static boolean hasRequired(UIComponent component, FacesContext context)
  +   {
  +      if ( !component.isRendered() ) return false;
  +      
  +      if ( component instanceof EditableValueHolder )
  +      {
  +         if (  ( (EditableValueHolder) component ).isRequired() ) return true;
  +      }
  +
  +      for (Object child: component.getChildren())
  +      {
  +         if (child instanceof UIComponent)
  +         {
  +            boolean required = hasRequired( (UIComponent) child, context );
  +            if (required) return true;
  +         }
  +      }
  +      return false;
  +   }
  +
  +   private boolean hasMessage()
  +   {
  +      String clientId = getInputClientId();
  +      if (clientId==null)
  +      {
  +         return false;
  +      }
  +      else
  +      {
  +         return getFacesContext().getMessages(clientId).hasNext();
  +      }
  +   }
  +
  +   public String getInputId()
  +   {
  +      String id = getFor();
  +      if (id==null)
  +      {
  +         UIComponent evh = getEditableValueHolder(this);
  +         return evh==null ? null : evh.getId();
  +      }
  +      else
  +      {
  +         return id;
  +      }
  +   }
  +
  +   private String getInputClientId()
  +   {
  +      String id = getFor();
  +      if (id==null)
  +      {
  +         UIComponent evh = getEditableValueHolder(this);
  +         return evh==null ? null : evh.getClientId( getFacesContext() );
  +      }
  +      else
  +      {
  +         UIComponent component = findComponent(id);
  +         return component==null ? null : component.getClientId( getFacesContext() );
  +      }
  +   }
  +
  +   /**
  +    * A depth-first search for an EditableValueHolder
  +    */
  +   private static UIComponent getEditableValueHolder(UIComponent component)
  +   {
  +      for (Object child: component.getChildren())
  +      {
  +         if (child instanceof EditableValueHolder)
  +         {
  +            UIComponent evh =(UIComponent) child;
  +            if ( evh.isRendered() )
  +            {
  +               return evh;
  +            }
  +         }
  +         else if (child instanceof UIComponent)
      {
  -      writer.endElement("span");
  +            UIComponent evh = getEditableValueHolder( (UIComponent) child );
  +            if (evh!=null) return evh;
  +         }
  +      }
  +      return null;
      }
      
      @Override
  -   public String getFamily()
  +   public boolean getRendersChildren()
      {
  -      return COMPONENT_FAMILY;
  +      return true;
      }
   
      public String getFor()
  @@ -43,16 +151,100 @@
         this.forId = forId;
      }
   
  +   private UIComponent getDecoration(String name)
  +   {
  +      return getDecoration(name, this);
  +   }
  +   
  +   private static UIComponent getDecoration(String name, UIComponent component)
  +   {
  +      UIComponent dec = component.getFacet(name);
  +      if (dec!=null) return dec;
  +      if ( component.getParent()==null ) return null;
  +      return getDecoration( name, component.getParent() );
  +   }
  +
  +   @Override
  +   public void encodeBegin(FacesContext context) throws IOException
  +   {
  +      super.encodeBegin(context);
  +      
  +      Contexts.getEventContext().set("invalid", hasMessage(this, context));
  +      Contexts.getEventContext().set("required", hasRequired(this, context));
  + 
  +      context.getResponseWriter().startElement("span", this);
  +      context.getResponseWriter().writeAttribute("id", getClientId(context), "id");
  +      boolean hasMessage = hasMessage();
  +      UIComponent aroundDecoration = getDecoration("aroundField");
  +      UIComponent aroundInvalidDecoration = getDecoration("aroundInvalidField");
  +      if (aroundDecoration!=null && !hasMessage)
  +      {
  +         aroundDecoration.setParent(this);
  +         aroundDecoration.encodeBegin(context);
  +      }
  +      if (aroundInvalidDecoration!=null && hasMessage)
  +      {
  +         aroundInvalidDecoration.setParent(this);
  +         aroundInvalidDecoration.encodeBegin(context);
  +      }
  +   }
  +   
      @Override
  -   public void encodeChildren(FacesContext context) throws IOException
  +   public void encodeEnd(FacesContext context) throws IOException
  +   {
  +      boolean hasMessage = hasMessage();
  +      UIComponent aroundDecoration = getDecoration("aroundField");
  +      UIComponent aroundInvalidDecoration = getDecoration("aroundInvalidField");
  +      if (aroundDecoration!=null && !hasMessage)
  +      {
  +         aroundDecoration.setParent(this);
  +         aroundDecoration.encodeEnd(context);
  +      }
  +      if (aroundInvalidDecoration!=null && hasMessage)
      {
  -      renderChildAndDecorations(context, this);
  +         aroundInvalidDecoration.setParent(this);
  +         aroundInvalidDecoration.encodeEnd(context);
  +      }
  +      context.getResponseWriter().endElement("span");
  +
  +      Contexts.getEventContext().remove("invalid");
  +      Contexts.getEventContext().remove("required");
  +
  +      super.encodeEnd(context);
      }
      
      @Override
  -   protected void renderContent(FacesContext context, UIComponent thiz) throws IOException
  +   public void encodeChildren(FacesContext facesContext) throws IOException
  +   {
  +      boolean hasMessage = hasMessage();
  +
  +      UIComponent beforeDecoration = getDecoration("beforeField");
  +      UIComponent beforeInvalidDecoration = getDecoration("beforeInvalidField");
  +      if ( beforeDecoration!=null && !hasMessage )
  +      {
  +         beforeDecoration.setParent(this);
  +         JSF.renderChild(facesContext, beforeDecoration);
  +      }
  +      if ( beforeInvalidDecoration!=null && hasMessage )
  +      {
  +         beforeInvalidDecoration.setParent(this);
  +         JSF.renderChild(facesContext, beforeInvalidDecoration);
  +      }
  +      
  +      JSF.renderChildren(facesContext, this);
  +      
  +      UIComponent afterDecoration = getDecoration("afterField");
  +      UIComponent afterInvalidDecoration = getDecoration("afterInvalidField");
  +      if ( afterDecoration!=null  && !hasMessage )
  +      {
  +         afterDecoration.setParent(this);
  +         JSF.renderChild(facesContext, afterDecoration);
  +      }
  +      if ( afterInvalidDecoration!=null && hasMessage )
      {
  -      JSF.renderChildren(context, this);
  +         afterInvalidDecoration.setParent(this);
  +         JSF.renderChild(facesContext, afterInvalidDecoration);
  +      }
      }
   
      @Override
  @@ -70,10 +262,4 @@
         return values;
      }
   
  -   @Override
  -   protected void renderChild(FacesContext context, UIComponent thiz) throws IOException
  -   {
  -      renderFieldAndDecorations(context, this);
  -   }
  -
   }
  
  
  
  1.1      date: 2007/03/20 03:41:50;  author: gavin;  state: Exp;jboss-seam/src/ui/org/jboss/seam/ui/HtmlLabelDecoration.java
  
  Index: HtmlLabelDecoration.java
  ===================================================================
  package org.jboss.seam.ui;
  
  import javax.faces.component.EditableValueHolder;
  import javax.faces.component.UIComponent;
  import javax.faces.component.html.HtmlOutputLabel;
  
  
  public class HtmlLabelDecoration extends HtmlOutputLabel
  {
     public static final String COMPONENT_TYPE = "org.jboss.seam.ui.HtmlLabelDecoration";
  
     /**
      * A depth-first search for an EditableValueHolder
      */
     protected static UIComponent getEditableValueHolder(UIComponent component)
     {
        if (component instanceof EditableValueHolder)
        {
           return component.isRendered() ? component : null;
        }
        for (Object child: component.getChildren())
        {
           if (child instanceof UIComponent)
           {
              UIComponent evh = getEditableValueHolder( (UIComponent) child );
              if (evh!=null) return evh;
           }
        }
        return null;
     }
  
     private static String getInputId(UIComponent cmp)
     {
        String forId = cmp instanceof UIDecorate ?
                 ( (UIDecorate) cmp ).getFor() : null;
        if (forId==null)
        {
           UIComponent evh = getEditableValueHolder(cmp);
           return evh==null ? null : evh.getId();
        }
        else
        {
           return forId;
        }
     }
     
     private String getFor(UIComponent component)
     {
        
        if ( component.getParent()==null )
        {
           return null;
        }
        else if (component instanceof UIDecorate) 
        {
           return getInputId(component);
        }
        else
        {
           return getFor( component.getParent() );
        }
     }
  
     @Override
     public String getFor()
     {
        return getFor(this);
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list