Erro ao tentar deletar registro no Grails 2.5.0
15/10/2015 23:45
static allowedMethods = [save: "POST", update: "PUT", delete: ["POST", "DELETE"]]?
<g:form url="[resource:regraTributalizaInstance, action:'delete']" method="DELETE">
<g:actionSubmit value="Delete" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Tem certeza?')}');" />
</g:form>
[font=Arial][size=85]Remote Address:
[::1]:9090
Request URL:
http://localhost:9090/frontend/regraTributaliza/delete/3
Request Method:
[/size][/font] ?POST[font=Arial][size=85]
Status Code:
404 Not Found[/size][/font]
<g:actionSubmit>tags. These are used in the autogenerated GSPs that are created for you, and they enable having multiple submit buttons, each with its own action, inside a single form. The problem from the security perspective is that the form posts to the default action of the controller, and Grails figures out the handler action to use based on the
actionattribute of the
actionSubmittag. So for example you can guard the
/person/deletewith a restrictive role, but given this typical edit form:
/person/indexurl, which would often be the case.
actionSubmitand explicitly set the
actionon the
<g:form>tags, which will result in form submissions to the expected urls and properly guarded urls.
static allowedMethods = [save: "POST", update: "PUT", delete: ["POST", "DELETE", "GET"]]
@Transactional
def delete(Long id) {
def regraTributalizaInstance = RegraTributaliza.get(id)
if (regraTributalizaInstance == null) {
notFound()
return
}
regraTributalizaInstance.delete(flush: true)
flash.message = message(code: 'default.deleted.message', args: [message(code: 'regraTributaliza.label', default: 'RegraTributaliza'), regraTributalizaInstance.nome])
redirect action: "index", method: "GET"
}
action="delete", sendo assim ficaria no form ne actionSubmit.
<g:form url="[resource:regraTributalizaInstance, action:'delete']" method="DELETE">
<g:actionSubmit value="Delete" action="delete" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Tem certeza?')}');" />
</g:form>
Para se registrar, clique aqui.