-1

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.

Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
Hardik Patel
  • 937
  • 3
  • 14
  • 39

2 Answers2

0

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() }
Tom Metz
  • 919
  • 6
  • 7
  • I get newly saved data in requestList variable without writting Request.List(), i just wants to know how it is possible without writting query. – Hardik Patel May 31 '12 at 06:02
  • I don't believe, your approach is possible. How the system should know, that you want to fill your variable 'requestList' with Request.list(). This is IMO far behind convention-over-configuration. – Tom Metz May 31 '12 at 06:50
  • I also don't know how the system interpret it. but i got the updated result in requestList varible without writting query,it looks like magic on grails. – Hardik Patel May 31 '12 at 07:14
  • Hello Tom, i have edit my question. After saving, i redirect control to the action where i get updated result. Do you know how it's possible. – Hardik Patel May 31 '12 at 07:55
  • The instance of WorkStationAssetController is created by the new request and because you're filling in the variable 'requestList' in the class body, it gets filled ;-) – Tom Metz May 31 '12 at 09:08
0

in your list action you used global variable, which contains list of requests, and in list action you just returns that value to gsp page, that is the reason you are getting old as well as new requests created.

sanghavi7
  • 758
  • 1
  • 15
  • 38