at-m42:casestudies:cs05
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
at-m42:casestudies:cs05 [2009/04/30 16:59] – eechris | at-m42:casestudies:cs05 [2011/01/14 12:59] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 40: | Line 40: | ||
We shall take the example that we have developed over the previous four case studies, and re-implement //Player// and //Item// administration for an adventure game in Grails. | We shall take the example that we have developed over the previous four case studies, and re-implement //Player// and //Item// administration for an adventure game in Grails. | ||
- | * [[at-m42: | + | * [[at-m42: |
* [[#Step 2: Create project]] | * [[#Step 2: Create project]] | ||
+ | * [[#Step 3: Run Application]] | ||
+ | * [[#Step 4: Create First Domain Class]] | ||
+ | * [[#Step 5: Add some properties and a Controller]] | ||
+ | * Further steps ... to be written! | ||
An index to the source code for all the examples in this case study is [[/ | An index to the source code for all the examples in this case study is [[/ | ||
Line 152: | Line 156: | ||
Environment set to development | Environment set to development | ||
[mkdir] Created dir: e: | [mkdir] Created dir: e: | ||
- | [groovyc] Compiling 6 source files to e: | + | [groovyc] Compiling 6 source files to e: |
- | ame\classes | + | [mkdir] Created dir: e: |
- | [mkdir] Created dir: e: | + | [native2ascii] Converting 11 files from E: |
- | rails-app\i18n | + | |
- | [native2ascii] Converting 11 files from E: | + | |
- | dy-05\game\grails-app\i18n to e: | + | |
- | ces\grails-app\i18n | + | |
- | | + | |
- | s | + | |
- | | + | |
- | bling\.grails\1.1\projects\game\resources | + | |
Running Grails application.. | Running Grails application.. | ||
Server running. Browse to http:// | Server running. Browse to http:// | ||
</ | </ | ||
- | Now connect to http:// | + | Now connect to http:// |
+ | {{: | ||
+ | |||
+ | | ||
+ | |||
+ | ==== Step 4: Create First Domain Class ==== | ||
+ | |||
+ | Run command '' | ||
+ | <cli prompt=">"> | ||
+ | e: | ||
+ | Welcome to Grails 1.1 - http:// | ||
+ | Licensed under Apache Standard License 2.0 | ||
+ | Grails home is set to: d: | ||
+ | |||
+ | Base Directory: E: | ||
+ | Running script d: | ||
+ | Environment set to development | ||
+ | Created DomainClass for Item | ||
+ | Created Tests for Item | ||
+ | e: | ||
+ | </ | ||
+ | |||
+ | Creates a domain class '' | ||
+ | <code groovy 1|Listing 2: Domain class Item.groovy (at-m42/ | ||
+ | class Item { | ||
+ | |||
+ | static constraints = { | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | It also creates a '' | ||
+ | <code groovy 1|Listing 3: Test class for domain class Item.groovy (at-m42/ | ||
+ | import grails.test.* | ||
+ | |||
+ | class ItemTests extends GrailsUnitTestCase { | ||
+ | protected void setUp() { | ||
+ | super.setUp() | ||
+ | } | ||
+ | |||
+ | protected void tearDown() { | ||
+ | super.tearDown() | ||
+ | } | ||
+ | |||
+ | void testSomething() { | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Unit test and integration tests can be run automatically from the command line using '' | ||
+ | |||
+ | ==== Step 4: Add some properties and a Controller ==== | ||
+ | |||
+ | Each domain class is simply a Plain-Old-Groovy-Object with one major difference. If we add some properties, these will be automatically persisted to a database. | ||
+ | <code groovy 1|Listing 4: Item class with properties (at-m42/ | ||
+ | class Item { | ||
+ | |||
+ | static constraints = { | ||
+ | } | ||
+ | | ||
+ | String name | ||
+ | String description | ||
+ | Integer weight | ||
+ | |||
+ | String toString() { return " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | If we now add a controller, we will be able to create some objects via the web interface. | ||
+ | <cli prompt=">"> | ||
+ | e: | ||
+ | |||
+ | Welcome to Grails 1.1 - http:// | ||
+ | Licensed under Apache Standard License 2.0 | ||
+ | Grails home is set to: d: | ||
+ | |||
+ | Base Directory: E: | ||
+ | Running script d: | ||
+ | Environment set to development | ||
+ | Created Controller for Item | ||
+ | [mkdir] Created dir: E: | ||
+ | Created Tests for Item | ||
+ | e: | ||
+ | </ | ||
+ | |||
+ | As you can see this creates a new controller | ||
+ | <code groovy 1|Listing 5: ItemController class (at-m42/ | ||
+ | class ItemController { | ||
+ | |||
+ | def index = { } | ||
+ | } | ||
+ | </ | ||
+ | It also creates another '' | ||
+ | |||
+ | Before we use this, we'll make Grails generate the necessary views " | ||
+ | <code groovy 1|Listing 6: ItemController class with dynamic scaffolding (at-m42/ | ||
+ | class ItemController { | ||
+ | |||
+ | def scaffold = Item | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | I found that at this step, I had to stop the running grails application, | ||
+ | |||
+ | After this runs, you will be able to browse to http:// | ||
---- | ---- | ||
[[at-m42: | [[at-m42: |
at-m42/casestudies/cs05.1241110789.txt.gz · Last modified: 2011/01/14 12:48 (external edit)