Matthias Neumann
Matthias Neumann

Reputation: 1

Error after adding a new property in a base class in grails

I created a very simple Grails Project (IntelliJ IDEA 14.0.2) named CheckInheritance Two domain classes:

package checkinheritance

class Parent {

  String name

  static constraints = {
  }
}


package checkinheritance

class Child extends Parent{

  String prename

  static constraints = {
  }
}

I generated the controller class and the views for the Child class When I start the application everythin works fine.

Then I add the property "dscription" to the Parent class:

package checkinheritance

class Parent {

  String name
  String description

  static constraints = {
  }
}

I deleted the views and the controller for the Child class. Then I regenerate the files (view, controller) for the Child class. When I start the application, I want to add a Child object. After entering the Data (in ALL input fields) and press "Anlegen" (Save) I get an error that the property "description" must not be null (see Screenshot with german messages). This also happens when the base class is abstract. The Database is empty and new (Dev mode).

This is my generatet _form.gsp for the property "description":

<div class="fieldcontain ${hasErrors(bean: childInstance, field: 'description', 'error')} required">
    <label for="description">
        <g:message code="child.description.label" default="Description" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="description" required="" value="${childInstance?.description}"/>

</div>

Do I have to add something for the new property "description" in the base class?

This is my environment:

APPLICATION STATUS App version: 0.1 Grails version: 2.4.4 Groovy version: 2.3.7 JVM version: 1.8.0_25 Reloading active: true Controllers: 3 Domains: 2 Services: 3 Tag Libraries: 15 INSTALLED PLUGINS restResponder - 2.4.4 logging - 2.4.4 i18n - 2.4.4 dataBinding - 2.4.4 core - 2.4.4 servlets - 2.4.4 codecs - 2.4.4 webxml - 1.4.1 databaseMigration - 1.4.0 jquery - 1.11.1 dataSource - 2.4.4 urlMappings - 2.4.4 controllers - 2.4.4 assetPipeline - 1.9.9 filters - 2.4.4 domainClass - 2.4.4 controllersAsync - 2.4.4 mimeTypes - 2.4.4 hibernate4 - 4.3.6.1 converters - 2.4.4 groovyPages - 2.4.4 services - 2.4.4 validation - 2.4.4 scaffolding - 2.1.2 cache - 1.1.8

Upvotes: 0

Views: 99

Answers (1)

praveen_programmer
praveen_programmer

Reputation: 1062

By default description in mandatory. cause it is nullable = false;

you can try

    String name
    String description

    static constraints = {
    description nullable: true

    }

Upvotes: 1

Related Questions