I'm working on a very basic Grails application in order to dip my toes into web development.
Unfortunately, I'm stuck at trying to display a collection within my MongoDB database using the <f:table>-field tag.... Because the tag somehow seems to be incompatible with the unique constraint of my domain class? Is there anything I can do?
Here's the error message:
There was an unexpected error (type=Internal Server Error, status=500). Error processing GroovyPageView: [views/teaser/index.gsp:17] Error executing tag <f:table>: Exception thrown applying constraint [unique] to class [class com.test.site.Teaser] for value [true]: Cannot invoke "grails.gorm.validation.Constraint.isValid()" because "c" is null
My BootStrap contains two object instances for testing purposes; they seem to be working fine, since they appear in my MongoDB. Just to be safe, here is how I stored them:
new Teaser(imageUrl: "", teaserUrl: "", name: "mainTeaser", text: "").save()
new Teaser(imageUrl: "", teaserUrl: "", name: "footerTeaser", text: "").save()
Here's my domain class:
package com.test.site
class Teaser {
String imageUrl
String teaserUrl
String name
String text
static mapWith = "mongo"
static constraints = {
name blank: false
name unique: true
}
Here's the current state of my index.gsp (linked to my controller):
<!doctype html>
<html>
<head>
<meta name="layout" content="main">
<asset:stylesheet href="styles.css"/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Teaser Details</title>
</head>
<body id="body">
<header class="header">
</header>
<main class="main">
<div class="container">
<section>
<f:table collection="${teaserList}"/>
</section>
</div>
</main>
<footer class="footer">
</footer>
</body>
</html>
Finally, here's my controller:
package com.test.site
class TeaserController {
static scaffold = Teaser
def index() {
def teaserList = Teaser.list()
render view: "index", model: [teaserList : teaserList]
}
I'm grateful for any help :)