Author: alexsmirnov
Date: 2011-01-14 19:56:14 -0500 (Fri, 14 Jan 2011)
New Revision: 21041
Modified:
branches/RF-9797/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java
branches/RF-9797/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
Log:
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current wiki
document
https://issues.jboss.org/browse/RF-9797
Modified:
branches/RF-9797/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java
===================================================================
---
branches/RF-9797/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -79,9 +79,14 @@
first = false;
}
- target.append("){").append(body).append("}");
+ target.append("){");appendBody(target);
+ target.append("}");
}
+ protected void appendBody(Appendable target) throws IOException {
+ target.append(body);
+ }
+
/**
* @return the name
*/
Modified:
branches/RF-9797/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java
===================================================================
---
branches/RF-9797/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -43,5 +43,51 @@
public String getSummary() {
return summary;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((this.detail == null) ? 0 : this.detail.hashCode());
+ result = prime * result + this.severity;
+ result = prime * result + ((this.summary == null) ? 0 :
this.summary.hashCode());
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Message other = (Message) obj;
+ if (this.detail == null) {
+ if (other.detail != null) {
+ return false;
+ }
+ } else if (!this.detail.equals(other.detail)) {
+ return false;
+ }
+ if (this.severity != other.severity) {
+ return false;
+ }
+ if (this.summary == null) {
+ if (other.summary != null) {
+ return false;
+ }
+ } else if (!this.summary.equals(other.summary)) {
+ return false;
+ }
+ return true;
+ }
}
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -1,32 +1,30 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
import java.util.Collections;
import org.richfaces.resource.ResourceKey;
public class AjaxOnlyScript extends ValidatorScriptBase {
+ public static final Iterable<ResourceKey> AJAX_LIBRARIES =
Collections.singleton(ResourceKey.create("ajax.reslib",
+ "org.richfaces"));
- public static final Iterable<ResourceKey>
AJAX_LIBRARIES=Collections.singleton(ResourceKey.create("ajax.reslib",
"org.richfaces"));
-
private final String ajaxScript;
public AjaxOnlyScript(String ajaxScript) {
super();
this.ajaxScript = ajaxScript;
-
+
}
public Iterable<ResourceKey> getResources() {
return AJAX_LIBRARIES;
}
- @Override
- protected Object buildBody() {
- return ajaxScript;
- }
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -37,7 +35,9 @@
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -61,5 +61,12 @@
}
return true;
}
-
+
+ @Override
+ protected void appendBody(Appendable target) throws IOException {
+ target.append("if(!").append(DISABLE_AJAX).append("){(");
+ appendAjaxFunction(target, ajaxScript);
+
target.append(").call(").append(ELEMENT).append(",").append(EVENT).append(",").append(CLIENT_ID).append(");");
+ target.append(("}"));
+ }
}
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -1,5 +1,6 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
import java.util.Collection;
import org.richfaces.resource.ResourceKey;
@@ -11,26 +12,27 @@
- final String ajaxScript;
+ private final String ajaxScript;
+ private final Iterable<ResourceKey> resources;
public ClientAndAjaxScript(LibraryScriptFunction clientSideConverterScript,
Collection<? extends LibraryScriptFunction> validatorScripts, String
ajaxScript) {
super(clientSideConverterScript,validatorScripts);
this.ajaxScript = ajaxScript;
+ resources =
Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
}
@Override
public Iterable<ResourceKey> getResources() {
- return Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
+ return resources;
}
- protected void finishValidation(StringBuilder body) {
- // AJAX callback
- body.append("if(!").append(DISABLE_AJAX).append("){\n");
- body.append(ajaxScript).append(EOL).append("}\n");
+
+ @Override
+ protected void appendAjaxParameter(Appendable target) throws IOException {
+ appendAjaxParameter(target, ajaxScript);
}
-
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -1,29 +1,31 @@
package org.richfaces.renderkit.html;
-import java.util.Arrays;
+import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Map;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
+import com.google.common.collect.UnmodifiableIterator;
public class ClientOnlyScript extends ValidatorScriptBase {
+ private static final ResourceKey CSV_RESOURCE =
ResourceKey.create("csv.reslib", "org.richfaces");
protected final LibraryScriptFunction converter;
- protected final Collection<? extends LibraryScriptFunction> validators;
+ protected final ImmutableList<? extends LibraryScriptFunction> validators;
private final ImmutableSet<ResourceKey> resources;
public ClientOnlyScript(LibraryScriptFunction clientSideConverterScript,
Collection<? extends LibraryScriptFunction> validatorScripts) {
super();
this.converter = clientSideConverterScript;
- this.validators = validatorScripts;
+ this.validators = ImmutableList.copyOf(validatorScripts);
LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
if (null != converter) {
Iterables.addAll(resources, converter.getResources());
@@ -31,6 +33,7 @@
for (LibraryScriptFunction scriptString : validators) {
Iterables.addAll(resources, scriptString.getResources());
}
+ resources.add(CSV_RESOURCE);
this.resources = ImmutableSet.copyOf(resources);
}
@@ -39,51 +42,47 @@
}
@Override
- protected Object buildBody() {
- StringBuilder body = new StringBuilder();
- // Get component value by clientId.
- /*
- * body.append("var
").append(ClientValidatorRenderer.VALUE_VAR).append("=");
- * GET_VALUE_FUNCTION.appendScriptToStringBuilder(body); body.append(EOL); // Try
client-side validation
- * body.append("try {\n"); // convert value
- * body.append("var
").append(ClientValidatorRenderer.CONVERTED_VALUE_VAR).append("=");
- * converter.appendScriptToStringBuilder(body); body.append(EOL); // call
validators for (ScriptWithDependencies
- * validatorScript : validators) {
validatorScript.appendScriptToStringBuilder(body); body.append(EOL); }
- * finishValidation(body); body.append("return true;\n"); // Catch
errors body.append("} catch(e) {\n");
- * SEND_ERROR_FUNCTION.appendScriptToStringBuilder(body);body.append(EOL);
body.append("return false;\n}");
- */
- body.append("var c;");
- if (null!=converter) {
- body.append("c=");
- body.append(converter.getClientScript());
- body.append("EOL");
+ protected void appendParameters(Appendable target) throws IOException {
+ if (null != converter) {
+ target.append(CONVERTER).append(":");
+ appendConverter(target, converter);
+ target.append(",");
}
- body.append("var v=[");
-
- int i = validators.size();
- for (LibraryScriptFunction validatorScript : validators) {
- body.append(validatorScript.getClientScript());
- if (--i>0) {
- body.append(",");
- }
+ target.append(VALIDATORS).append(":[");
+
+ UnmodifiableIterator<? extends LibraryScriptFunction> iterator =
validators.iterator();
+ while (iterator.hasNext()) {
+ LibraryScriptFunction validatorScript = (LibraryScriptFunction)
iterator.next();
+ appendValidator(target, validatorScript);
+ if (iterator.hasNext()) {
+ target.append(",");
+ }
}
- body.append("];");
-
- JSFunction callValidator =
- new JSFunction("RichFaces.csv.validate", new
JSReference("event"), new JSReference("id"), new JSReference(
- "element"), new JSReference("c"), new
JSReference("v"));
- body.append(callValidator);
- body.append(EOL);
- return body;
+ target.append("]");
+ appendAjaxParameter(target);
}
- protected void finishValidation(StringBuilder body) {
- // clear messages after successful validation
- body.append("if(!").append(DISABLE_AJAX).append("){\n");
- CLEAR_ERROR_FUNCTION.appendScriptToStringBuilder(body);
- body.append(EOL).append("}\n");
+ protected void appendValidator(Appendable target, LibraryScriptFunction
validatorScript) throws IOException {
+ appendConverter(target, validatorScript);
}
+ protected void appendConverter(Appendable target, LibraryScriptFunction converter)
throws IOException {
+
target.append('{').append("f").append(':').append(converter.getName()).append(',');
+ target.append(PARAMS).append(':').append('{');
+ target.append(MESSAGE).append(':');ScriptUtils.appendScript(target,
converter.getMessage());
+ for(Map.Entry<String, ? extends Object> entry:
converter.getParameters().entrySet()){
+ target.append(',');
+ target.append(entry.getKey()).append(':');
+ ScriptUtils.appendScript(target, entry.getValue());
+ }
+ target.append('}');
+ target.append('}');
+ }
+
+ protected void appendAjaxParameter(Appendable target) throws IOException {
+ // This is client-only validation script.
+ }
+
/*
* (non-Javadoc)
*
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -193,11 +193,11 @@
private String createAjaxScript(ClientBehaviorContext behaviorContext,
ClientValidatorBehavior behavior) {
String ajaxScript = behavior.getAjaxScript(behaviorContext);
- ajaxScript = ajaxScript.replace("this", ValidatorScriptBase.ELEMENT);
String clientId = getComponentClientId(behaviorContext);
ajaxScript = replaceTextToVariable(ajaxScript, clientId,
ValidatorScriptBase.CLIENT_ID);
String sourceId = behaviorContext.getSourceId();
if (null != sourceId) {
+ // TODO - send sourceId as separate parameter.
ajaxScript = replaceTextToVariable(ajaxScript, sourceId,
ValidatorScriptBase.ELEMENT);
}
return ajaxScript;
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -23,18 +23,14 @@
package org.richfaces.renderkit.html;
-import java.util.HashMap;
import java.util.Map;
-import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.javascript.LibraryFunction;
import org.richfaces.javascript.Message;
import org.richfaces.resource.ResourceKey;
import org.richfaces.resource.ResourceLibrary;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
/**
* <p class="changed_added_4_0">
@@ -49,9 +45,9 @@
private final ImmutableSet<ResourceKey> resources;
private final String name;
private final Message message;
- private final Object parameters;
+ private final Map<String, ? extends Object> parameters;
- public LibraryScriptFunction(LibraryFunction libraryScript, Message message, Object
parameters) {
+ public LibraryScriptFunction(LibraryFunction libraryScript, Message message,
Map<String, ? extends Object> parameters) {
this.message = message;
this.parameters = parameters;
this.resources = ImmutableSet.copyOf(libraryScript.getResources());
@@ -87,19 +83,10 @@
*
* @return the parameters
*/
- public Object getParameters() {
+ public Map<String, ? extends Object> getParameters() {
return this.parameters;
}
- public String getClientScript() {
- Map <String, Object> hash = Maps.newHashMap();
- hash.put("f", new JSReference(name));
- HashMap <String, Object> params = new HashMap<String, Object>((Map
<String, Object>) parameters);
- params.put("customMessage", message.getSummary());
- hash.put("params", params);
- return ScriptUtils.toScript(hash);
- }
-
/*
* (non-Javadoc)
*
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2011-01-15
00:56:14 UTC (rev 21041)
@@ -6,46 +6,80 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
-public abstract class ValidatorScriptBase extends JSFunctionDefinition implements
ComponentValidatorScript {
+public abstract class ValidatorScriptBase extends JSFunctionDefinition implements
ComponentValidatorScript {
- public static final String ELEMENT = "element";
- public static final JSReference ELEMENT_LITERAL = new JSReference(ELEMENT);
+ public static final String ELEMENT = "e";
+ public static final JSReference ELEMENT_REF = new JSReference(ELEMENT);
public static final String EVENT = "event";
- public static final JSReference EVENT_LITERAL = new JSReference(EVENT);
- public static final String DISABLE_AJAX = "disableAjax";
+ public static final JSReference EVENT_REF = new JSReference(EVENT);
+ public static final String DISABLE_AJAX = "da";
+ public static final JSReference DISABLE_AJAX_REF = new JSReference(DISABLE_AJAX);
public static final String EOL = ";\n";
public static final String CLIENT_ID = "id";
- public static final JSReference CLIENT_ID_LITERAL = new JSReference(CLIENT_ID);
- public static final String SOURCE_ID = "sourceId";
- public static final JSReference SOURCE_ID_LITERAL = new JSReference(SOURCE_ID);
+ public static final JSReference CLIENT_ID_REF = new JSReference(CLIENT_ID);
+ public static final String SOURCE_ID = "sid";
+ public static final JSReference SOURCE_ID_REF = new JSReference(SOURCE_ID);
+ public static final String CONVERTER = "c";
+ public static final JSReference CONVERTER_REF = new JSReference(CONVERTER);
+ public static final String VALIDATORS = "v";
+ public static final JSReference VALIDATORS_REF = new JSReference(VALIDATORS);
+ public static final String AJAX = "a";
+ public static final JSReference AJAX_REF = new JSReference(AJAX);
+ public static final String PARAMS = "p";
+ public static final JSReference PARAMS_REF = new JSReference(PARAMS);
+ public static final String MESSAGE = "m";
+ public static final JSReference MESSAGE_REF = new JSReference(MESSAGE);
+
public static final NullConverterScript NULL_CONVERTER_SCRIPT = new
NullConverterScript();
public static final String CSV_NAMESPACE = "RichFaces.csv.";
- public static final String VALUE_FUNCTION_NAME = CSV_NAMESPACE+"getValue";
- public static final JSFunction GET_VALUE_FUNCTION = new
JSFunction(VALUE_FUNCTION_NAME,CLIENT_ID_LITERAL,ELEMENT_LITERAL);
- public static final JSFunction SEND_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"sendMessage",CLIENT_ID_LITERAL,new
JSReference("e"));
- public static final JSFunction CLEAR_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"clearMessage",CLIENT_ID_LITERAL);
-
- private boolean bodyProcessed = false;
+ public static final String VALUE_FUNCTION_NAME = CSV_NAMESPACE +
"getValue";
+ public static final JSFunction GET_VALUE_FUNCTION = new
JSFunction(VALUE_FUNCTION_NAME, CLIENT_ID_REF, ELEMENT_REF);
+ public static final String VALIDATE_FUNCTION_NAME = CSV_NAMESPACE +
"validate";
+ public static final JSFunction VALIDATE_FUNCTION = new
JSFunction(VALIDATE_FUNCTION_NAME, CLIENT_ID_REF,
+ ELEMENT_REF);
public ValidatorScriptBase() {
- super(CLIENT_ID,ELEMENT,EVENT);
+ super(EVENT, CLIENT_ID, ELEMENT, DISABLE_AJAX);
}
- public void appendScript(Appendable target) throws IOException {
- if(!bodyProcessed){
- // pending RF-9565
- addToBody(buildBody());
- bodyProcessed = true;
- }
- super.appendScript(target);
+ public String createCallScript(String clientId, String sourceId) {
+ JSFunction callFunction =
+ new JSFunction(getName(), EVENT_REF, clientId, null != sourceId ? sourceId :
JSReference.THIS);
+ return callFunction.toScript();
}
- protected abstract Object buildBody();
+ protected void appendParameters(Appendable target) throws IOException {
+ }
- public String createCallScript(String clientId,String sourceId) {
- JSFunction callFunction = new
JSFunction(getName(),clientId,null!=sourceId?sourceId:JSReference.THIS,EVENT_LITERAL);
- return callFunction.toScript();
+ @Override
+ protected void appendBody(Appendable target) throws IOException {
+ appendParametersDefinition(target);
+ appendValidatorCall(target);
}
+ private void appendParametersDefinition(Appendable target) throws IOException {
+ target.append("var ").append(PARAMS).append("={");
+
target.append(DISABLE_AJAX).append(':').append(DISABLE_AJAX).append(',');
+ appendParameters(target);
+ target.append("}").append(EOL);
+ }
+ protected void appendValidatorCall(Appendable target) throws IOException {
+ JSFunction callValidator =
+ new JSFunction(VALIDATE_FUNCTION_NAME, EVENT_REF, CLIENT_ID_REF, ELEMENT_REF,
PARAMS_REF);
+ callValidator.appendScript(target);
+ target.append(EOL);
+ }
+
+ protected void appendAjaxParameter(Appendable target, String ajaxScript) throws
IOException {
+ target.append(AJAX).append(':');
+ appendAjaxFunction(target, ajaxScript);
+ }
+
+ protected void appendAjaxFunction(Appendable target, String ajaxScript) throws
IOException {
+ JSFunctionDefinition ajaxFunction = new JSFunctionDefinition(EVENT, CLIENT_ID);
+ ajaxFunction.addToBody(ajaxScript);
+ ajaxFunction.appendScript(target);
+ }
+
}
\ No newline at end of file
Modified:
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-14
19:38:59 UTC (rev 21040)
+++
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-15
00:56:14 UTC (rev 21041)
@@ -22,6 +22,16 @@
return message;
}
+ var _interpolateFacesMessage = function(msg,id,value){
+ var d = msg.detail?_substitute(msg.detail,id,value):"";
+ var s = msg.summary?_substitute(msg.summary,id,value):"";
+ return {detail:d,summary:s};
+ }
+
+ var _substitute = function(msg,id,value){
+ return msg.replace("{id}",id).replace("{value}",value);
+ }
+
var __getValue = function(id) {
var value;
var element = rf.getDomElement(id);
@@ -49,32 +59,41 @@
sendMessage: function (componentId, message) {
rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId, 'message':message});
},
- validate: function (event, id, element, converter, validators, params) {
+ validate: function (event, id, element, params) {
var value = __getValue(element || id);
+ var convertedValue;
+ var converter = params.c;
if (converter) {
try {
- converter.options.componentId = id;
if (converter.f)
- value = converter.f(value, converter.params);
+ convertedValue = converter.f(value, converter.p);
} catch (e){
- rf.csv.sendMessage(id, e);
+ rf.csv.sendMessage(id, _interpolateFacesMessage(e,id,value));
return false;
}
+ } else {
+ convertedValue = value;
}
+ var validators = params.v;
if (validators) {
var validatorFunction;
try {
for (i=0;i<validators.length;i++) {
validatorFunction = validators[i].f;
if (validatorFunction) {
- validatorFunction(id, value, validators[i].params);
+ validatorFunction(convertedValue, validators[i].p);
}
}
} catch (e) {
- rf.csv.sendMessage(id, e);
+ rf.csv.sendMessage(id, _interpolateFacesMessage(e,id,value));
return false;
}
}
+ if(!params.da && params.a){
+ params.a.call(element,event,id);
+ } else {
+ rf.csv.sendMessage(id, "");
+ }
return true;
},
/*
@@ -113,14 +132,14 @@
"convertByte": function (value, params) {
var result; value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-128 ||
result>127) {
- throw rf.csv.getMessage(params.customMessage, 'BYTE_CONVERTER_BYTE', [value,
0, params.componentId]);
+ throw rf.csv.getMessage(params.m, 'BYTE_CONVERTER_BYTE', [value, 0,
params.componentId]);
}
return result;
},
"convertNumber": function (value, params) {
var result; value=$.trim(value);
if (isNaN(value)) {
- throw rf.csv.getMessage(params.customMessage, 'NUMBER_CONVERTER_NUMBER',
[value, 0, params.componentId]);
+ throw rf.csv.getMessage(params.m, 'NUMBER_CONVERTER_NUMBER', [value, 0,
params.componentId]);
} else {
result = parseInt(value, 10);
}
@@ -129,7 +148,7 @@
"convertShort": function (value, params) {
var result; value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-32768 ||
result>32767) {
- throw rf.csv.getMessage(params.customMessage, 'SHORT_CONVERTER_SHORT',
[value, 0, params.componentId]);
+ throw rf.csv.getMessage(params.m, 'SHORT_CONVERTER_SHORT', [value, 0,
params.componentId]);
}
return result;
}
@@ -139,15 +158,15 @@
* Validators implementation
*/
$.extend(rf.csv, {
- "validateLongRange": function (componentId, value, params) {
+ "validateLongRange": function (value, params) {
var type = typeof value;
if (type != "number") {
if (type != "string") {
- throw rf.csv.getMessage(params.customMessage, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_TYPE', [componentId,
""]);
} else {
value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (value = parseInt(value, 10))==NaN) {
- throw rf.csv.getMessage(params.customMessage, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
}
}
}
@@ -157,28 +176,28 @@
if (isMaxSet && value > params.maximum) {
if (isMinSet) {
- throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(params.m,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
} else {
- throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_MAXIMUM', [params.maximum, componentId]);
+ throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
}
}
if (isMinSet && value < params.minimum) {
if (isMaxSet) {
- throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(params.m,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
} else {
- throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_MINIMUM', [params.minimum, componentId]);
+ throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
}
}
},
- "validateDoubleRange": function (componentId, value, params) {
+ "validateDoubleRange": function (value, params) {
var type = typeof value;
if (type != "number") {
if (type != "string") {
- throw rf.csv.getMessage(params.customMessage, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
} else {
value = $.trim(value);
if (!rf.csv.RE_FLOAT.test(value) || (value = parseFloat(value))==NaN) {
- throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_TYPE', [componentId, ""]);
+ throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
}
}
}
@@ -188,45 +207,45 @@
if (isMaxSet && value > params.maximum) {
if (isMinSet) {
- throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(params.m,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
} else {
- throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_MAXIMUM', [params.maximum, componentId]);
+ throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
}
}
if (isMinSet && value < params.minimum) {
if (isMaxSet) {
- throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(params.m,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
} else {
- throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_MINIMUM', [params.minimum, componentId]);
+ throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
}
}
},
- "validateLength": function (componentId, value, params) {
+ "validateLength": function (value, params) {
if (params.maximum && value.length > params.maximum) {
- throw rf.csv.getMessage(params.customMessage, 'LENGTH_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
+ throw params.m;
}
if (params.minimum && value.length < params.minimum) {
- throw rf.csv.getMessage(params.customMessage, 'LENGTH_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
+ throw params.m
}
},
- "validateRegex": function (componentId, value, params) {
+ "validateRegex": function (value, params) {
if (typeof params.pattern != "string" || params.pattern.length == 0) {
- throw rf.csv.getMessage(params.customMessage,
'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
+ throw rf.csv.getMessage(params.m, 'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
}
var re;
try {
re = new RegExp(params.pattern);
} catch (e) {
- throw rf.csv.getMessage(params.customMessage,
'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
+ throw rf.csv.getMessage(params.m, 'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
}
if (!re.test(value)){
- throw rf.csv.getMessage(params.customMessage, 'REGEX_VALIDATOR_NOT_MATCHED',
[params.pattern]);
+ throw rf.csv.getMessage(params.m, 'REGEX_VALIDATOR_NOT_MATCHED',
[params.pattern]);
}
},
- "validateRequired": function (componentId, value, params) {
+ "validateRequired": function (value, params) {
if (value.length==0) {
- throw rf.csv.getMessage(params.customMessage, 'UIINPUT_REQUIRED',
[componentId]);
+ throw rf.csv.getMessage(params.m, 'UIINPUT_REQUIRED', [componentId]);
}
}
});