Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
  * regarding copyright ownership.  The ASF licenses this file
  * to you 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 javax.faces.convert;
see Javadoc of JSF Specification

Author(s):
Thomas Spiegl (latest modification by $Author: grantsmith $)
Version:
$Revision: 472555 $ $Date: 2006-11-08 18:30:58 +0100 (Mi, 08 Nov 2006) $
public class DoubleConverter
        implements Converter
    // API FIELDS
	// the wrong string javax.faces.DoubleTime is required to be compatible with JSF RI and its TCK tests
    public static final String CONVERTER_ID = "javax.faces.DoubleTime";
    private static final String CONVERSION_MESSAGE_ID = "javax.faces.convert.DoubleConverter.CONVERSION";
    // CONSTRUCTORS
    public DoubleConverter()
    {
    }
    // METHODS
    public Object getAsObject(FacesContext facesContextUIComponent uiComponentString value)
    {
        if (facesContext == nullthrow new NullPointerException("facesContext");
        if (uiComponent == nullthrow new NullPointerException("uiComponent");
        if (value != null)
        {
            value = value.trim();
            if (value.length() > 0)
            {
                try
                {
                    return Double.valueOf(value);
                }
                catch (NumberFormatException e)
                {
                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
                                                                               ,
                                                                               new Object[]{uiComponent.getId(),value}), e);
                }
            }
        }
        return null;
    }
    public String getAsString(FacesContext facesContextUIComponent uiComponentObject value)
    {
        if (facesContext == nullthrow new NullPointerException("facesContext");
        if (uiComponent == nullthrow new NullPointerException("uiComponent");
        if (value == null)
        {
            return "";
        }
        if (value instanceof String)
        {
            return (String)value;
        }
        try
        {
            return Double.toString(((Number)value).doubleValue());
        }
        catch (Exception e)
        {
            throw new ConverterException(e);
        }
    }
New to GrepCode? Check out our FAQ X