Search code examples
grailsgrails-ormgrails-domain-classgrails-controller

get values of variable defined on controller without writting query in action


I have the following code in my Controller.

class WorkStationAssetController {
     def requestList = Request.list()

     def list = {
         [requestList :requestList]
     }        

     def save = {
         def requestInstance = new Request(params)            
         requestInstance.save(flush:true)  
         redirect(action:'list')            
     }
}

In requestList variable, I get the list of requests with newly saved values.

My question is how do I get the new value without writing query (say Request.list()) in render part of save action.


Solution

  • If you really just need to get the list of Requests, you can add to the top of your template:

    <%@ page import="your.package.Request" %>
    

    and where you need the list just call:

    ${ Request.list() }