Teedaを使って開発していると、内部エラーが発生したときに、エラーメッセージ表示用のページにリダイレクトされてしまう。
が、これだと、エラー修正したあとイチイチアドレスバーに、エラーになった画面のURLを入力しなおさないといけないので面倒くさい。
#デザイナーさんが作ってきたHTMLをベースにページを作ってるときなんか、SAXエラーの度にエラー画面に遷移しちゃって結構大変なのです。
というわけで、Teedaのエラーハンドラーをちょっと変更したクラスを作って、リダイレクトしないようにしてみました。
これで、不具合を修正したらブラウザのリロードするだけで確認!という
良い感じの動作になりました。
というわけで、その手順を貼り付けます。
手順は以下
1.エラーハンドラー用クラスを作る。
2.teedaErrorPage.dicon のエラーハンドラーの記述を置き換える。
具体的に必要なコードは以下
#半角の<> は、イザのブログエディタだとうまく扱えないっぽいので、全角に置き換えています。
#コピペする場合は注意・・・。
■ 今回作ったエラーハンドラークラスのソース
package jp.co.mekefactory.sample.helper;
import java.io.IOException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletResponse;
import org.seasar.framework.log.Logger;
import org.seasar.framework.util.AssertionUtil;
import org.seasar.teeda.core.util.ServletErrorPageManagerImpl;
import org.seasar.teeda.core.util.ServletExternalContextUtil;
public class BaseErrorPageManager extends ServletErrorPageManagerImpl {
private static final Logger logger = Logger.getLogger(BaseErrorPageManager.class);
public boolean handleException(Throwable exception, FacesContext context, ExternalContext extContext) throws IOException {
AssertionUtil.assertNotNull("exception", exception);
if (logger.isDebugEnabled()) {
logger.debug(exception.getMessage(), exception);
}
ServletResponse response = ServletExternalContextUtil.getResponse(extContext);
response.setCharacterEncoding("UTF-8");
StringBuffer buffer = new StringBuffer();
buffer.append("<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>");
buffer.append("<body style="FONT-FAMILY: MS Pゴシック,Osaka,Hiragino Kaku Gothic Pro,Verdana,Helvetica,sans-serif">");
Throwable curException = exception;
while(curException != null){
buffer.append("<br>");
buffer.append("<B style="font-size:11pt" >").append(curException.getClass().getName()).append("</B><br>");
buffer.append("<B style="font-size:10pt" >").append(curException.getMessage()).append("</B><br>");
StackTraceElement[] elements = curException.getStackTrace();
for(int i = 0; i < elements.length; i++){
buffer.append("<span style="font-size:9pt">").append(elements[i]).append("</span><br>");
}
curException = curException.getCause();
}
buffer.append("</body></html>");
response.getWriter().write(buffer.toString());
return true;
}
}
■ teedaErrorPage.dicon の内容
<components namespace="teedaErrorPage" >
<component class="jp.co.mekefactory.sample.helper.BaseErrorPageManager">
</component>
</components>
![ドキドキしよう!!ワクワクしよう!!meet-me meet-meとは? [meet-me(ミートミー)は東京を忠実に再現した3D仮想空間です!]](/images/meetme/blog/blog_top.jpg)
by tmoro
Hadoopがジワジワきてるかもし…