public static String update(String id, User user) {
user.update(id);
return ("Your profile has been updated");
}
public static Result updateUser() { Form<UpdateUser> filledForm = updateUserForm.bindFromRequest(); if(filledForm.hasErrors()) { flash("success","Error while updating (Form filled uncorrectly)"); }else{ UpdateUser uuser = filledForm.get(); if(uuser.id.equals(User.find.byId(request().username()).id)) { User newUser = new User(uuser.id, uuser.email, User.find.byId(request().username()).name, User.find.byId(request().username()).surname, User.find.byId(request().username()).rank, uuser.password); System.out.println(newUser.toString()); flash("success", User.update(newUser.id, newUser)); }else{ flash("success", "Error while updating (ID not corresponding)"); } } return redirect(routes.Application.dashboard()); }[RuntimeException: DataSource user is null?]
libraryDependencies ++= Seq(javaJdbc,javaEbean,cache)
package models;
import java.util.List;
import javax.persistence.*;
import controllers.Application;import controllers.Application.UpdateUser;
import play.data.validation.Constraints.Required;import play.db.ebean.Model;import play.db.ebean.Model.Finder;
@Entitypublic class User extends Model { @Id @Required public String id; public String email; @Required public String name; public String surname; @Required public int rank; @Required public String passphrase; public static Finder<String,User> find = new Finder(String.class, User.class); /** * @param id * @param email * @param name * @param surname * @param passphrase * @param rank */ public User(String id, String email, String name, String surname, int rank, String passphrase) { this.id = id; this.email = email; this.name = name; this.surname = surname; this.rank=rank; this.passphrase = passphrase; }
public static List<User> all() { return find.all(); } public static String create(User user) { try{ user.save(); return ("User "+user.id+" has been successfully created"); }catch(Exception e){return("Error : user "+user.id+" already exists");} } public static void deleteUser(String id) { find.ref(id).delete(); } public static String update(String id, User user) { user.update((Object)id); return ("Your profile has been updated"); }
public static User authenticate(String id, String passphrase) { return find.where().eq("id", id) .eq("passphrase", passphrase).findUnique(); } public String toString() { return("User : "+this.id+" ; "+this.email+" ; "+this.surname+" "+this.name+" ; rank"+this.rank+" ; passphrase : "+this.passphrase); }}