[ https://issues.apache.org/jira/browse/WW-3954?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
COMBEAU updated WW-3954:
------------------------
Description:
Hello,
I have find an issue on Struts 2.3.4.1. I have made a migration from Struts 2.1.8 to Struts
2.3.4.1 and I have seen that the Ajax Validation doesn't work anymore.
Moreover, when I would like to make the validation of my form in Ajax I seen that response
was already "success" even if one or more fields are in errors. I think it's not normal. In
Struts 2.1.8 when fields are in errors the response of an Ajax call is "error" not "success"
To correct this issue I have made a workaround. In the JSONValidationInterceptor, if the buildResponse
method have "/*" in the first append and "*/" in the last it correct the problem...
why this :
protected String buildResponse(ValidationAware validationAware) {
//should we use FreeMarker here?
StringBuilder sb = new StringBuilder();
sb.append("/* { ");
if (validationAware.hasErrors()) {
//action errors
if (validationAware.hasActionErrors()) {
sb.append("\"errors\":");
sb.append(buildArray(validationAware.getActionErrors()));
}
//field errors
if (validationAware.hasFieldErrors()) {
if (validationAware.hasActionErrors())
sb.append(",");
sb.append("\"fieldErrors\": {");
Map<String, List<String>> fieldErrors = validationAware
.getFieldErrors();
for (Map.Entry<String, List<String>> fieldError : fieldErrors
.entrySet()) {
sb.append("\"");
//if it is model driven, remove "model." see WW-2721
String fieldErrorKey = fieldError.getKey();
sb.append(((validationAware instanceof ModelDriven) && fieldErrorKey.startsWith("model."))?
fieldErrorKey.substring(6)
: fieldErrorKey);
sb.append("\":");
sb.append(buildArray(fieldError.getValue()));
sb.append(",");
}
//remove trailing comma, IE creates an empty object, duh
sb.deleteCharAt(sb.length() - 1);
sb.append("}");
}
}
sb.append("} */");
/*response should be something like:
* {
* "errors": ["this", "that"],
* "fieldErrors": {
* field1: "this",
* field2: "that"
* }
* }
*/
return sb.toString();
}
as been replaced by this :
protected String buildResponse(ValidationAware validationAware) {
//should we use FreeMarker here?
StringBuilder sb = new StringBuilder();
sb.append("{ ");
if (validationAware.hasErrors()) {
//action errors
if (validationAware.hasActionErrors()) {
sb.append("\"errors\":");
sb.append(buildArray(validationAware.getActionErrors()));
}
//field errors
if (validationAware.hasFieldErrors()) {
if (validationAware.hasActionErrors())
sb.append(",");
sb.append("\"fieldErrors\": {");
Map<String, List<String>> fieldErrors = validationAware
.getFieldErrors();
for (Map.Entry<String, List<String>> fieldError : fieldErrors
.entrySet()) {
sb.append("\"");
//if it is model driven, remove "model." see WW-2721
String fieldErrorKey = fieldError.getKey();
sb.append(((validationAware instanceof ModelDriven) && fieldErrorKey.startsWith("model."))?
fieldErrorKey.substring(6)
: fieldErrorKey);
sb.append("\":");
sb.append(buildArray(fieldError.getValue()));
sb.append(",");
}
//remove trailing comma, IE creates an empty object, duh
sb.deleteCharAt(sb.length() - 1);
sb.append("}");
}
}
sb.append("}");
/*response should be something like:
* {
* "errors": ["this", "that"],
* "fieldErrors": {
* field1: "this",
* field2: "that"
* }
* }
*/
return sb.toString();
}
Is this a real issue ?
was:
Hello,
I have find an issue on Struts 2.3.4.1. I have made a migration from Struts 2.1.8 to Struts
2.3.4.1 and I have seen that the Ajax Validation doesn't work anymore.
Moreover, when I would like to make the validation of my form in Ajax I seen that response
was already "success" even if one or more fields are in errors. I think it's not normal. In
Struts 2.1.8 when fields are in errors the response of an Ajax call is "error" not "success"
To correct this issue I have made a workaround. In the JSONValidationInterceptor, if the buildResponse
method have "/*" in the first append and "*/" in the last it correct the problem...
Is this a real issue ?
> Ajax Validation is broken (json)
> --------------------------------
>
> Key: WW-3954
> URL: https://issues.apache.org/jira/browse/WW-3954
> Project: Struts 2
> Issue Type: Bug
> Components: Plugin - JSON
> Affects Versions: 2.3.1, 2.3.1.1, 2.3.1.2, 2.3.3, 2.3.4, 2.3.4.1
> Environment: Struts 2.3.4.1, Jquery 1.7, Struts json plugin 2.3.4.1
> Reporter: COMBEAU
> Priority: Critical
>
> Hello,
> I have find an issue on Struts 2.3.4.1. I have made a migration from Struts 2.1.8 to
Struts 2.3.4.1 and I have seen that the Ajax Validation doesn't work anymore.
> Moreover, when I would like to make the validation of my form in Ajax I seen that response
was already "success" even if one or more fields are in errors. I think it's not normal. In
Struts 2.1.8 when fields are in errors the response of an Ajax call is "error" not "success"
> To correct this issue I have made a workaround. In the JSONValidationInterceptor, if
the buildResponse method have "/*" in the first append and "*/" in the last it correct the
problem...
> why this :
> protected String buildResponse(ValidationAware validationAware) {
> //should we use FreeMarker here?
> StringBuilder sb = new StringBuilder();
> sb.append("/* { ");
> if (validationAware.hasErrors()) {
> //action errors
> if (validationAware.hasActionErrors()) {
> sb.append("\"errors\":");
> sb.append(buildArray(validationAware.getActionErrors()));
> }
> //field errors
> if (validationAware.hasFieldErrors()) {
> if (validationAware.hasActionErrors())
> sb.append(",");
> sb.append("\"fieldErrors\": {");
> Map<String, List<String>> fieldErrors = validationAware
> .getFieldErrors();
> for (Map.Entry<String, List<String>> fieldError : fieldErrors
> .entrySet()) {
> sb.append("\"");
> //if it is model driven, remove "model." see WW-2721
> String fieldErrorKey = fieldError.getKey();
> sb.append(((validationAware instanceof ModelDriven) && fieldErrorKey.startsWith("model."))?
fieldErrorKey.substring(6)
> : fieldErrorKey);
> sb.append("\":");
> sb.append(buildArray(fieldError.getValue()));
> sb.append(",");
> }
> //remove trailing comma, IE creates an empty object, duh
> sb.deleteCharAt(sb.length() - 1);
> sb.append("}");
> }
> }
> sb.append("} */");
> /*response should be something like:
> * {
> * "errors": ["this", "that"],
> * "fieldErrors": {
> * field1: "this",
> * field2: "that"
> * }
> * }
> */
> return sb.toString();
> }
> as been replaced by this :
> protected String buildResponse(ValidationAware validationAware) {
> //should we use FreeMarker here?
> StringBuilder sb = new StringBuilder();
> sb.append("{ ");
> if (validationAware.hasErrors()) {
> //action errors
> if (validationAware.hasActionErrors()) {
> sb.append("\"errors\":");
> sb.append(buildArray(validationAware.getActionErrors()));
> }
> //field errors
> if (validationAware.hasFieldErrors()) {
> if (validationAware.hasActionErrors())
> sb.append(",");
> sb.append("\"fieldErrors\": {");
> Map<String, List<String>> fieldErrors = validationAware
> .getFieldErrors();
> for (Map.Entry<String, List<String>> fieldError : fieldErrors
> .entrySet()) {
> sb.append("\"");
> //if it is model driven, remove "model." see WW-2721
> String fieldErrorKey = fieldError.getKey();
> sb.append(((validationAware instanceof ModelDriven) && fieldErrorKey.startsWith("model."))?
fieldErrorKey.substring(6)
> : fieldErrorKey);
> sb.append("\":");
> sb.append(buildArray(fieldError.getValue()));
> sb.append(",");
> }
> //remove trailing comma, IE creates an empty object, duh
> sb.deleteCharAt(sb.length() - 1);
> sb.append("}");
> }
> }
> sb.append("}");
> /*response should be something like:
> * {
> * "errors": ["this", "that"],
> * "fieldErrors": {
> * field1: "this",
> * field2: "that"
> * }
> * }
> */
> return sb.toString();
> }
> Is this a real issue ?
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
|