Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate Play! Framework 1.2.3 application controller to 2.0

Out of curiosity I would like to migrate a Play! 1.2.3 Java application to Play! 2.0, but I'm having difficulty understanding the new application controller. I've examined the three example applications, but they've been of little help to me as I'm not an experienced programmer. Here is a stripped down example of how I currently approach an application controller in Play! 1.2.3.

The Master and Detail classes:

@Entity
public class Master extends Model {
    public String name;
    public String address;
    @OneToMany(cascade=CascadeType.ALL,mappedBy="detailId")
    public List<Detail> details;
}

@Entity
public class Detail extends Model {
    public String pet;
    @JoinColumn(name="detail_id")
    @ManyToOne
    public Master detailId;
}

The Application class:

public class Application extends Controller {

    public static void master(Long id) {
        Master master = Master.findById(id);
        render(master);
    }

    public static void saveMaster(final Master master) {
        master.save();
    }

    public static void saveDetail(Long id, final Detail detail) {
        Master master = Master.findById(id);
        detail.detailId = master;
        detail.save();
        master.details.add(detail);
        master.save();
        master(id)
   }
}

I know it's far from elegant but it works and code is easy for me to follow. I would like to do something similar using the new framework and any help would be greatly appreciated.

like image 760
Francois Green Avatar asked Dec 23 '11 16:12

Francois Green


1 Answers

You can use the wiki as a reference. The new Controller would be similar to:

public class Application extends Controller {

    public static Result master(Long id) {
        Master master = Master.findById(id);
        return ok(master);
    }

    ...
}
like image 139
Pere Villega Avatar answered Nov 11 '22 22:11

Pere Villega