Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update an existing object in playframework 2.0.2? aka CRUD in 1.2.x

Have tried to lookup info in a lot of doc, but seem to not find the right answer.

My scenario: 1. Create Object by using Form (GUI) 2. Submit - save. 3. Reopen the object (picking from the list) 4. Edit the object 5. Save the updates to an existing object.

The problem seems how to bind the ID of the existing object to an field on the Form.

Thanks.

Bård

like image 454
user1523029 Avatar asked Jan 01 '26 19:01

user1523029


1 Answers

See the code from example for updating object

public static Result update(Long id) {
    Form<Computer> computerForm = form(Computer.class).bindFromRequest();
    if(computerForm.hasErrors()) {
        return badRequest(editForm.render(id, computerForm));
    }
    computerForm.get().update(id);
    flash("success", "Computer " + computerForm.get().name + " has been updated");
    return GO_HOME;
}

Whole sample is available in your play directory or on github

like image 103
biesior Avatar answered Jan 10 '26 05:01

biesior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!