myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmarinsc...@apache.org
Subject cvs commit: incubator-myfaces/webapps/examples/web countryTableForm.jsp
Date Wed, 26 Jan 2005 13:27:16 GMT
mmarinschek    2005/01/26 05:27:16

  Modified:    src/components/org/apache/myfaces/renderkit/html/ext
                        HtmlMessageRenderer.java
               src/jsfapi/javax/faces/component _ComponentUtils.java
               src/share/org/apache/myfaces/renderkit/html
                        HtmlMessageRendererBase.java
                        HtmlMessagesRendererBase.java
               src/share/org/apache/myfaces/renderkit RendererUtils.java
               webapps/examples/web countryTableForm.jsp
  Log:
  The x:message tags are now extended to use the column-name as a label for all inputs in
an x:dataTable, without having to specify additional information.
  
  Revision  Changes    Path
  1.8       +69 -6     incubator-myfaces/src/components/org/apache/myfaces/renderkit/html/ext/HtmlMessageRenderer.java
  
  Index: HtmlMessageRenderer.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/renderkit/html/ext/HtmlMessageRenderer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HtmlMessageRenderer.java	22 Jan 2005 19:47:44 -0000	1.7
  +++ HtmlMessageRenderer.java	26 Jan 2005 13:27:16 -0000	1.8
  @@ -25,18 +25,26 @@
   
   import javax.faces.application.FacesMessage;
   import javax.faces.component.UIComponent;
  +import javax.faces.component.UIColumn;
  +import javax.faces.component.UIInput;
  +import javax.faces.component.ValueHolder;
   import javax.faces.component.html.HtmlOutputLabel;
  +import javax.faces.component.html.HtmlOutputText;
   import javax.faces.context.FacesContext;
   import java.io.IOException;
   import java.text.MessageFormat;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.List;
   
   /**
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.8  2005/01/26 13:27:16  mmarinschek
  + * The x:message tags are now extended to use the column-name as a label for all inputs
in an x:dataTable, without having to specify additional information.
  + *
    * Revision 1.7  2005/01/22 19:47:44  mmarinschek
    * Message rendering updated - if a validation exception needs to be rendered, the id of
the component is replaced with a label.
    *
  @@ -146,6 +154,28 @@
       {
           Map outputLabelMap = getOutputLabelMap(facesContext);
           MessageLabelInfo info = ((MessageLabelInfo)outputLabelMap.get(inputClientId));
  +
  +        if(info == null)
  +        {
  +            UIComponent comp = facesContext.getViewRoot().findComponent(inputClientId);
  +
  +            UIComponent parent=comp;
  +
  +            while(parent != null && !((parent=parent.getParent())instanceof UIColumn));
  +
  +            if(parent != null)
  +            {
  +                UIColumn column = (UIColumn) parent;
  +
  +                if(column.getHeader()!=null)
  +                {
  +                    UIComponent header = column.getHeader();
  +
  +                    return getComponentText(facesContext, header);
  +                }
  +            }
  +        }
  +
           return info==null?null:info.getText();
       }
   
  @@ -153,6 +183,17 @@
       {
           Map outputLabelMap = getOutputLabelMap(facesContext);
           MessageLabelInfo info = ((MessageLabelInfo)outputLabelMap.get(inputClientId));
  +
  +        if(info == null)
  +        {
  +            UIComponent comp = facesContext.getViewRoot().findComponent(inputClientId);
  +
  +            if(comp!=null)
  +            {
  +                return comp.getId();
  +            }
  +        }
  +
           return info==null?null:(info.getForComponent()==null?null:info.getForComponent().getId());
       }
   
  @@ -192,7 +233,7 @@
                   {
                       map.put(input.getClientId(facesContext),
                               new MessageLabelInfo(
  -                                    input,getLabelText(facesContext, (HtmlOutputLabel)child)));
  +                                    input,getComponentText(facesContext, (HtmlOutputLabel)child)));
                   }
               }
               else
  @@ -202,12 +243,34 @@
           }
       }
   
  -    private static String getLabelText(FacesContext facesContext, HtmlOutputLabel label)
  +    private static String getComponentText(FacesContext facesContext, UIComponent component)
       {
  -        String text = RendererUtils.getStringValue(facesContext, label);
  +        String text = null;
  +
  +        if(component instanceof ValueHolder)
  +        {
  +            text=RendererUtils.getStringValue(facesContext, component);
  +        }
  +
           if (text == null)
           {
  -            //TODO: traverse children and append OutputText and/or OutputMessage texts
  +            StringBuffer buf = new StringBuffer();
  +            List li = component.getChildren();
  +
  +            for (int i = 0; i < li.size(); i++)
  +            {
  +                UIComponent uiComponent = (UIComponent) li.get(i);
  +
  +                if(uiComponent instanceof HtmlOutputText)
  +                {
  +                    String str = RendererUtils.getStringValue(facesContext, component);
  +
  +                    if(str!=null)
  +                        buf.append(str);
  +                }
  +            }
  +
  +            text = buf.toString();
           }
           return text;
       }
  
  
  
  1.5       +26 -4     incubator-myfaces/src/jsfapi/javax/faces/component/_ComponentUtils.java
  
  Index: _ComponentUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/jsfapi/javax/faces/component/_ComponentUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- _ComponentUtils.java	1 Jul 2004 22:00:49 -0000	1.4
  +++ _ComponentUtils.java	26 Jan 2005 13:27:16 -0000	1.5
  @@ -72,7 +72,7 @@
   
       static UIComponent findComponent(UIComponent findBase, String id)
       {
  -        if (id.equals(findBase.getId()))
  +        if (idsAreEqual(id,findBase))
           {
               return findBase;
           }
  @@ -85,7 +85,7 @@
                   UIComponent find = findComponent(childOrFacet, id);
                   if (find != null) return find;
               }
  -            else if (id.equals(childOrFacet.getId()))
  +            else if (idsAreEqual(id,childOrFacet))
               {
                   return childOrFacet;
               }
  @@ -94,6 +94,28 @@
           return null;
       }
   
  +    private static boolean idsAreEqual(String id, UIComponent cmp)
  +    {
  +        if(id.equals(cmp.getId()))
  +            return true;
  +
  +        if(cmp instanceof UIData)
  +        {
  +            UIData uiData = ((UIData) cmp);
  +
  +            if(uiData.getRowIndex()==-1)
  +            {
  +                return id.startsWith(cmp.getId());
  +            }
  +            else
  +            {
  +                return id.equals(cmp.getId()+"_"+uiData.getRowIndex());
  +            }
  +        }
  +
  +        return false;
  +    }
  +
   
       static void callValidators(FacesContext context, UIInput input, Object convertedValue)
       {
  
  
  
  1.12      +5 -2      incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlMessageRendererBase.java
  
  Index: HtmlMessageRendererBase.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlMessageRendererBase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- HtmlMessageRendererBase.java	22 Jan 2005 19:47:44 -0000	1.11
  +++ HtmlMessageRendererBase.java	26 Jan 2005 13:27:16 -0000	1.12
  @@ -34,6 +34,9 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.12  2005/01/26 13:27:16  mmarinschek
  + * The x:message tags are now extended to use the column-name as a label for all inputs
in an x:dataTable, without having to specify additional information.
  + *
    * Revision 1.11  2005/01/22 19:47:44  mmarinschek
    * Message rendering updated - if a validation exception needs to be rendered, the id of
the component is replaced with a label.
    *
  @@ -115,7 +118,7 @@
           FacesMessage facesMessage = (FacesMessage)messageIterator.next();
   
           // and render it
  -        renderSingleFacesMessage(facesContext, message, facesMessage, clientId);
  +        renderSingleFacesMessage(facesContext, message, facesMessage,clientId);
       }
   
   
  
  
  
  1.5       +7 -3      incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlMessagesRendererBase.java
  
  Index: HtmlMessagesRendererBase.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlMessagesRendererBase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HtmlMessagesRendererBase.java	23 Dec 2004 13:03:09 -0000	1.4
  +++ HtmlMessagesRendererBase.java	26 Jan 2005 13:27:16 -0000	1.5
  @@ -35,6 +35,9 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.5  2005/01/26 13:27:16  mmarinschek
  + * The x:message tags are now extended to use the column-name as a label for all inputs
in an x:dataTable, without having to specify additional information.
  + *
    * Revision 1.4  2004/12/23 13:03:09  mmarinschek
    * id's not rendered (or not conditionally rendered); changes in jslistener to support
both ie and firefox now
    *
  @@ -132,7 +135,8 @@
               renderSingleFacesMessage(facesContext,
                                        messages,
                                        (FacesMessage)messagesIterator.next(),
  -                                     messagesIterator.getClientId());
  +                                        messagesIterator.getClientId());
  +
               writer.endElement(HTML.TD_ELEM);
               writer.endElement(HTML.TR_ELEM);
           }
  
  
  
  1.22      +40 -3     incubator-myfaces/src/share/org/apache/myfaces/renderkit/RendererUtils.java
  
  Index: RendererUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/RendererUtils.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- RendererUtils.java	22 Jan 2005 16:47:17 -0000	1.21
  +++ RendererUtils.java	26 Jan 2005 13:27:16 -0000	1.22
  @@ -21,6 +21,7 @@
   import org.apache.commons.logging.LogFactory;
   
   import javax.faces.FacesException;
  +import javax.faces.render.Renderer;
   import javax.faces.component.*;
   import javax.faces.component.html.HtmlInputText;
   import javax.faces.context.FacesContext;
  @@ -37,6 +38,9 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.22  2005/01/26 13:27:16  mmarinschek
  + * The x:message tags are now extended to use the column-name as a label for all inputs
in an x:dataTable, without having to specify additional information.
  + *
    * Revision 1.21  2005/01/22 16:47:17  mmarinschek
    * fixing bug with validation not called if the submitted value is empty; an empty string
is submitted instead if the component is enabled.
    *
  @@ -147,7 +151,40 @@
               getPathToComponent(component.getParent(),buf);
           }
       }
  -    
  +
  +    public static String getConcatenatedId(FacesContext context, UIComponent container,
  +                                           String clientId)
  +    {
  +        UIComponent child = container.findComponent(clientId);
  +
  +        if(child == null)
  +                return clientId;
  +
  +        return getConcatenatedId(context, child);
  +    }
  +
  +    public static String getConcatenatedId(FacesContext context, UIComponent component)
  +    {
  +        if (context == null) throw new NullPointerException("context");
  +
  +        StringBuffer idBuf = new StringBuffer();
  +
  +        idBuf.append(component.getId());
  +
  +        UIComponent parent = null;
  +
  +        while((parent = component.getParent())!=null)
  +        {
  +            if(parent instanceof NamingContainer)
  +            {
  +                idBuf.insert(0,NamingContainer.SEPARATOR_CHAR);
  +                idBuf.insert(0,parent.getId());
  +            }
  +        }
  +
  +        return idBuf.toString();
  +    }
  +
       public static Boolean getBooleanValue(UIComponent component)
       {
           if (!(component instanceof ValueHolder))
  
  
  
  1.15      +3 -2      incubator-myfaces/webapps/examples/web/countryTableForm.jsp
  
  Index: countryTableForm.jsp
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/countryTableForm.jsp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- countryTableForm.jsp	18 Dec 2004 16:05:37 -0000	1.14
  +++ countryTableForm.jsp	26 Jan 2005 13:27:16 -0000	1.15
  @@ -57,9 +57,10 @@
           <f:facet name="body">
               <h:panelGroup id="body">
   
  -               <h:messages errorClass="error" showSummary="true" showDetail="true" />
  -
                   <h:form id="form" style="display:inline" >
  +
  +                <x:messages errorClass="error" showSummary="true" showDetail="true"
/>
  +
                   <x:dataTable id="data"
                           styleClass="standardTable"
                           headerClass="standardTable_Header"
  
  
  

Mime
View raw message