[jboss-cvs] jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component ...

Peter Muir peter at bleepbleep.org.uk
Wed Mar 28 08:52:14 EDT 2007


  User: pmuir   
  Date: 07/03/28 08:52:14

  Modified:    seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component   
                        UICache.java UISeamCommandBase.java
  Added:       seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component   
                        UIDecorate.java
  Log:
  More ui examples, better ant integration for cdk, lots of fixes to button and link
  
  Revision  Changes    Path
  1.2       +2 -2      jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UICache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UICache.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UICache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UICache.java	20 Mar 2007 17:58:58 -0000	1.1
  +++ UICache.java	28 Mar 2007 12:52:14 -0000	1.2
  @@ -41,9 +41,9 @@
         return COMPONENT_FAMILY;
      }
      
  -   public abstract Boolean getEnabled();
  +   public abstract boolean isEnabled();
      
  -   public abstract void setEnabled(Boolean enabled);
  +   public abstract void setEnabled(boolean enabled);
      
      public abstract String getKey();
      
  
  
  
  1.4       +10 -104   jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UISeamCommandBase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UISeamCommandBase.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UISeamCommandBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- UISeamCommandBase.java	23 Mar 2007 22:24:25 -0000	1.3
  +++ UISeamCommandBase.java	28 Mar 2007 12:52:14 -0000	1.4
  @@ -1,9 +1,6 @@
   package org.jboss.seam.ui.component;
   
  -import java.io.IOException;
   import java.io.UnsupportedEncodingException;
  -import java.net.URLEncoder;
  -import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Map;
   import java.util.Set;
  @@ -21,100 +18,20 @@
   
   import org.jboss.seam.core.Conversation;
   import org.jboss.seam.core.Pages;
  -import org.jboss.seam.pages.Page;
  +import org.jboss.seam.ui.util.UrlBuilder;
   
   public abstract class UISeamCommandBase extends UIOutput implements ActionSource
   {
   
      private String encodedUrl;
   
  -   private class Url
  -   {
  -      private String encodedUrl;
  -
  -      private Map<String, String> parameters;
  -
  -      private String fragment;
  -
  -      private String characterEncoding;
  -
  -      private Page page;
  -
  -      public Url(String viewId, String fragment)
  -      {
  -         FacesContext facesContext = FacesContext.getCurrentInstance();
  -         String url = facesContext.getApplication().getViewHandler().getActionURL(facesContext,
  -                  viewId);
  -         String encodedUrl = facesContext.getExternalContext().encodeActionURL(url);
  -         encodedUrl = Pages.instance().encodeScheme(viewId, facesContext, encodedUrl);
  -         characterEncoding = facesContext.getResponseWriter().getCharacterEncoding();
  -         page = Pages.instance().getPage(viewId);
  -         this.encodedUrl = url;
  -         this.fragment = fragment;
  -         this.parameters = new HashMap<String, String>();
  -      }
  -
  -      private String urlEncode(String value) throws UnsupportedEncodingException
  -      {
  -         return characterEncoding == null ? URLEncoder.encode(value) : URLEncoder.encode(value,
  -                  characterEncoding);
  -      }
  -
  -      public void addParameter(UIParameter parameter) throws UnsupportedEncodingException
  -      {
  -         String value = parameter.getValue() == null ? "" : parameter.getValue().toString();
  -         String name = parameter.getName();
  -         boolean append = true;
  -         if (name.equals(page.getConversationIdParameter().getParameterName())
  -                  && parameters.containsKey(name))
  -         {
  -            append = false;
  -         }
  -         if (append)
  -         {
  -            parameters.put(name, urlEncode(value));
  -         }
  -      }
  -
  -      private String getParameters()
  -      {
  -         String params = "";
  -         for (String key : parameters.keySet())
  -         {
  -            params += "&" + key + "=" + parameters.get(key);
  -         }
  -         if (!"".equals(params))
  -         {
  -            params = "?" + params.substring(1);
  -         }
  -         return params;
  -      }
  -
  -      private String getFragment()
  -      {
  -         if (fragment != null && !"".equals(fragment))
  -         {
  -            return "#" + fragment;
  -         }
  -         else
  -         {
  -            return "";
  -         }
  -      }
  -
  -      public String getEncodedUrl()
  -      {
  -         return encodedUrl + getParameters() + getFragment();
  -      }
  -   }
  -
      public abstract boolean isDisabled();
   
      public abstract void setDisabled(boolean disabled);
   
      public abstract String getView();
   
  -   protected String getUrl() throws UnsupportedEncodingException
  +   public String getUrl() throws UnsupportedEncodingException
      {
         if (encodedUrl == null)
         {
  @@ -125,7 +42,7 @@
               viewId = Pages.getViewId(getFacesContext());
            }
   
  -         Url url = new UISeamCommandBase.Url(viewId, getFragment());
  +         UrlBuilder url = new UrlBuilder(this, viewId, getFragment());
   
            Set<String> usedParameters = new HashSet<String>();
            for (Object child : getChildren())
  @@ -133,6 +50,7 @@
               if (child instanceof UIParameter)
               {
                  usedParameters.add(((UIParameter) child).getName());
  +               url.addParameter((UIParameter) child);
               }
            }
   
  @@ -221,24 +139,6 @@
   
      public abstract String getOnclick();
   
  -   public String getOnClick() throws IOException
  -   {
  -      String onclick = getOnclick();
  -      if (onclick == null)
  -      {
  -         onclick = "";
  -      }
  -      else if (onclick.length() > 0 && !onclick.endsWith(";"))
  -      {
  -         onclick += ";";
  -      }
  -      if (!isDisabled())
  -      {
  -         onclick += "location.href='" + getUrl() + "'";
  -      }
  -      return onclick;
  -   }
  -
      public abstract void setOnclick(String onclick);
   
      public UISelection getSelection()
  @@ -301,4 +201,10 @@
         return null;
      }
   
  +   @Override
  +   public boolean getRendersChildren()
  +   {
  +      return true;
  +   }
  +
   }
  
  
  
  1.1      date: 2007/03/28 12:52:14;  author: pmuir;  state: Exp;jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/component/UIDecorate.java
  
  Index: UIDecorate.java
  ===================================================================
  package org.jboss.seam.ui.component;
  
  import javax.faces.component.EditableValueHolder;
  import javax.faces.component.UIComponent;
  import javax.faces.component.UIComponentBase;
  import javax.faces.context.FacesContext;
  
  public abstract class UIDecorate extends UIComponentBase
  {
  
     public static final String COMPONENT_TYPE = "org.jboss.seam.ui.UIDecorate";
     public static final String COMPONENT_FAMILY = "org.jboss.seam.ui.Decorate";
  
     public 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;
     }
  
     public 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;
     }
  
     public 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)
           {
              UIComponent evh = getEditableValueHolder( (UIComponent) child );
              if (evh!=null) return evh;
           }
        }
        return null;
     }
  
     public abstract String getFor();
  
     public abstract void setFor(String forId);
  
     public 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() );
     }
  }
  
  



More information about the jboss-cvs-commits mailing list