Accessing the Exception in View

2 views
Skip to first unread message

Norman Maurer

unread,
Jul 3, 2009, 2:58:20 PM7/3/09
to gwt-mvc
Hi,

I want to react in the view on Exceptions when trying to access data
in a model. At the moment I use a Wrapper around the Data which is
returned from my rpc calls. I wondered if there is a other way to get
the exception from the View. Here is the wrapper I'm using:
--------------------------------------------------------
public class ModelReturnData<E> {

private Throwable error = null;
private E obj;

public ModelReturnData(Throwable error) {
this.error = error;
}

public ModelReturnData(E obj) {
this.obj = obj;
}

public boolean hasError() {
return error != null;
}

public Throwable getThrowable() {
return error;
}

public E getObject() {
return obj;
}
}

And I use in the model like this:

ublic class LoginModel extends Model<ModelReturnData<IMAPUser>> {

private IMAPServiceAsync imapService = GWT.create(IMAPService.class);

@Override
protected void init() {

}

public void login(final Event<LoginModelData,HupaAction> event) {
LoginModelData data = event.getValue();

imapService.login(data.getUsername(),data.getPassword(),
new AsyncCallback<IMAPUser>() {

public void onFailure(Throwable caught) {
update(new ModelReturnData<IMAPUser>(caught),event);
}

public void onSuccess(IMAPUser
result) {
update(new
ModelReturnData<IMAPUser>(result),event);
}

});
}

}
---------------------------------------------------------------------------------

Any better idea ?

Francois Wauquier

unread,
Jul 27, 2009, 4:05:47 AM7/27/09
to gwt-mvc
Hello

I reopen this post to react to this questions.

You are offering a solution to get an exception from the server in the
view.
But maybe some others would like to get the exception in the
controller,
or in the model itself (which is the simplest one).

Anyway, to get the exception in the view , i could keep the exception
in the model like the value, by adding it in the 'ModelForView'
interface.
http://gwt-mvc.googlecode.com/svn/trunk/gwt-mvc/javadoc/0.2/com/googlecode/gwtmvc/client/ModelForView.html

Change the update method in the model, like your wrapper does (The
model is updated by a value OR an error)
Does an error implies to reset the value to null ? I think both
possibilities must be let to the developer, but the default choice
could be 'yes' ?

The view will receive the value and the error onModelChange
(ModelForView<T> model) .

If you are satisfied with this version, i could add it for the next
0.3 release.

François Wauquier

Reply all
Reply to author
Forward
0 new messages