Não estou conseguindo salvar na base de dados
30/01/2013 17:27
Tenho o seguinte código gsp que é um include, quando tento persistir com a tag g:link dá erro e com o submitToRemote nem funciona. Alguém poderia analisar o código e me dizer qual é o problema. No console não esta exibindo o erro.
Agradeço imensamente.
<tr class="prop">
<td valign="top" class="name2"><g:hiddenField name="id" value="${encaminhamentoInstance?.id}" />
<label for="nome"><g:message code="encaminhamento.localOrgaoEncaminhamento.label" default="Local / Orgão de Encaminhamento" /></label>
</td>
<td valign="top" class="value2 ${hasErrors(bean: encaminhamentoInstance, field: 'localOrgaoEncaminhamento', 'errors')}">
<g:textField name="nome" value="${encaminhamentoInstance?.localOrgaoEncaminhamento}" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name2">
<label for=horaDataChegada><g:message code="encaminhamento.dataHoraChegada.label" default="Data / Hora de Chegada" /></label>
</td>
<td valign="top" class="value2 ${hasErrors(bean: encaminhamentoInstance, field: 'horaDataChegada', 'errors')} espacoBotaoMais">
<g:textField name="horaDataChegada" class="dataHoraMinuto" value="${encaminhamentoInstance?.horaDataChegada}" />
</td>
<td valign="top" class="name2">
<label for="horaDataSaida"><g:message code="encaminhamento.horaDataSaida.label" default="Data / Hora de Saída" /></label>
</td>
<td valign="top" class="value2 ${hasErrors(bean: encaminhamentoInstance, field: 'horaDataSaida', 'errors')} espacoBotaoMais">
<g:textField name="horaDataSaida" class="dataHoraMinuto" value="${encaminhamentoInstance?.horaDataSaida}" />
</td>
</tr>
<tr class="prop">
<td>
<g:submitToRemote update="encaminhamentos" url="[controller:'encaminhamento', action:'salvar']" value="Adicionar"/>
<g:link url="[controller:'encaminhamento', action:'salvar']" action="salvar">Salvar</g:link>
</td>
</tr>
<div id="encaminhamentos">
<g:if test="${encaminhamentos}">
<br/>
<h3>Encaminhamentos Adicionados</h3>
<div class="list">
<table>
<thead>
<tr>
<g:sortableColumn property="localOrgaoEncaminhamento" title="encaminhamento.localOrgaoEncaminhamento.label" />
<g:sortableColumn property="dataHoraChegada" title="encaminhamento.dataHoraChegada.label" />
<g:sortableColumn property="dataHoraSaida" title="encaminhamento.horaDataSaida.label" />
</tr>
</thead>
<tbody>
<g:each in="${searchresults}" status="i" var="encaminhamentoInstance">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td><g:link action="show" id="${encaminhamentoInstance.id}">${fieldValue(bean: encaminhamentoInstance, field: "id")}</g:link></td>
<td>${fieldValue(bean: encaminhamentoInstance, field: "localOrgaoEncaminhamento")}</td>
<td>${fieldValue(bean: encaminhamentoInstance, field: "horaDataChegada")}</td>
<td>${fieldValue(bean: encaminhamentoInstance, field: "horaDataSaida")}</td>
</tr>
</g:each>
</tbody>
</table>
</div>
</g:if>
</div>
///////////////////////////////////////////////////////////////////////////////////////
package br.com.geocontrol.tro
class EncaminhamentoController {
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
List<Encaminhamento> encaminhamentos = new ArrayList<Encaminhamento>();
def salvar = {
def encaminhamentoInstance = new Encaminhamento(params)
//Não salva
if (encaminhamentoInstance.save(flush: true)) {
encaminhamentos << encaminhamentoInstance;
}
redirect(controller: "tro", action: "create")
}
def show = {
def encaminhamentoInstance = Encaminhamento.get(params.id)
if (!encaminhamentoInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'encaminhamento.label', default: 'Encaminhamento'), params.id])}"
redirect(action: "tro")
}
else {
[encaminhamentoInstance: encaminhamentoInstance]
}
}
}
Tags:
erro ao persistir