0

I have this DomainClass:

package cm

class XXX{


    String city
    String website

    static constraints = {
     city(nullable: true)
     website(nullable: true)

    }

    static mapping = {
        id column:'xxx_id'
        city column: 'xxx_city'
        website column: 'xxx_website'
        table "xxx_XXX"
        version false

}
}

The Controller:

class ConferenceController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [XXXInstanceList: XXX.list(params), XXXInstanceTotal: XXX.count()]
    }

    def save = {
        def XXXInstance= new XXX(params)
        if (!XXXInstance.save(flush: true)) {
            render view: 'add', model: [XXXInstance: XXXInstance]
            return
        }

        //flash.message = "${message(code: 'default.created.message', args: [message(code: 'person.label', default: 'Person'), personInstance.id])}"
        redirect(uri:"/index.gsp")
    }

}

and my add.gsp page:

<head>

  <title> xXXx</title>
  <meta name="layout" content="main2" />


</head>

...


<g:form controller="XXX" action="save">

  <g:hasErrors bean="${XXXInstance}">
   <div class="errors">
      <g:renderErrors bean="${XXXInstance}" as="list" />
   </div>
</g:hasErrors>


    year
    <g:textField name="year" /><br>
    website
    <g:textField name="website" /><br>

    <g:submitButton name="save2" value="Save" />

     </g:form></div>
    </div>


              ...
</body>

With this current code, everything works fine, but when a contraint is failed, it is showns the corresponding error but the written values are gone.. I cant figure this out - i'v tried a lot of things, but im sure the solution is as easy as my question -.- Please help.

John
  • 259
  • 8
  • 19

1 Answers1

0

I think you should check the *.properties file in YOUR_PROJECT\grails-app\i18n folder. They have the definition for translation. Investigate it for a time and refer to the document if need, you will understand how Grails perform translation.

And uncomment the following line in your controller:

//flash.message = "${message(code: 'default.created.message', args: [message(code: 'person.label', default: 'Person'), personInstance.id])}"
Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
  • hm i think i was not very specific :p What i mean is, while completing a form, if some of the contraints fail, the page is 'reloaded' and i lose my previous introduced information. – John May 10 '11 at 02:50
  • @John: that is another problem. If my guess is right, this page is made by scaffolding utility of Grails: it only add the server-side validation. If you want to keep the information entered before submitting, you should try some client-side validation, by jQuery-javascript for example – Hoàng Long May 10 '11 at 02:53
  • @John: You can check some client-side validation solution here:http://stackoverflow.com/questions/1806086/grails-client-side-validation – Hoàng Long May 10 '11 at 02:57
  • no. it was not made with scaffolding because i need it relatively diferent. The grails scaffolding does it, and it isnt using jQuery-js so there might be a thing here. Any idea? – John May 10 '11 at 15:47
  • @John: I recommend you take a look at the jQuery validation plugin for Grails(http://www.grails.org/plugin/jquery-validation). Or if you are familiar with javascript, you can use the jQuery-validation plugin directly – Hoàng Long May 11 '11 at 02:37