My first post so please go easy on me..
I am currently writing a hospital rostering web application in BackboneJS + JAX-RS. It has been ok until now but I can't for the life of me work this one out...
In my Group model I have a Users collection.
This is returned as a List<User> from JAX and User has the @XmlRootElement annotation on it.
But when I call fetch it fills the Group model with an array of User models instead of a Users collection.
Is there a way to tell JAX to return my list of User models as a Users collection?
Any help appreciated!
EDIT:
Group model in Backbone:
window.Group = Backbone.Model.extend({
urlRoot: "api/groups",
defaults: {
name: ''
},
validate: function(attrs){
var errors = [];
if (!attrs.name) {
errors.push({name: 'name', message: 'Please fill in the name field.'});
}
if(!attrs.users || attrs.users.length == 0){
errors.push({name: 'users', message: 'Please add at least 1 user.'});
}
return errors.length > 0 ? errors : false;
}
});
Group model in Java:
package org.jakeduncandev.roster;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Group {
private int id;
private String name;
private int ownerid;
private List<User> users;
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getOwnerid() {
return ownerid;
}
public void setOwnerid(int ownerid) {
this.ownerid = ownerid;
}
}
JSON returned:
"groups":[{"name":"mates","id":71,"users":[{"id":6,"password":"<PASSWORD>","email":"<EMAIL>","firstName":"Jake","lastName":"Duncan"},{"id":7,"password":"<PASSWORD>","email":"<EMAIL>","firstName":"alec","lastName":"stearn"}],"ownerid":0}]
parsefunction to set data to collection. - user10