porno porno rokettube
Results 1 to 3 of 3

Thread: How to write

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    2

    How to write

    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!

  2. #2
    Administrator dave's Avatar
    Join Date
    Mar 2010
    Location
    West Yorkshire, UK - Valencia Spain
    Posts
    110
    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.
    Connect with me on twitter : @davebrown1975 http://twitter.com/davebrown1975

    Web & Mobile Development by Tucanoo Solutions Ltd

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Quote Originally Posted by dave View Post
    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Forum Design by Tucanoo Solutions Ltd Grails Development Specialists.