Ignore:
Timestamp:
Jan 28, 2010, 6:42:30 PM (10 years ago)
Author:
keesvb
Message:

added helper functions to Subject and Template classes to easily get the template fields, and added a demonstration of use in the sandbox

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/SandboxController.groovy

    r144 r146  
    1 import dbnp.studycapturing.Study
     1import dbnp.studycapturing.*
    22
    33// The sandbox is meant for internal communication over code examples etc.
     
    55class SandboxController {
    66
    7     def index = {
     7        def index = {
    88
    9         // Get the example study in a lazy way
    10         def st = Study.get(1)
    11         def f = st.template.subjectFields
     9                // Get the example study in a lazy way
     10                def st = Study.get(1)
     11                def f = st.template.subjectFields
    1212
    13         // This is a way to iterate over the fields in your controller
    14         // And print them to the console
    15         // Most of the time, you would just iterate over them in the view using <g:each>
    16         // See also views/sandbox/index.gsp
    17         f.each{ field ->
    18                 println field.name}
     13                // This is a way to iterate over the fields in your controller
     14                // And print them to the console
     15                // Most of the time, you would just iterate over them in the view using <g:each>
     16                // See also views/sandbox/index.gsp
     17                f.each {field ->
     18                        println field.name + "(" + field.type + ")"
     19                }
    1920
    20         // Specify which variables we want to be available in the controller (implicit return statement)
    21         [fields : f]
    22     }
     21                //Let's get a certain field for a certain subject
     22                def subject = Subject.findByName('A1')
     23                println st.template.getSubjectFieldType('Age')
     24                println subject.getFieldValue('Age')
     25
     26
     27                // Specify which variables we want to be available in the controller (implicit return statement)
     28                [fields: f, subjects: st.subjects]
    2329}
     30}
Note: See TracChangeset for help on using the changeset viewer.