Note that there are some explanatory texts on larger screens.

plurals
  1. POSencha: Iterating a list store of a custom BaseModel subclass
    text
    copied!<p>I just started playing with Sencha's Ext GWT yesterday and I've hit a wall. I combined methods from their JSON loaded grid and their editable grid. As a test data set I'm using a list of Stargate Atlantis episodes hence the SGAEpisode which is defined as:</p> <pre><code>public class SGAEpisode extends BaseModel { public SGAEpisode() { } public SGAEpisode(String season, String episode) { set("season",season); set("episode",episode); } public void setSeason(String season) { set("season",season); } public String getSeason(){ return get("season"); } public void setEpisode(String name) { set("episode",name); } public String getEpisode() { return get("episode"); } public String toString() { return "Season: " + get("season") + " episode: " + get("episode"); } } </code></pre> <p>the onModuleLoad() starts off with...</p> <pre><code>ModelType type = new ModelType(); type.setRoot("seasons"); type.addField("Season","season"); type.addField("Episode","episode"); String path = GWT.getHostPageBaseURL() + "senchaapp/sgaepisodes"; final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,path); final MVProxy&lt;String&gt; proxy = new SProxy&lt;String&gt;(builder); JsonLoadResultReader&lt;ListLoadResult&lt;SGAEpisode&gt;&gt; reader = new JsonLoadResultReader&lt;ListLoadResult&lt;SGAEpisode&gt;&gt;(type); final BaseListLoader&lt;ListLoadResult&lt;SGAEpisode&gt;&gt; loader = new BaseListLoader&lt;ListLoadResult&lt;SGAEpisode&gt;&gt;(proxy,reader); final ListStore&lt;SGAEpisode&gt; episodes = new ListStore&lt;SGAEpisode&gt;(loader); </code></pre> <p>so loader.load() works great, populating a grid, I can edit fields, but I don't see commitChanges() doing anything and I can't iterate over the ListStore "episodes" to gather changed or added values. Oh, and SProxy is just a DataProxy subclass to allow me to specify the season's JSON I'm loading into the grid.</p> <p>If I try either </p> <pre><code>for(SGAEpisode episode : episodes) { save(episode); } </code></pre> <p>or </p> <pre><code>for(int i = 0; i &lt; episodes.getCount(); i++) { save(episodes.getAt(i)); } </code></pre> <p>I get an exception with the message "com.extjs.gxt.ui.client.data.BaseModel cannot be cast to com.mvsc.sencha.shared.SGAEpisode" Any idea what I'm doing wrong? Everything up to that point was defined/populated with SGAEpisodes.....</p> <p><em>Addendum</em> Ok, so if I try </p> <pre><code>List&lt;Record&gt; modified = episodes.getModifiedRecords(); for(Record r : modified) { ModelData md = r.getModel(); save(md.get("season"),md.get("episode")); } </code></pre> <p>I can iterate, and get the modified values, but what's the point of having a ModelData subclass if I have to use the base class like this. Which makes me think I don't in fact have to..... little help?</p> <p><em>Addendum 2</em> I tried subclassing BaseModelData instead with no success.</p>
 

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