Jason Swett
Jason Swett

Reputation: 45074

Dojo DataGrid validation

What's the best way to put validation on a Dojo DataGrid cell? Among all the callbacks available, I haven't found any way to do it, not even a hacky way.

(I'm using Dojo 1.6.)

Upvotes: 0

Views: 1094

Answers (1)

Oswaldo
Oswaldo

Reputation: 26

I suggest to create a button to apply/validate the data in the grid, call ajax with method PUT /{table}/{id} (-1) and json data item in the body.

var jsItem = JSON.stringify(jsonRestReflexion.newItem);
// function startAjax(xmlhttp, Url, callback, method, obj, headerName, headerValue)
ajaxhttp = startAjax(ajaxhttp               ,jsonRestReflexion.getUrlRestFul()+jsonRestReflexion.newItem.id+"?query=validateEntity"
                , callbackFromAjax, "PUT", jsItem
                , "Content-Type", "application/json; charset=UTF-8");

Execute validation in the server and return error in the header

callbackFromAjax = function() {
                //addDiv(portletId, this.responseText);
$("errorDetails").innerHTML = "Errors # " + this.getResponseHeader("ConstraintViolationsSize") + "<br/>"+ this.getAllResponseHeaders();
showDialog();
            }

then open a dojo.dialog with error returning from the server with a close button or any error display implementation that you like.

I used the following technology:

  • toplink jpa 1.0 and validation annotation
  • rest-jersey
  • tomcat 6
  • hibernate-validation 4
  • springframework 3.0
  • mysql 5
  • dojo 1.6

good luck

Upvotes: 1

Related Questions