You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ca...@apache.org on 2007/03/11 12:46:45 UTC
svn commit: r516893 - in /myfaces/tomahawk/trunk/sandbox/core/src/main:
java/org/apache/myfaces/convert/ex/ resources-facesconfig/META-INF/
resources/org/apache/myfaces/custom/clientvalidation/validationscript/resource/
Author: cagatay
Date: Sun Mar 11 04:46:45 2007
New Revision: 516893
URL: http://svn.apache.org/viewvc?view=rev&rev=516893
Log:
Add extended FloatConverter with Client Side Conversion capability
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java (with props)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/clientvalidation/validationscript/resource/converters.js
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java?view=auto&rev=516893
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java Sun Mar 11 04:46:45 2007
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.myfaces.convert.ex;
+
+import org.apache.myfaces.custom.clientvalidation.common.ClientConverter;
+
+/**
+ * @author cagatay (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class FloatConverter extends javax.faces.convert.FloatConverter implements ClientConverter{
+
+ public String getScriptFunction() {
+ return "tomahawk.FloatConverter()";
+ }
+
+ public String getScriptResource() {
+ return null;
+ }
+}
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/convert/ex/FloatConverter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?view=diff&rev=516893&r1=516892&r2=516893
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml Sun Mar 11 04:46:45 2007
@@ -641,6 +641,14 @@
<converter-for-class>java.lang.Double</converter-for-class>
<converter-class>org.apache.myfaces.convert.ex.DoubleConverter</converter-class>
</converter>
+ <converter>
+ <converter-id>javax.faces.Float</converter-id>
+ <converter-class>org.apache.myfaces.convert.ex.FloatConverter</converter-class>
+ </converter>
+ <converter>
+ <converter-for-class>java.lang.Float</converter-for-class>
+ <converter-class>org.apache.myfaces.convert.ex.FloatConverter</converter-class>
+ </converter>
<validator>
<validator-id>javax.faces.Length</validator-id>
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/clientvalidation/validationscript/resource/converters.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/clientvalidation/validationscript/resource/converters.js?view=diff&rev=516893&r1=516892&r2=516893
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/clientvalidation/validationscript/resource/converters.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/clientvalidation/validationscript/resource/converters.js Sun Mar 11 04:46:45 2007
@@ -64,4 +64,29 @@
}
return null;
}
+}
+
+tomahawk.FloatConverter = function() {
+
+ this.CONVERSION_MESSAGE_ID = "javax.faces.convert.FloatConverter.CONVERSION";
+
+ this.getAsObject = function(context,uiinput,value) {
+
+ if( value != null ) {
+ //TODO trim
+ if( value.length > 0) {
+ var floatRegExp = /^(\+|-)?\d*\.?\d*([eE]\d+)?[fF]?$/;
+ var isFloat = floatRegExp.test(value);
+ if( !isFloat ) {
+ var facesMessage = tomahawk.MessageUtils.getMessage(tomahawk.FacesMessage.SEVERITY_ERROR,this.CONVERSION_MESSAGE_ID,new Array(uiinput.id,value))
+ throw new tomahawk.ConverterException( facesMessage );
+ }
+ else {
+ var convertedValue = parseFloat( value );
+ return convertedValue;
+ }
+ }
+ }
+ return null;
+ }
}