Author: alexsmirnov
Date: 2011-01-19 02:55:42 -0500 (Wed, 19 Jan 2011)
New Revision: 21067
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/validator/FacesValidatorServiceImpl.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
Length validator working.
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-19
01:02:11 UTC (rev 21066)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-19
07:55:42 UTC (rev 21067)
@@ -68,15 +68,10 @@
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(PARAMS).append(':');ScriptUtils.appendScript(target,
converter.getParameters());
+ target.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 {
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-01-19
01:02:11 UTC (rev 21066)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-01-19
07:55:42 UTC (rev 21067)
@@ -40,7 +40,18 @@
if (component instanceof DoubleRangeValidator) {
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
} else if (component instanceof LengthValidator) {
- messageId = LengthValidator.MAXIMUM_MESSAGE_ID;
+ LengthValidator validator = (LengthValidator) component;
+ if(validator.getMaximum() >0){
+ if(validator.getMinimum()>0){
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ } else {
+ messageId = LengthValidator.MAXIMUM_MESSAGE_ID;
+ }
+ } else if( validator.getMinimum()>0){
+ messageId = LengthValidator.MINIMUM_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
+ }
} else if (component instanceof LongRangeValidator) {
messageId = LongRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
} else if (component instanceof RegexValidator) {
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-19
01:02:11 UTC (rev 21066)
+++
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-19
07:55:42 UTC (rev 21067)
@@ -8,8 +8,7 @@
var RE_MESSAGE_PATTERN = /\{(\d+)\}/g;
- var __interpolateMessage = function (customMessage, values) {
- var message = customMessage || "";
+ var __interpolateMessage = function (message, values) {
if (message) {
var msgObject =
message.replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
var value;
@@ -17,9 +16,10 @@
value = values[msgObject[i]];
msgObject[i] = typeof value == "undefined" ? "" : value;
}
- message = msgObject.join('');
+ return msgObject.join('');
+ } else {
+ return "";
}
- return message;
}
var _interpolateFacesMessage = function(msg,id,value){
@@ -56,6 +56,9 @@
var message = customMessage ? {detail:customMessage,summary:customMessage} :
_messages[messageId] || {detail:"",summary:""};
return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values)};
},
+ interpolateMessage: function(message,values){
+ return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values)};
+ },
sendMessage: function (componentId, message) {
rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId, 'message':message});
},
@@ -66,9 +69,9 @@
if (converter) {
try {
if (converter.f)
- convertedValue = converter.f(value, converter.p);
+ convertedValue = converter.f(value,id,converter.p,converter.m);
} catch (e){
- rf.csv.sendMessage(id, _interpolateFacesMessage(e,id,value));
+ rf.csv.sendMessage(id, e);
return false;
}
} else {
@@ -81,11 +84,11 @@
for (i=0;i<validators.length;i++) {
validatorFunction = validators[i].f;
if (validatorFunction) {
- validatorFunction(convertedValue, validators[i].p);
+ validatorFunction(convertedValue,id, validators[i].p,validators[i].m);
}
}
} catch (e) {
- rf.csv.sendMessage(id, _interpolateFacesMessage(e,id,value));
+ rf.csv.sendMessage(id, e);
return false;
}
}
@@ -123,32 +126,32 @@
* Converters implementation
*/
$.extend(rf.csv, {
- "convertBoolean": function (value, params) {
+ "convertBoolean": function (value,label,params,msg) {
var result; value = $.trim(value).toLowerCase();
result = value=='true' ? true : value.length<1 ? null : false;
return result;
},
- "convertByte": function (value, params) {
+ "convertByte": function (value,label,params,msg) {
var result; value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-128 ||
result>127) {
- throw rf.csv.getMessage(params.m, 'BYTE_CONVERTER_BYTE', [value, 0,
params.componentId]);
+ throw rf.csv.getMessage(msg, 'BYTE_CONVERTER_BYTE', [value, 0,
params.componentId]);
}
return result;
},
- "convertNumber": function (value, params) {
+ "convertNumber": function (value,label,params,msg) {
var result; value=$.trim(value);
if (isNaN(value)) {
- throw rf.csv.getMessage(params.m, 'NUMBER_CONVERTER_NUMBER', [value, 0,
params.componentId]);
+ throw rf.csv.getMessage(msg, 'NUMBER_CONVERTER_NUMBER', [value, 0,
params.componentId]);
} else {
result = parseInt(value, 10);
}
return result;
},
- "convertShort": function (value, params) {
+ "convertShort": function (value,label,params,msg) {
var result; value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-32768 ||
result>32767) {
- throw rf.csv.getMessage(params.m, 'SHORT_CONVERTER_SHORT', [value, 0,
params.componentId]);
+ throw rf.csv.getMessage(msg, 'SHORT_CONVERTER_SHORT', [value, 0,
params.componentId]);
}
return result;
}
@@ -158,15 +161,15 @@
* Validators implementation
*/
$.extend(rf.csv, {
- "validateLongRange": function (value, params) {
+ "validateLongRange": function (value,label,params,msg) {
var type = typeof value;
if (type != "number") {
if (type != "string") {
- throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_TYPE', [componentId,
""]);
+ throw rf.csv.getMessage(msg, '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.m, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_TYPE', [componentId,
""]);
}
}
}
@@ -176,28 +179,28 @@
if (isMaxSet && value > params.maximum) {
if (isMinSet) {
- throw rf.csv.getMessage(params.m,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(msg,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
} else {
- throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
+ throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
}
}
if (isMinSet && value < params.minimum) {
if (isMaxSet) {
- throw rf.csv.getMessage(params.m,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_NOT_IN_RANGE',
[params.minimum, params.maximum, componentId]);
} else {
- throw rf.csv.getMessage(params.m, 'LONG_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
+ throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
}
}
},
- "validateDoubleRange": function (value, params) {
+ "validateDoubleRange": function (value,label,params,msg) {
var type = typeof value;
if (type != "number") {
if (type != "string") {
- throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ throw rf.csv.getMessage(msg, '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.m, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_TYPE', [componentId,
""]);
}
}
}
@@ -207,45 +210,48 @@
if (isMaxSet && value > params.maximum) {
if (isMinSet) {
- throw rf.csv.getMessage(params.m,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(msg,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
} else {
- throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
+ throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
}
}
if (isMinSet && value < params.minimum) {
if (isMaxSet) {
- throw rf.csv.getMessage(params.m,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE',
[params.minimum, params.maximum, componentId]);
} else {
- throw rf.csv.getMessage(params.m, 'DOUBLE_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
+ throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
}
}
},
- "validateLength": function (value, params) {
- if (params.maximum && value.length > params.maximum) {
- throw params.m;
+ "validateLength": function (value,label,params,msg) {
+ var isMinSet = typeof params.minimum == "number" && params.minimum
>0;
+ var isMaxSet = typeof params.maximum == "number" && params.maximum
>0;
+
+ if (isMaxSet && value.length > params.maximum) {
+ throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
}
- if (params.minimum && value.length < params.minimum) {
- throw params.m
+ if (isMinSet && value.length < params.minimum) {
+ throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.minimum,params.maximum,label]:[params.minimum,label]);
}
},
- "validateRegex": function (value, params) {
+ "validateRegex": function (value,label,params,msg) {
if (typeof params.pattern != "string" || params.pattern.length == 0) {
- throw rf.csv.getMessage(params.m, 'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
}
var re;
try {
re = new RegExp(params.pattern);
} catch (e) {
- throw rf.csv.getMessage(params.m, 'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
}
if (!re.test(value)){
- throw rf.csv.getMessage(params.m, 'REGEX_VALIDATOR_NOT_MATCHED',
[params.pattern]);
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_NOT_MATCHED',
[params.pattern]);
}
},
- "validateRequired": function (value, params) {
+ "validateRequired": function (value,label,params,msg) {
if (value.length==0) {
- throw rf.csv.getMessage(params.m, 'UIINPUT_REQUIRED', [componentId]);
+ throw rf.csv.getMessage(msg, 'UIINPUT_REQUIRED', [componentId]);
}
}
});