Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot render my returned Backbone models
    primarykey
    data
    text
    <p>My first post so please go easy on me..</p> <p>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...</p> <p>In my <code>Group</code> model I have a <code>Users</code> collection. </p> <p>This is returned as a <code>List&lt;User&gt;</code> from JAX and <code>User</code> has the <code>@XmlRootElement</code> annotation on it. </p> <p>But when I call fetch it fills the <code>Group</code> model with an array of <code>User</code> models instead of a <code>Users</code> collection.</p> <p>Is there a way to tell JAX to return my list of <code>User</code> models as a <code>Users</code> collection?</p> <p>Any help appreciated!</p> <p>EDIT:</p> <p>Group model in Backbone:</p> <pre><code>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 &gt; 0 ? errors : false; } }); </code></pre> <p>Group model in Java:</p> <pre><code>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&lt;User&gt; users; public List&lt;User&gt; getUsers() { return users; } public void setUsers(List&lt;User&gt; 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; } } </code></pre> <p>JSON returned:</p> <pre><code>"groups":[{"name":"mates","id":71,"users":[{"id":6,"password":"&lt;PASSWORD&gt;","email":"&lt;EMAIL&gt;","firstName":"Jake","lastName":"Duncan"},{"id":7,"password":"&lt;PASSWORD&gt;","email":"&lt;EMAIL&gt;","firstName":"alec","lastName":"stearn"}],"ownerid":0}] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload