java - Grails error validating on existing input -
i got error when tried modify controller (generated scaffolding). want do, add current user capture springsecurity service.
payment class has user property inside. tried inject user value springsecurityservice.getcurrentuser()
;
when tried this, produce error : property [user] of class [class kks.payment] cannot null
i tried debug, looks fine still producing error ....
this work if put user.id inside form hidden value .. didn't want ...
how solve problem ?
here code:
class paymentcontroller { def springsecurityservice; @transactional def save(payment paymentinstance) { println("1..... payment"); paymentinstance.user = springsecurityservice.getcurrentuser(); if (paymentinstance == null) { notfound() return } println("2..... payment"+springsecurityservice.getcurrentuser().class); println(paymentinstance.user.id); // still okay !!! if (paymentinstance.haserrors()) { println("3..... haserrors?"); // entered here property [user] of class > [class kks.payment] cannot null respond paymentinstance.errors, view: 'create' return } println("3..... payment"); paymentinstance.save flush: true request.withformat { form multipartform { flash.message = message(code: 'default.created.message', args: >[message(code: 'payment.label', default: 'payment'), paymentinstance.id]) redirect paymentinstance } '*' { respond paymentinstance, [status: created] } } } }
after inserting value in paymentinstance
should validate instance like:
paymentinstance.user = springsecurityservice.getcurrentuser(); paymentinstance.validate()
and check error.
ps: please follow convention: variable name should started lower case character.
Comments
Post a Comment