Algum exemplo de como fazer CRUD completo uma unica pagina
30/08/2009 00:00
0
Olá pessoal, estou estudando Groovy e Grails a uns 15 dias, e ainda não consegui achar um exemplo usando o Grails num crud de uma unica pagina, não como é gerado pelo scaffold uma pagina para cada action, uma para lista, criar, editar, show.
Gostaria de fazer uma página onde eu possa fazer tudo isso sem sair da pagina onde eu estiver, seria mais ou menos assim:

- Na minha pagina eu teria o formulário, e logo abaixo uma tabela com a lista de dados, onde o usuário selecionaria uma linha nessa tabela e o mesmo formulário seria preenchido para fazer a atualização, e ainda na tabela teria um link para o usuário deletar o item daquela linha.

Então ficaria um CRUD completo numa unica pagina, alguem teria um exemplo de como eu posso estar fazendo isso?
Tags: Grails


0
Algum???
Ou uma ideia de como eu posso ter uma table com dos dados e um formulário de cadastro numa mesma pagina??
31/08/2009 00:00


0
No list de cada controler exibimos uma table com os principais dados e para cada registro um link para alterar, exibir e excluir, logo já na table consigo executar várias actions:

<table id=&quot;tab&quot; class=&quot;tabelas&quot; border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;1&quot;>
<thead>
<tr>
<g&#58;remoteSortableColumn update=&quot;updateMe&quot; onclick=&quot;carregando('updateMe');&quot; params=&quot;[parametros&#58;parametros]&quot; property=&quot;a.nome&quot; title=&quot;Nome&quot; />
<g&#58;remoteSortableColumn update=&quot;updateMe&quot; onclick=&quot;carregando('updateMe');&quot; params=&quot;[parametros&#58;parametros]&quot; property=&quot;a.controle&quot; title=&quot;Controle&quot; />
<g&#58;remoteSortableColumn update=&quot;updateMe&quot; onclick=&quot;carregando('updateMe');&quot; params=&quot;[parametros&#58;parametros]&quot; property=&quot;a.ativo&quot; title=&quot;Ativo&quot; />
<g&#58;remoteSortableColumn update=&quot;updateMe&quot; onclick=&quot;carregando('updateMe');&quot; params=&quot;[parametros&#58;parametros]&quot; property=&quot;m.nome&quot; title=&quot;Menu&quot; />
<th>Exibir</th>
<th>Editar</th>
<th>Excluir</th>

</tr>
</thead>
<tbody>
<g&#58;each in=&quot;${aplicacoes}&quot; status=&quot;i&quot; var=&quot;aplicacao&quot;>
<tr>
<td class=&quot;divisoes&quot; align=&quot;right&quot;>${fieldValue(bean&#58;aplicacao, field&#58;'nome')}</td>
<td class=&quot;divisoes&quot; align=&quot;right&quot;>${fieldValue(bean&#58;aplicacao, field&#58;'controle')}</td>
<td class=&quot;divisoes&quot; align=&quot;right&quot;>${fieldValue(bean&#58;aplicacao, field&#58;'ativo')}</td>
<td class=&quot;divisoes&quot; align=&quot;right&quot;>${fieldValue(bean&#58;aplicacao?.menu, field&#58;'nome')}</td>
<td class=&quot;divisoes&quot; align=&quot;center&quot;><g&#58;link action=&quot;show&quot; id=&quot;${aplicacao.id}&quot;><img src=&quot;../images/skin/show.gif&quot; border=&quot;0&quot; alt=&quot;Exibir&quot; title=&quot;Exibir&quot;></g&#58;link></td>
<td class=&quot;divisoes&quot; align=&quot;center&quot;><g&#58;link action=&quot;edit&quot; id=&quot;${aplicacao.id}&quot;><img src=&quot;../images/skin/database_edit.png&quot; border=&quot;0&quot; alt=&quot;Editar&quot; title=&quot;Editar&quot;></g&#58;link></td>
<td class=&quot;divisoes&quot; align=&quot;center&quot;><g&#58;remoteLink onSuccess=&quot;buscar('buscar');&quot; action=&quot;delete&quot; id=&quot;${aplicacao.id}&quot; before=&quot;if (!confirm('Deseja realmente apagar?')){return false;}&quot;><img src=&quot;../images/skin/database_delete.png&quot; border=&quot;0&quot; alt=&quot;Excluir&quot; title=&quot;Excluir&quot;></g&#58;remoteLink></td>
</tr>
</g&#58;each>
</tbody>
</table>


Meu create:


<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/>
<meta name=&quot;layout&quot; content=&quot;main&quot; />
<g&#58;javascript src=&quot;app/aplicacao.js&quot; />
</head>
<body>
<div class=&quot;body&quot; style=&quot;width&#58;550px&quot;>
<h1>Nova Aplicação</h1>
<g&#58;if test=&quot;${flash.message}&quot;>
<div class=&quot;message&quot;>${flash.message}</div>
</g&#58;if>
<g&#58;hasErrors bean=&quot;${aplicacaoInstance}&quot;>
<div class=&quot;errors&quot;>
<g&#58;renderErrors bean=&quot;${aplicacaoInstance}&quot; as=&quot;list&quot; />
</div>
</g&#58;hasErrors>
<g&#58;form method=&quot;post&quot; >
<div class=&quot;dialog&quot;>
<table>
<tbody>
<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'ativo','errors')}&quot;>
Ativo&#58; * </br>
<g&#58;checkBox name=&quot;ativo&quot; value=&quot;${aplicacaoInstance?.ativo}&quot; ></g&#58;checkBox>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'menu','errors')}&quot;>
Menu&#58; * </br>
<g&#58;select style=&quot;width&#58;56%&quot; optionKey=&quot;id&quot; from=&quot;${Menu.list()}&quot; name=&quot;menu.id&quot; value=&quot;${aplicacaoInstance?.menu?.id}&quot; ></g&#58;select>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'nome','errors')}&quot;>
Nome&#58; * </br>
<input style=&quot;width&#58;56%&quot; type=&quot;text&quot; maxlength=&quot;40&quot; id=&quot;nome&quot; name=&quot;nome&quot; value=&quot;${fieldValue(bean&#58;aplicacaoInstance,field&#58;'nome')}&quot;/>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'controle','errors')}&quot;>
Controle&#58; * </br>
<input style=&quot;width&#58;56%&quot; type=&quot;text&quot; maxlength=&quot;40&quot; id=&quot;controle&quot; name=&quot;controle&quot; value=&quot;${fieldValue(bean&#58;aplicacaoInstance,field&#58;'controle')}&quot;/>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'inicio','errors')}&quot;>
Início&#58; * </br>
<g&#58;datePicker name=&quot;inicio&quot; value=&quot;${aplicacaoInstance?.inicio}&quot; ></g&#58;datePicker>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'fim','errors')}&quot;>
Fim&#58; * </br>
<g&#58;datePicker name=&quot;fim&quot; value=&quot;${aplicacaoInstance?.fim}&quot; ></g&#58;datePicker>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td>* Campos Obrigatórios </td>
</tr>
</tbody>
</table>
</div>
<div class=&quot;buttons&quot;>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;save&quot; controller=&quot;aplicacao&quot; action=&quot;save&quot; value=&quot;Salvar&quot; /></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;return&quot; controller=&quot;aplicacao&quot; action=&quot;list&quot; value=&quot;Voltar&quot; /></span>
</div>
</g&#58;form>
</div>
</body>
</html>


Edit:


<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/>
<meta name=&quot;layout&quot; content=&quot;main&quot; />
<g&#58;javascript src=&quot;app/aplicacao.js&quot; />
</head>
<body>
<div class=&quot;body&quot; style=&quot;width&#58;550px&quot;>
<h1>Alterar Aplicação</h1>
<g&#58;if test=&quot;${flash.message}&quot;>
<div class=&quot;message&quot;>${flash.message}</div>
</g&#58;if>
<g&#58;hasErrors bean=&quot;${aplicacaoInstance}&quot;>
<div class=&quot;errors&quot;>
<g&#58;renderErrors bean=&quot;${aplicacaoInstance}&quot; as=&quot;list&quot; />
</div>
</g&#58;hasErrors>
<g&#58;form method=&quot;post&quot; >
<input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;${aplicacaoInstance?.id}&quot; />
<div class=&quot;dialog&quot;>
<table>
<tbody>
<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'ativo','errors')}&quot;>
Ativo&#58; * </br>
<g&#58;checkBox name=&quot;ativo&quot; value=&quot;${aplicacaoInstance?.ativo}&quot; ></g&#58;checkBox>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'menu','errors')}&quot;>
Menu&#58; * </br>
<g&#58;select style=&quot;width&#58;56%&quot; optionKey=&quot;id&quot; from=&quot;${Menu.list()}&quot; name=&quot;menu.id&quot; value=&quot;${aplicacaoInstance?.menu?.id}&quot; ></g&#58;select>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'nome','errors')}&quot;>
Nome&#58; * </br>
<input style=&quot;width&#58;56%&quot; type=&quot;text&quot; maxlength=&quot;40&quot; id=&quot;nome&quot; name=&quot;nome&quot; value=&quot;${fieldValue(bean&#58;aplicacaoInstance,field&#58;'nome')}&quot;/>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'controle','errors')}&quot;>
Controle&#58; * </br>
<input style=&quot;width&#58;56%&quot; type=&quot;text&quot; maxlength=&quot;40&quot; id=&quot;controle&quot; name=&quot;controle&quot; value=&quot;${fieldValue(bean&#58;aplicacaoInstance,field&#58;'controle')}&quot;/>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'inicio','errors')}&quot;>
Início&#58; * </br>
<g&#58;datePicker name=&quot;inicio&quot; value=&quot;${aplicacaoInstance?.inicio}&quot; ></g&#58;datePicker>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;value ${hasErrors(bean&#58;aplicacaoInstance,field&#58;'fim','errors')}&quot;>
Fim&#58; * </br>
<g&#58;datePicker name=&quot;fim&quot; value=&quot;${aplicacaoInstance?.fim}&quot; ></g&#58;datePicker>
</td>
</tr>

<tr class=&quot;prop&quot;>
<td>* Campos Obrigatórios </td>
</tr>
</tbody>
</table>
</div>
<div class=&quot;buttons&quot;>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;save&quot; controller=&quot;aplicacao&quot; action=&quot;update&quot; value=&quot;Salvar&quot; onClick=&quot;seleciona('listAplic2');&quot;/></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;create&quot; controller=&quot;aplicacao&quot; action=&quot;create&quot; value=&quot;Novo&quot;/></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;show&quot; controller=&quot;aplicacao&quot; action=&quot;show&quot; value=&quot;Exibir&quot;/></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;delete&quot; controller=&quot;aplicacao&quot; action=&quot;delete&quot; onclick=&quot;return confirm('Deseja excluir o registro?');&quot; value=&quot;Excluir&quot; /></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;return&quot; controller=&quot;aplicacao&quot; action=&quot;list&quot; value=&quot;Voltar&quot; /></span>
</div>
</g&#58;form>
</div>
</body>
</html>


Show:


<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/>
<meta name=&quot;layout&quot; content=&quot;main&quot; />
</head>
<body>
<div class=&quot;body&quot; style=&quot;width&#58;550px&quot;>
<h1>Exibir Aplicação</h1>
<g&#58;if test=&quot;${flash.message}&quot;>
<div class=&quot;message&quot;>${flash.message}</div>
</g&#58;if>
<div class=&quot;dialog&quot;>
<table>
<tbody>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Ativo&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;>${fieldValue(bean&#58;aplicacaoInstance, field&#58;'ativo')}</td>

</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Menu&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;>${aplicacaoInstance?.menu?.encodeAsHTML()}</td>

</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Nome&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;>${fieldValue(bean&#58;aplicacaoInstance, field&#58;'nome')}</td>

</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Controle&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;>${fieldValue(bean&#58;aplicacaoInstance, field&#58;'controle')}</td>

</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Data Criação&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;><g&#58;formatDate format=&quot;EEEE, d MMMMM yyyy HH&#58;mm&quot;>${fieldValue(bean&#58;aplicacaoInstance, field&#58;'dateCreated')}</g&#58;formatDate></td>

</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Usuário Criação&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;>${aplicacaoInstance?.usuarioCreated?.encodeAsHTML()}</td>

</tr>

<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Última Alteração&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;><g&#58;formatDate format=&quot;EEEE, d MMMMM yyyy HH&#58;mm&quot;>${fieldValue(bean&#58;aplicacaoInstance, field&#58;'lastUpdated')}</g&#58;formatDate></td>

</tr>


<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; class=&quot;name&quot;>Usuário Alteração&#58;</td>

<td valign=&quot;top&quot; class=&quot;value&quot;>${aplicacaoInstance?.usuarioUpdated?.encodeAsHTML()}</td>

</tr>

</tbody>
</table>
</div>
<div class=&quot;buttons&quot;>
<g&#58;form>
<input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;${aplicacaoInstance?.id}&quot; />
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;edit&quot; controller=&quot;aplicacao&quot; action=&quot;edit&quot; value=&quot;Alterar&quot; /></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;create&quot; controller=&quot;aplicacao&quot; action=&quot;create&quot; value=&quot;Novo&quot;/></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;delete&quot; controller=&quot;aplicacao&quot; action=&quot;delete&quot; onclick=&quot;return confirm('Deseja excluir o registro?');&quot; value=&quot;Excluir&quot; /></span>
<span class=&quot;button&quot;><g&#58;actionSubmit class=&quot;return&quot; controller=&quot;aplicacao&quot; action=&quot;list&quot; value=&quot;Voltar&quot; /></span>
</g&#58;form>
</div>
</div>
</body>
</html>
01/09/2009 00:00


0
Não seria isso, dessa forma ainda assim tenho uma pagina para cada action, no máximo eu teria duas, uma pra edit outra pra insert.
A minha dúvida nesse momento é em como eu faço pra no momento em que a página iniciar eu tenha o formulário e a tabela com os dados.
Isso tudo em uma unica página, o formulário com os dados a serem preenchidos para inserção/edição e a tabela com os dados já existente no banco.
01/09/2009 00:00


0
pega o que o grails gerou, copia e cola tudo numa mesma pagina?

So voce quiser que o scaffold gere esses forms imensos customizados, basta alterar o template de geração.
Ref: <!-- m --><a class="postlink" href="http://grails.org/Artifact+and+Scaffolding+Templates">http://grails.org/Artifact+and+Scaffolding+Templates</a><!-- m -->
03/09/2009 00:00


0
valeu Raphael, vou tentar essa abordagem.
07/09/2009 00:00


0
93!


Dá uma olhada em ScaffoldTags Plugin.....Acho que ele resolve seu problema! <!-- s;-) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";-)" title="Wink" /><!-- s;-) -->

Features
...
* Inherit views through inheritance
...


Se resolver volte aki e comente com a gente... <!-- s:-P --><img src="{SMILIES_PATH}/icon_razz.gif" alt=":-P" title="Razz" /><!-- s:-P -->


93,93/93
10/09/2009 00:00


0
93!

Faltou o link.....rs

<!-- m --><a class="postlink" href="http://grails.org/plugin/scaffold-tags">http://grails.org/plugin/scaffold-tags</a><!-- m -->

93,93/93
10/09/2009 00:00


0
[quote=&quot;Baphomet93'.'&quot;]93!

Faltou o link.....rs

<!-- m --><a class="postlink" href="http://grails.org/plugin/scaffold-tags">http://grails.org/plugin/scaffold-tags</a><!-- m -->

93,93/93[/quote]

Por que 93? <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->


0
[quote=&quot;kicolobo&quot;][quote=&quot;Baphomet93'.'&quot;]93!

Faltou o link.....rs

<!-- m --><a class="postlink" href="http://grails.org/plugin/scaffold-tags">http://grails.org/plugin/scaffold-tags</a><!-- m -->

93,93/93[/quote]

Por que 93? <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->[/quote]

93!

&quot;Apenas&quot; uma forma de cumprimento e reconhecimento...hehehe <!-- s;-) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";-)" title="Wink" /><!-- s;-) -->

<!-- m --><a class="postlink" href="http://www.ocultura.org.br/index.php/93">http://www.ocultura.org.br/index.php/93</a><!-- m -->

93,93/93
11/09/2009 00:00


0
[quote=&quot;Baphomet93'.'&quot;][quote=&quot;kicolobo&quot;][quote=&quot;Baphomet93'.'&quot;]93!

Faltou o link.....rs

<!-- m --><a class="postlink" href="http://grails.org/plugin/scaffold-tags">http://grails.org/plugin/scaffold-tags</a><!-- m -->

93,93/93[/quote]

Por que 93? <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->[/quote]

93!

&quot;Apenas&quot; uma forma de cumprimento e reconhecimento...hehehe <!-- s;-) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";-)" title="Wink" /><!-- s;-) -->

<!-- m --><a class="postlink" href="http://www.ocultura.org.br/index.php/93">http://www.ocultura.org.br/index.php/93</a><!-- m -->

93,93/93[/quote]

Que legal!

ps: aliás, sabe do que o Grails Brasil precisa? De um fórum off-topic


0
Eu estava tentando uma abordagem errada sobre a minha aplicação, percebi que o modelo de uma pagina pra tudo como eu estava querendo fazer seria mais útil para uma aplicação em si, e não um web site como estou querendo fazer.

Mais de qualquer forma kicolobo 93, obrigado pela dica, vou tentar numa próxima aplicação que for fazer.

valeu mesmo...
22/09/2009 00:00



Ainda não faz parte da comunidade???

Para se registrar, clique aqui.


Aprenda Groovy e Grails com a Formação itexto!

Newsletter Semana Groovy

Assinar

Envie seu link!


Livro de Grails


/dev/All

Os melhores blogs de TI (e em português) em um único lugar!

 
Creative Commons
RSS Grails Brasil é mantido por itexto Consultoria.
Em caso de problemas contacte Henrique Lobo Weissmann (Kico) por e-mail: kico@itexto.com.br
Todo o conteúdo presente neste site adota o Creative Commons como licença padrão.
Ver: 4.14.0
itexto