Grails command object validation with Ajax -


in grails project have command object validate submitted forms. command obj. has custom validators. data submitted jquery ajax ($.post).

my question how can map data send jquery ajax properties listed in command object?

for example:

$.post('comment/save', {id: id, title: title}); 

and in controller:

def save(savecommand cmd){    if (!cmd.validate()){     ...   } }  class savecommand {     comment comment_id    // maps to: params.comment_id send ajax    string title          // maps to: params.title send ajax     // constraints    // validators     } 

the comment_id attribute should bound "comment_id" parameter in parameter map sent jquery, not "id" have right now.

anyway, guess have comment domain class, , expect bind entity database. in case, should add ".id" suffix parameter name.

$.post('comment/save', {"comment_id.id": id, "title": title}); 

ps: maybe want rename "comment_id" "comment" in command class. doing that, have change parameter name in ajax request "comment.id".


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -