Hi,
I'm having a Spring MVC 2.5 - webflow 2 - tiles application which is quite similar to the booking mvc sample. I'm also experimenting with Dojo. There's a difference here with booking mvc sample concerning validation. I'm using server side validation in the business layer with the Spring Validation package. All required and formatting validations of my jsp fields happens in this validation layer, instead of client side with Dojo - javascript.
Problem is that I don't manage to show these server side validation errors on field level in Spring decorated dijit.form.ValidationTextBox widgets. Field errors are showing correctly with the form:errors tag, so I thought it should be possible to attach these errors to the ValidationTextBox error state, showing the error style as well.
Here's an input tag together with decoration and form:errors for the field.
The form:errors tag generates this in html:Code:<form:input id="abNumber" path="abNumber" maxlength="8" size="20"/> <script type="text/javascript"> Spring.addDecoration(new Spring.ElementDecoration({ elementId : "abNumber", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : { promptMessage : "<fmt:message key="tooltip.abNumber" bundle="${msg}" />" }, validate : function(){ if (dojo.byId("abNumber.errors") == undefined) { return true; } else { this.widget.state = "Error"; this.widget._setStateClass(); return false; } } })); </script> <form:errors path="abNumber" />
The form is submitted with:Code:<span id="abNumber.errors">ab is mandatory.</span>
Of course the problem with this approach is that the javascript decoration on the input element is executed before form submit, there are no errors then. After submit, the errors are present but the decoration script isn't executed anymore, so the error style on the text box isn't shown.Code:<input id="btnDeclChoice" class="button btnNext" type="submit" title="Next step in add decl " value="Next" name="_eventId_confirm" /> <script type="text/javascript"> Spring.addDecoration(new Spring.ValidateAllDecoration({ elementId:'btnDeclChoice', event:'onclick' })); </script>
I'm sure I'm close to getting this to work, but I'm still missing some insight.
What can I change to make sure that the decoration script reacts to the presence of the span generated by form:errors.
Any help on showing server side validation with Dojo widgets greatly appreciated!


Reply With Quote