How to write

M

mitteg

Guest
Hello,

I have a model like this:

class News{

String title
String content
String author

}

When I generate the controller and the view (grails generate-all News) then I have a working CRUD (Create, Read, Update and Delete). So far so good.

But I would like the "author" field to be filled in automatically from the logged in user. The username is accessible doing something like <sec: username> which retrieves the logged-in user from the CAS.

So, I would like to not have the "author" field in the create.gsp scaffolded view. Very much in the same way that dateCreated and lastUpdated get filled automatically.

Thank you very much!
 

dave

Administrator
Staff member
The best way would be to set the value in the create action of your controller, not in the view.
In your create action look where you create an instance of your News class, I expect it will be called newsInstance and set the author accordingly. It will then be passed through to your view with the author value set.
 
M

mitteg

Guest
The best way would be to set the value in the create action of your controller, not in the view.
In your create action look where you create an instance of your News class, I expect it will be called newsInstance and set the author accordingly. It will then be passed through to your view with the author value set.

Thank you!
 
Top