[ 
https://issues.apache.org/jira/browse/EMPIREDB-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16986725#comment-16986725
 ] 

Jan Glaubitz commented on EMPIREDB-320:
---------------------------------------

Hi Rainer,

I'd like to change number parsing in TextInputControl to allow custom handling:


{code:java}
    // ------- value parsing -------
    
    protected Object parseNumber(String value, DataType type, Locale locale) {
        switch (type) {
                case INTEGER:
                        return parseInteger(value, locale);
                case DECIMAL:
                case FLOAT:
                        return parseDecimal(value, locale);
                default:
                        throw new InvalidArgumentException("type", type);
        }
    }
    
    protected Object parseInteger(String value, Locale locale) {
        NumberFormat nf = NumberFormat.getIntegerInstance();
        // Parse String
        try {
            return nf.parseObject(value);
        } catch (ParseException pe) {
            throw new NumberFormatException("Not a number: " + value + " 
Exception: " + pe.toString());
        }        
    }
    
    protected Object parseDecimal(String value, Locale locale) {
        NumberFormat nf = NumberFormat.getNumberInstance(locale);
        // Parse String
        try {
            return nf.parseObject(value);
        } catch (ParseException pe) {
            throw new NumberFormatException("Not a number: " + value + " 
Exception: " + pe.toString());
        }  
    }
{code}

and


{code:java}
    @Override
    protected Object parseInputValue(String value, InputInfo ii)
    {
        // Trim
        if (hasFormatOption(ii, "notrim") == false)
        {
            value = value.trim();
        }
        // Check Data Type
        Column column = ii.getColumn();
        DataType type = column.getDataType();
        if (type.isText())
        {
            return value;
        }
        // Check other types
        if (type == DataType.INTEGER)
        {
            return parseNumber(value, type, ii.getLocale());
        }
        if (type == DataType.DECIMAL || type == DataType.FLOAT)
        {
            return parseNumber(value, type, ii.getLocale());
        }
        if (type == DataType.DATE || type == DataType.DATETIME || type == 
DataType.TIMESTAMP)
        {
            return parseDate(value, getDateFormat(column.getDataType(), ii, 
column));
        }
        if (type == DataType.BOOL)
        {
            return ObjectUtils.getBoolean(value);
        }
        if (type == DataType.AUTOINC)
        { // autoinc
            log.error("Autoinc-value cannot be changed.");
            return null;
        }
        // Default
        return value;
    }
{code}

That would allow custom parsing for every locale. Your opinion?

> JSF Input skip default JSF input validations
> --------------------------------------------
>
>                 Key: EMPIREDB-320
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-320
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: JSF2 Extensions
>            Reporter: Rainer Döbele
>            Assignee: Rainer Döbele
>            Priority: Minor
>
> When validating values of e:input or e:control tags, skip the default 
> validations of the child input components.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to