grails - How to keep query results after deleting an item? -



grails - How to keep query results after deleting an item? -

in grails application have multiple pages list grouping of info objects within of table. in these pages provide search function when performed adjust table display info objects match query. if user decides delete 1 of these info objects application take them default table displays everything. query results remain intact after performing delete.

i utilize "skill evaluations" page illustration in post.

here relevant code in domain class

skilleval.groovy class skilleval { static hasmany = [lines: skillevall, courses: courseoffering, choicelabels: choicelabel] string name string formversion static def search(params) { def criteria = skilleval.createcriteria() def results = criteria.list(params) { or { ilike("name", params.search+'%') } } homecoming results } }

relevant section of gsp view file

list.gsp <g:form> <div class="search"> <label for="searchfield">search:</label> <input type="text" id="searchfield" name="search" value="${params.search}" /> <input type="submit" value="search" /> </div> <br> <table id="maintable"> <thead> <tr> <th>name</th> <th>version</th> <th>actions</th> </tr> </thead> <tbody> <g:each var="eval" in="${skillevallist}"> <tr> <td> <strong> ${eval.name} </strong> </td> <td> ${eval.formversion} </td> <td> <g:actionsubmit value="delete" controller="skilleval" action="delete" onclick="setid(${eval.id});return confirm('are sure?');" class="delete" /> </td> </tr> </g:each> </tbody> </table> <g:if test="${(skillevalcount/maxcount) > 1}"> <div class="pagination"> <g:paginate action="list" total="${skillevalcount}" /> </div> </g:if> <input id="evalid" type="hidden" name="id" value="" /> </g:form> </div> <r:script> function setid(id) { $('#evalid').val(id); } </r:script>

relevant code in controller class

skillevalcontroller.groovy def delete(long id) { def skilleval = skilleval.get(id) if (skilleval) { def allinstances = skillevali.findallbyform(skilleval) allinstances.each { evalinstance -> evalinstance.lines.clear() if(!evalinstance.delete()) { println "failed delete skill eval instance" } else { println "instance deleted." } } seek { skilleval.delete(flush: true) } grab (dataintegrityviolationexception e) { } } redirect(action: "list") }

how can create view retain queried results after deleting 1 of queried items?

when redirect list action can provide parameters -- capture parameters (if any) in delete action , pass them in redirect phone call list @ end of controller action.

(update: forgot actionsubmit not take params attribute, cobbled solution this answer , the grails docs)

example:

// view (list.gsp) <g:actionsubmit action="deletewithparams" value="delete" ... /> // controller def list() { def deletewithparams = { forward(action:'delete', params:[search: params?.search]) } render... } def delete(long id) { // deleting skilleval ... redirect(action: "list", params: [search: params?.search]) }

grails groovy gsp

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -