I have class Menu, it's a self to self with manytoone and onetomany relational.
package models;
import java.util.*;
import javax.persistence.*;
import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;
import static play.data.validation.Constraints.*;
import javax.validation.*;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonManagedReference;
import com.avaje.ebean.*;
import play.i18n.Messages;
@Entity
public class Menu extends Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
@Required
@MinLength(4)
@MaxLength(30)
public String name;
public String url;
@Transient
public boolean hasChild() {
return url.isEmpty();
}
public Integer idx;
@Temporal(TemporalType.TIMESTAMP)
@Formats.DateTime(pattern = "yyyy/MM/dd hh:mm:ss")
public Date created;
@Required
public boolean enabled;
@ManyToOne
@JsonBackReference
public Menu parent;
@OneToMany
@JsonManagedReference("parent")
public List<Menu> children;
public static Model.Finder<Long, Menu> find = new Model.Finder<Long, Menu>(Long.class, Menu.class);
public static List<Menu> findTops() {
return find.where().eq("parent_id", null).eq("enabled", true).orderBy("idx asc").findList();
}
public static List<Menu> findChildsByParent(Menu parent) {
return findChildsByParent(parent, true);
}
public static List<Menu> findChildsByParent(Menu parent, boolean enabled) {
return find.where().eq("parent_id", parent.id).eq("enabled", enabled).orderBy("idx asc").findList();
}
public static boolean hasChilds(Menu parent) {
return hasChilds(parent, true);
}
public static boolean hasChilds(Menu parent, boolean enabled) {
return find.where().eq("parent_id", parent.id).eq("enabled", enabled).findList().size() > 0;
}
public static Page<Menu> findPage(int page, int size) {
return find.findPagingList(size).getPage(page - 1);
}
public Menu() {
}
}
In Controller code is :
@BodyParser.Of(BodyParser.Json.class)
public static Result menuJson() {
if (menus == null) {
menus = Menu.find.all();
}
JsonNode json = new ObjectMapper().valueToTree(menus);
return ok(json);
}
Error details is:
[RuntimeException: java.lang.IllegalArgumentException: Query threw SQLException:Unknown column 't1.menu_id' in 'on clause' Bind values:[1] Query was: select t0.id c0 , t1.id c1, t1.name c2, t1.url c3, t1.idx c4, t1.created c5, t1.enabled c6, t1.parent_id c7 from menu t0 left outer join menu t1 on t1.menu_id = t0.id where t0.id = ? order by t0.id (through reference chain: com.avaje.ebean.common.BeanList[0]->models.Menu["children"])]
It's there have good solution to solve them or how to declare a custom serialize? For the tree model i don't have good object to class design,is't there a better design for this env.?
Jquery Dynamic Table. Adding a div for each cell to make it draggable
I am trying to create a dynamic table using JQuery.
Right now, I want each cell to be a div
but I am not sure how I should go about doing it.
My ultimate goal is wanting each element to be draggable and changing them to be a div seems like a good idea.
Please do suggest any possible ways of doing it or how I could go about changing each cell to be a div so I could make it draggable.
This are the relevant codes.
//create table function
function createDynamicTable(tbody, rows, cols) {
if(tbody == null || tbody.length < 1) return;
for(var r=1; r<=rows; r++){
var trow=$("<tr>");
for(var c=1; c<=cols; c++){
//first column data
if (c==1){
if(r==1){
$("<td>")
.addClass("tableCell")
.text("Subject")
.data("col", c)
.appendTo(trow);
}
if(r==2){
$("<td>")
.addClass("tableCell")
.text("Monday")
.data("col", c)
.appendTo(trow);
}
if(r==3){
$("<td>")
.addClass("tableCell")
.text("Tuesday")
.data("col", c)
.appendTo(trow);
}
if(r==4){
$("<td>")
.addClass("tableCell")
.text("Wednesday")
.data("col", c)
.appendTo(trow);
}
if(r==5){
$("<td>")
.addClass("tableCell")
.text("Thursday")
.data("col", c)
.appendTo(trow);
}
if(r==6){
$("<td>")
.addClass("tableCell")
.text("Friday")
.data("col", c)
.appendTo(trow);
}
if(r==7){
$("<td>")
.addClass("tableCell")
.text("Saturday")
.data("col", c)
.appendTo(trow);
}
if(r==8){
$("<td>")
.addClass("tableCell")
.text("Sunday")
.data("col", c)
.appendTo(trow);
}
}
else{
//for first row
if(r==1){
if(c==2){
$("<td>")
.addClass("tableCell")
.text("101")
.data("col", c)
.appendTo(trow);
}
if(c==3){
$("<td>")
.addClass("tableCell")
.text("102")
.data("col", c)
.appendTo(trow);
}
if(c==4){
$("<td>")
.addClass("tableCell")
.text("103")
.data("col", c)
.appendTo(trow);
}
if(c==5){
$("<td>")
.addClass("tableCell")
.text("104")
.data("col", c)
.appendTo(trow);
}
if(c==6){
$("<td>")
.addClass("tableCell")
.text("105")
.data("col", c)
.appendTo(trow);
}
}
else{
var cellText = "Cell " + r + "." + c
$("<td>")
.addClass("tableCell")
.text(cellText)
.data("col", c)
.appendTo(trow);
}
}
}
trow.appendTo(tbody);
}
}