论坛首页 Web前端技术论坛

MVP For GWT 系列资料转载一:Quick note on using gwt-presenter’s ActionException

浏览 1110 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2010-03-07   最后修改:2010-03-07
GWT

源文转自:Quick note on using gwt-presenter’s ActionException

 

It seems that the best way to use gwt-presenter’s ActionException is to extend it, as exception chaining using ActionException does not appear to work. Here’s a working example:

package com.roa.common.exception;

import net.customware.gwt.dispatch.shared.ActionException;

public class UserNotLoggedInException extends ActionException
{
	private String loginUrl;

	// Required for GWT-RPC!
	private UserNotLoggedInException()
	{
		super();
	}

	public UserNotLoggedInException(String loginUrl)
	{
		super();
		this.loginUrl = loginUrl;
	}

	public String getLoginUrl()
	{
		return loginUrl;
	}
}
 Extending ActionException is nice because all your handler execute methods already declare it. And this way, in client code, you can use instanceof in your exception handlers without the need for getCause(), checking for null, etc.

 

Thanks to the Apache Hupa mail project for a similar example (InvalidSessionException) that helped me see the light on this! While you’re checking out Hupa, have a look at the HupaCallback class, too. Pretty nifty way to achieve centralized error handling on the client combined with gwt-presenter’s DisplayCallback class.

 

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics