⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rendererutils.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.myfaces.renderkit;import org.apache.myfaces.util.HashMapUtils;import org.apache.commons.logging.Log;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;import javax.faces.convert.Converter;import javax.faces.convert.ConverterException;import javax.faces.el.ValueBinding;import javax.faces.el.PropertyNotFoundException;import javax.faces.model.SelectItem;import java.io.IOException;import java.lang.reflect.Array;import java.util.*;/** * @author Manfred Geiler (latest modification by $Author: manolito $) * @version $Revision: 1.23 $ $Date: 2005/04/06 10:21:55 $ * $Log: RendererUtils.java,v $ * Revision 1.23  2005/04/06 10:21:55  manolito * MYFACES-149 fix for NullPointerException in _SharedRendererUtils.getConvertedUISelectManyValue * * 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. * * Revision 1.20  2005/01/18 22:43:05  svieujot * Fix some bugs where converter wasn't used to determine selected values. * This caused for examples the list, checkbox and radio based components to bug when the backing bean value type is a primitive. * * Revision 1.19  2005/01/09 18:15:12  mmarinschek * small changes - better error handling, label renderer supports more hooks for sub-classes * * Revision 1.18  2005/01/07 01:54:35  svieujot * radioRenderer wasn't looking at the submitted value. * * Revision 1.17  2005/01/05 23:06:43  svieujot * Fix bug : checkbox wasn't looking at the submitted value. * * Revision 1.16  2004/12/14 14:12:33  mmarinschek * PR: * Obtained from: * Submitted by:	 * Reviewed by: * * Revision 1.15  2004/12/09 12:18:43  mmarinschek * changes in Calendar-Renderer to check for submitted-value first * * Revision 1.14  2004/10/13 11:51:01  matze * renamed packages to org.apache * * Revision 1.13  2004/09/06 08:41:49  tinytoony * changes to calendar - rendering wrong weekday, check output-text behavior * * Revision 1.12  2004/07/01 22:01:18  mwessendorf * ASF switch * * Revision 1.11  2004/06/23 12:42:26  tinytoony * just a tad more information ;) * * Revision 1.10  2004/05/18 14:31:40  manolito * user role support completely moved to components source tree * * Revision 1.9  2004/04/28 10:38:33  tinytoony * child is of type added to exception message * * Revision 1.8  2004/04/28 10:37:14  tinytoony * child is of type added to exception message * * Revision 1.7  2004/04/28 08:17:11  tinytoony * child is of type added to exception message * * Revision 1.6  2004/04/07 08:21:10  manolito * handling of select items with label == null * * Revision 1.5  2004/04/06 15:33:21  manolito * getStringValue must return submitted value if any * */public class RendererUtils{    private static final Log log = LogFactory.getLog(RendererUtils.class);    public static final String SELECT_ITEM_LIST_ATTR = RendererUtils.class.getName() + ".LIST";    public static final String EMPTY_STRING = new String();    public static String getPathToComponent(UIComponent component)    {        StringBuffer buf = new StringBuffer();        if(component == null)        {            buf.append("{Component-Path : ");            buf.append("[null]}");            return buf.toString();        }        getPathToComponent(component,buf);        buf.insert(0,"{Component-Path : ");        buf.append("}");        return buf.toString();    }    private static void getPathToComponent(UIComponent component, StringBuffer buf)    {        if(component == null)            return;        StringBuffer intBuf = new StringBuffer();        intBuf.append("[Class: ");        intBuf.append(component.getClass().getName());        if(component instanceof UIViewRoot)        {            intBuf.append(",ViewId: ");            intBuf.append(((UIViewRoot) component).getViewId());        }        else        {            intBuf.append(",Id: ");            intBuf.append(component.getId());        }        intBuf.append("]");        buf.insert(0,intBuf);        if(component!=null)        {            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))        {            throw new IllegalArgumentException("Component : "+getPathToComponent(component)                    +"is not a ValueHolder");        }        if (component instanceof EditableValueHolder)        {            Object submittedValue = ((EditableValueHolder)component).getSubmittedValue();            if (submittedValue != null)            {                if (submittedValue instanceof Boolean)                {                    return (Boolean)submittedValue;                }                else                {                    throw new IllegalArgumentException("Expected submitted value of type Boolean for component : "+                            getPathToComponent(component));                }            }        }        Object value = ((ValueHolder)component).getValue();        if (value==null || value instanceof Boolean)        {            return (Boolean) value;        }        else        {            throw new IllegalArgumentException("Expected submitted value of type Boolean for Component : "+                    getPathToComponent(component));        }    }        public static Date getDateValue(UIComponent component)    {        if (!(component instanceof ValueHolder))        {            throw new IllegalArgumentException("Component : "+                    getPathToComponent(component)+"is not a ValueHolder");        }        if (component instanceof EditableValueHolder)        {            Object submittedValue = ((EditableValueHolder)component).getSubmittedValue();            if (submittedValue != null)            {                if (submittedValue instanceof Date)                {                    return (Date)submittedValue;                }                else                {                    throw new IllegalArgumentException(                            "Expected submitted value of type Date for component : "+                            getPathToComponent(component));                }            }        }        Object value = ((ValueHolder)component).getValue();        if (value==null || value instanceof Date)        {            return (Date) value;        }        else        {            throw new IllegalArgumentException("Expected submitted value of type Date for component : "                +getPathToComponent(component));        }    }    public static String getStringValue(FacesContext facesContext,                                        UIComponent component)    {        try        {            if (!(component instanceof ValueHolder))            {                throw new IllegalArgumentException("Component : "+getPathToComponent(component)+"is not a ValueHolder");            }            if (component instanceof EditableValueHolder)            {                Object submittedValue = ((EditableValueHolder)component).getSubmittedValue();                if (submittedValue != null)                {                    if (submittedValue instanceof String)                    {                        return (String)submittedValue;                    }                    else                    {                        throw new IllegalArgumentException("Expected submitted value of type String for component : "                            +getPathToComponent(component));                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -