PDA

View Full Version : ListField used to modifiy BeanInfo within a RowEditor



Alkpone
29 Aug 2009, 2:58 AM
Hi all,

I'm trying to edit a List of object represented as a List in the Grid [OBJ1, OBJ2]. I'm using correctly the RowEditor by using BeanModelMarker.


final RowEditor<BeanModel> re = new RowEditor<BeanModel>();
Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
grid.setAutoExpandColumn("name");
grid.setBorders(true);
grid.addPlugin(re);
However as soon as I'm trying to use ListField, I have to use a ModelData, therefore I've tried to used ListField as follow. The disciplines field is List<Discipline> field in my Object.



ColumnConfig disciplineConfig = new ColumnConfig("disciplines", "Discipline", 200);
ListField<BeanModel> disciplineField = new ListField<BeanModel>();

disciplineConfig.setEditor(new CellEditor(disciplineField));

columns.add(disciplineConfig);
Everytimes I trying to edit a row this error occur :



[ERROR] Uncaught exception escaped
java.lang.ClassCastException: java.util.ArrayList
at com.extjs.gxt.ui.client.widget.form.ModelPropertyEditor.getStringValue(ModelPropertyEditor.java:1)
at com.extjs.gxt.ui.client.widget.form.Field.setValue(Field.java:888)
at com.extjs.gxt.ui.client.widget.form.Field.initValue(Field.java:1030)
at com.extjs.gxt.ui.client.widget.form.Field.afterRender(Field.java:975)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:961)


I probably using this not correctly, any help ?

mask_hot
20 Sep 2010, 4:16 AM
Hi, I'm trying to do the same : add a listField as cellEditor for a field through a roweditor.
When I insert a row I have a null pointer exception as there is no value for my field.
Is there something to do in preProcess and PostProcess methods to fix that?

sven
20 Sep 2010, 4:26 AM
mask_hot, can you please post a fully working testcase that implements EntryPoint and shows the exact problem you have?

mask_hot
20 Sep 2010, 4:37 AM
In a grid panel, I build my column like this :


final TeamList listTeam = new TeamList();
listTeam.getStore().getLoader().load();

cellEditor = new CellEditor(listTeam){
@Override
public Object preProcessValue(Object value) {
System.out.println("preProcess "+value);
if (value == null) {
return value;
}
BeanModel bm = (BeanModel)comboPlace.getStore().findModel(Team.PROP_KEY, value);

return bm;
}

@Override
public Object postProcessValue(Object value) {
System.out.println("postProcess "+value);
if (value == null) {
return value;
}
return ((ModelData) value).get(listTeam.getValueField());
}
};
column.setEditor(cellEditor);
this.columnConfig.add(column);

My teamList class :

/**
*
*/
package com.maskhot.fam.client.widget.combo;

import java.util.List;

import com.extjs.gxt.ui.client.Style.SortDir;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ListField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.maskhot.fam.client.service.Services;
import com.maskhot.fam.client.service.team.TeamService;
import com.maskhot.fam.client.service.team.TeamServiceAsync;
import com.maskhot.fam.model.team.Team;

/**
* @author mask_hot
*
*/
public class TeamList extends ListField<BeanModel> {

private static final String SERVICE_NAME = Services.SVC_TEAM;
private static final String COL_ID = "key";
private static final String COL_TEAM = "libelle";
private static final String DEFAULT_SORT = COL_TEAM;

private TeamServiceAsync service = (TeamServiceAsync) GWT.create(TeamService.class);


public TeamList() {
super();

ServiceDefTarget endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = GWT.getModuleBaseURL();
moduleRelativeURL += SERVICE_NAME;
endpoint.setServiceEntryPoint(moduleRelativeURL);

// proxy, reader and loader
RpcProxy<List<Team>> proxy = new RpcProxy<List<Team>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<Team>> callback) {
service.findAll(callback);
}

};

BeanModelReader reader = new BeanModelReader();
ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
loader.setSortField(DEFAULT_SORT);
loader.setSortDir(SortDir.ASC);
loader.setRemoteSort(true);

// configure store
final ListStore<BeanModel> store = new ListStore<BeanModel>(loader);

this.setStore(store);

this.setDisplayField(COL_TEAM);
this.setValueField(COL_ID);

// this.setForceSelection(true);
// this.setLoadingText("Chargement équipes");
this.setEmptyText("Equipes");
// this.setPageSize(10);

}



/* (non-Javadoc)
* @see com.extjs.gxt.ui.client.widget.form.ListField#setSelection(java.util.List)
*/
@Override
public void setSelection(List<BeanModel> selection) {
// TODO Auto-generated method stub
if (selection != null && selection.size() > 0) {
// super.setValue(selection.get(0));
listView.getSelectionModel().setSelection(selection);
} else {
super.setValue(null);
listView.getSelectionModel().deselectAll();
}
}


}


when I do the following :


Event item = new Event();
BeanModelFactory factory = BeanModelLookup.get().getFactory(Event.class);
BeanModel model = factory.createModel(item);rowEditor.stopEditing(false);
store.insert(model, 0);
rowEditor.startEditing(store.indexOf(model), true);


The error :


java.lang.NullPointerException: null
at com.extjs.gxt.ui.client.widget.ListViewSelectionModel.onLastFocusChanged(ListViewSelectionModel.java:270)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.setLastFocused(AbstractStoreSelectionModel.java:418)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.doMultiSelect(AbstractStoreSelectionModel.java:303)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.doSelect(AbstractStoreSelectionModel.java:321)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.select(AbstractStoreSelectionModel.java:232)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.select(AbstractStoreSelectionModel.java:236)
at com.extjs.gxt.ui.client.widget.form.ListField.setValue(ListField.java:210)
at com.extjs.gxt.ui.client.widget.form.ListField.setValue(ListField.java:1)
at com.extjs.gxt.ui.client.widget.grid.RowEditor.startEditing(RowEditor.java:421)
at com.maskhot.fam.client.widget.grid.EventGridPanel$2.componentSelected(EventGridPanel.java:155)
at com.maskhot.fam.client.widget.grid.EventGridPanel$2.componentSelected(EventGridPanel.java:1)
at com.extjs.gxt.ui.client.event.SelectionListener.handleEvent(SelectionListener.java:20)
at com.extjs.gxt.ui.client.event.SelectionListener.handleEvent(SelectionListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:178)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:86)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:454)
at com.extjs.gxt.ui.client.widget.button.Button.onClick(Button.java:586)
at com.extjs.gxt.ui.client.widget.button.Button.onComponentEvent(Button.java:285)
at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:864)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1307)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1263)
at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1714)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1669)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
at java.lang.Thread.run(Unknown Source)

mask_hot
20 Sep 2010, 4:59 AM
I'm wondering if the ListField.setValue method would not be bugged :


@Override
public void setValue(D value) {
super.setValue(value);
listView.getSelectionModel().select(value, false);
}

What does happen if value == null?

sven
20 Sep 2010, 4:59 AM
I am going to add a change to roweditor which should fix this exception.

sven
20 Sep 2010, 5:00 AM
I'm wondering if the ListField.setValue method would not be bugged :


@Override
public void setValue(D value) {
super.setValue(value);
listView.getSelectionModel().select(value, false);
}

What does happen if value == null?

Than nothing gets selected because null is not part of the store.