Author: matzew
Date: Wed Jan 24 07:00:36 2007
New Revision: 499425
URL: http://svn.apache.org/viewvc?view=rev&rev=499425
Log:
-first step in making the <tr:numberConverter> working on the client
(ADFFACES-164)
-number is working and no pattern can be set (currently)
-Didn't close bug, only commenting on the new progress here
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java?view=diff&rev=499425&r1=499424&r2=499425
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java
Wed Jan 24 07:00:36 2007
@@ -18,11 +18,20 @@
*/
package org.apache.myfaces.trinidadinternal.convert;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
+import org.apache.myfaces.trinidad.convert.ClientConverter;
+import org.apache.myfaces.trinidadinternal.util.JsonUtils;
+
public final class NumberConverter extends
org.apache.myfaces.trinidad.convert.NumberConverter
+ implements ClientConverter
{
public NumberConverter()
{
@@ -64,4 +73,73 @@
// bug 4214147:
return super.getAsString(context, component, value);
}
+
+ public String getClientConversion(FacesContext context, UIComponent
component)
+ {
+ String hintPattern = this.getHintPattern();
+ Map<String, String> cMessages = null;
+ if(hintPattern != null)
+ {
+ cMessages = new HashMap<String, String>();
+ cMessages.put("hintPattern", hintPattern);
+ }
+
+ return _getTrNumberConverter(context, component, cMessages);
+ }
+
+ public Collection<String> getClientImportNames()
+ {
+ return _IMPORT_NAMES;
+ }
+
+ public String getClientLibrarySource(FacesContext context)
+ {
+ return null;
+ }
+
+ public String getClientScript(FacesContext context, UIComponent component)
+ {
+ return null;
+ }
+
+ private String _getTrNumberConverter(
+ FacesContext context,
+ UIComponent component,
+ Map messages)
+ {
+ StringBuilder outBuffer = new StringBuilder(250);
+
+ outBuffer.append("new TrNumberConverter(");
+
+ String pattern = this.getPattern();
+ String type = this.getType();
+
+ try
+ {
+ JsonUtils.writeString(outBuffer, pattern, false);
+ } catch (Exception e)
+ {
+ outBuffer.append("null");
+ }
+ outBuffer.append(',');
+ try
+ {
+ JsonUtils.writeString(outBuffer, type, false);
+ } catch (Exception e)
+ {
+ outBuffer.append("null");
+ }
+ outBuffer.append(',');
+ try
+ {
+ JsonUtils.writeMap(outBuffer, messages, false);
+ } catch (Exception e)
+ {
+ outBuffer.append("null");
+ }
+ outBuffer.append(')');
+
+ return outBuffer.toString();
+ }
+ private static final Collection<String> _IMPORT_NAMES =
Collections.singletonList( "TrNumberConverter()" );
}
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?view=diff&rev=499425&r1=499424&r2=499425
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
Wed Jan 24 07:00:36 2007
@@ -16,6 +16,85 @@
* specific language governing permissions and limitations
* under the License.
*/
+function TrNumberConverter(
+ pattern,
+ type,
+ messages)
+{
+ this._pattern = pattern;
+ this._type = type;
+ this._messages = messages;
+
+ // for debugging
+ this._class = "TrNumberConverter";
+}
+
+TrNumberConverter.prototype = new TrConverter();
+
+TrNumberConverter.prototype.isConvertible = function()
+{
+ if(this._pattern == null && this._type=="number")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+TrNumberConverter.prototype.getFormatHint = function()
+{
+ if(this._messages && this._messages["hintPattern"])
+ {
+ return TrMessageFactory.createCustomMessage(
+ this._messages["hintPattern"],
+ this._pattern);
+ }
+ else
+ {
+ if(this._pattern)
+ {
+ return TrMessageFactory.createMessage(
+ "org.apache.myfaces.trinidad.convert.NumberConverter.FORMAT_HINT",
+ this._pattern);
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
+
+TrNumberConverter.prototype.getAsString = function(
+ number,
+ label
+ )
+{
+ return "" + number;
+}
+
+TrNumberConverter.prototype.getAsObject = function(
+ numberString,
+ label
+ )
+{
+ if(this.isConvertible())
+ {
+ return _decimalParse(numberString,
+ this._messages,
+ "org.apache.myfaces.trinidad.convert.NumberConverter",
+ null,
+ null,
+ null,
+ null,
+ label);
+ }
+ else
+ {
+ return numberString;
+ }
+}
function TrIntegerConverter(
message,
maxPrecision,
@@ -882,8 +961,16 @@
return result;
}
}
-
- facesMessage = _createFacesMessage( standardKey+".CONVERT",
+ var usedKey = null;
+ if(standardKey.indexOf("NumberConverter")==-1)
+ {
+ usedKey = standardKey+".CONVERT";
+ }
+ else
+ {
+ usedKey = standardKey+".CONVERT_NUMBER";
+ }
+ facesMessage = _createFacesMessage( usedKey,
label,
numberString);
throw new TrConverterException(facesMessage);
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js?view=diff&rev=499425&r1=499424&r2=499425
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
Wed Jan 24 07:00:36 2007
@@ -620,6 +620,16 @@
*/
TrConverter.prototype.getAsObject = function(value, label){}
+/**
+ * This should only be false if there is an only server side converter but no
+ * client side converter. But still it is possible to send down the format
hint.
+ *
+ * By default this function returns true.
+ */
+TrConverter.prototype.isConvertible = function()
+{
+ return true;
+}
/**
* Validator "interface" similar to javax.faces.validator.Validator,