[2.2 Java] Form Fill

38 views
Skip to first unread message

Sushi

unread,
Oct 14, 2013, 10:04:30 AM10/14/13
to play-fr...@googlegroups.com
Hi all,

I am trying to fill data into a form...
In my client I have

    public static Result editIndex(Long id) {
       
Form<Client> clientForm = Form.form(Client.class).fill(Client.find.byId(id));
       
return ok(editClient.render(id, clientForm));
   
}


When using
        System.out.println(clientForm.get().email);


I get the email printed.

But when accessing the same data in the template I do not get any data...
So here ist the template code:

@(id: Long, clientForm: Form[Client])
@import helper._
@implicitFieldConstructor = @{ FieldConstructor(views.html.twitterBootstrapAdminTheme.render) }

@pageLevelStyles = {
   
<link media="screen" rel="stylesheet" href="@routes.Assets.at("vendors/datepicker.css")"></link>
}

@pageLevelScripts = {
       
<script src="@routes.Assets.at("vendors/bootstrap-datepicker.js")"></script>
}

@scripts = {
<script>
    $
(function() {
        $
(".datepicker").datepicker();
   
});
</script>
}

@title = {
    Edit Client
}


@main(title, "clients", scripts, pageLevelStyles, pageLevelScripts) {
<div class="row-fluid">
    <!-- block -->
    <div class="block">
        <div class="navbar navbar-inner block-header">
            <div class="muted pull-left">Edit client -> @clientForm("id").value()</
div>
       
</div>
        <div class="block-content collapse in">
            <div class="span12">

                @helper.form(action = routes.Clients.update(id), 'class -> "form-horizontal") {
                   @views.html.clients.clientFormFull(clientForm)
                   <input class="span12" type="hidden" name="id" value="@clientForm("id").value">
                }
               
            </
div>
       
</div>
    </
div>
   
<!-- /block -->
</div>

}
Code hier eingeben...

 with clientFormFull
@(clientForm: Form[Client])
@import helper._
@implicitFieldConstructor = @{ FieldConstructor(views.html.twitterBootstrapAdminTheme.render) }

<fieldset>
 
<legend>Person Info</legend>
 
 <div class="row-fluid">
    <div class="span6">
         @helper.inputText(clientForm("firstname"), '_label -> "Firstname", 'class -> "span12", 'placeholder -> "Clients firstname...")
    </
div>
   
<div class="span6">
         
@helper.inputText(clientForm("lastname"), '_label -> "Lastname", 'class -> "span12", 'placeholder -> "Clients lastname...")
    </div>
 </div>

 <div class="row-fluid">
    <div class="span6">
         @helper.select(clientForm("gender"), options(Seq("Male", "Female")), '
_label -> "Gender", 'class -> "span12")
    </div>
    <div class="span6">
         @helper.inputText(clientForm("dateofbirth"), '
_label -> "Date of Birth", 'class -> "span12 datepicker", 'placeholder -> "mm/dd/yy")
   
</div>
 </
div>
</fieldset>

<fieldset>
 <legend>Address</
legend>
 
<div class="row-fluid">
     
<div class="span12">
         
@helper.inputText(clientForm("street"), '_label -> "Street", 'class -> "span12")
     
</div>
 </
div>
 
<div class="row-fluid">
     
<div class="span6">
         
@helper.inputText(clientForm("zipcode"), '_label -> "Post Code", 'class -> "span12")
     
</div>
     <div class="span6">
         @helper.inputText(clientForm("city"), '_label -> "City", 'class -> "span12")
     </
div>
 
</div>
 
 <legend>Contact</
legend>
 
<div class="row-fluid">
     
<div class="span6">
         
@helper.inputText(clientForm("phone"), '_label -> "Phone Number", 'class -> "span12")
     
</div>
     <div class="span6">
         @helper.inputText(clientForm("email"), '_label -> "EMail", 'class -> "span12")
     </
div>
 
</div>
</
fieldset>
 

 
<div class="form-actions">
     
<button class="btn btn-primary" type="submit">
       
<i class="icon-ok icon-white"></i>
       
Save changes
     
</button>
     <a href=""><button class="btn">Cancel</
button></a>
 
</div>
                   


Does anybody has an idea why I don't get the data into the form?

Bests,
Sushi
Message has been deleted

Sushi

unread,
Oct 14, 2013, 10:17:56 AM10/14/13
to play-fr...@googlegroups.com
Hi all,

so according to another post I could figure out that we now (since play 2.2) need getters and setters...
When I add them to my client model class than the error mentioned above is solved!

But I do not understand why we now need getters and setters for public attributes?! Can anybody explain this descision to me?

Bests,
Sushi
Reply all
Reply to author
Forward
0 new messages