I'm having an issue using Stripes validation method. It works but rather than returning an ajax message to display an error message in the error div, I get a whole new page with that error meesage.
I'm going exactly like the example from this page: http://www.stripesframework.org/display/stripes/AJAX
So when the validation message should be replacing the html of < div class='error'>, it just brings up a fresh new page with the error message.
any help would be really appreciated.
Thanks!
JSP:
< td>
< div style= left" id="searchError"></ div>
< /td>
< td style="text-align: right">
< stripes:submit name="search" onclick="invoke(this.form, this.name);">
< fmt:message key="search.submit"/>
</ stripes:submit>
< input name="" type="text" value="" style="display:none" />
</ td>
JS:
function invoke(form, name) {
var params = $(form).serialize();
$.ajax({
url: form.action,
data:name+"&"+params,
type:'post',
dataType: 'html',
success: function(data) {
if (data.indexOf("link:") == 0) {
window.location = data.substring(5);
} else {
$('#searchError').html(data);
}
}
});
return false;
};
ActionBean :
@Validate(mask="\\d*")
private String poNo;
Does your ActionBean implement ValidationErrorHandler?
It sounds like the resolution you get when the validation is failing is getContext().getSourcePageResolution()...
Your validation method should be implemented the following way:
/** Converts errors to HTML and streams them back to the browser. */
public Resolution handleValidationErrors(ValidationErrors errors) throws Exception {
StringBuilder message = new StringBuilder();
for (List<ValidationError> fieldErrors : errors.values()) {
for (ValidationError error : fieldErrors) {
message.append("<div class=\"error\">");
message.append(error.getMessage(getContext().getLocale()));
message.append("</div>");
}
}
return new StreamingResolution("text/html", new StringReader(message.toString()));
}