Search code examples
grailsgsp

Update or change user data form in Grails


I must write an update or change user data form in Grails. This is my form:

<g:form class="form-signin" controller="VisitorSpace">
    <label for="login" class="sr-only">Login</label>
    <g:textField id="login" class="form-control" name="login" placeholder="login" required="" autofocus=""/>
    <label for="firstName" class="sr-only">Your name</label>
    <g:textField id="firstName" class="form-control" name="firstName" placeholder="Your name" required="" type="text"/>
    <label for="lastName" class="sr-only">Your lastname</label>
    <g:textField id="lastName" class="form-control" name="lastName" placeholder="Your lastname" required=""  type="text"/>

    <label for="inputEmail" class="sr-only">e-mail</label>
    <g:textField id="inputEmail" class="form-control" name="email" placeholder="e-mail" required="" autofocus="" data-translatable-string="Email address" type="email"/>
    <label for="inputPassword" class="sr-only">Password</label>
    <g:passwordField id="inputPassword" class="form-control" name="password" placeholder="Password" required="" data-translatable-string="Password"/>

    <label for="confirmPassword" class="sr-only">Confirm password</label>
    <g:passwordField id="confirmPassword" class="form-control" name="controlPassword" placeholder="Confirm password" required="" data-translatable-string="Password"/>
    <g:actionSubmit value="Commit change"  action="updateUserData" class="btn btn-lg btn-primary btn-block">Commit change</g:actionSubmit>
</g:form>

The old data must be shown in the fields, so it must be sent from the database to the moment when the view-form will be loaded. I know, what may be possible to call required controller-method to do this and such method must be called before or while view-form will be loading. But how to do this?


Solution

  • Add the value attribute to your input field elements with the current data you want from the controller. Is that what you are asking for?

    <g:textField id="lastName" value="${objectInstance.lastName}" ... />