Exception Handle


import org.springframework.webflow.engine.RequestControlContext;
import org.springframework.webflow.engine.support.TransitionExecutingFlowExecutionExceptionHandler;
import org.springframework.webflow.execution.FlowExecutionException;
import org.springframework.webflow.execution.RequestContext;

public class FlowExceptionHandler extends TransitionExecutingFlowExecutionExceptionHandler {

public void handle(FlowExecutionException exception, RequestControlContext context) {
super.handle(exception, context);
exception.printStackTrace();
}

protected void exposeException(RequestContext context, FlowExecutionException exception, Throwable rootCause) {
// note that all Throwables are Serializable so putting them in flash
// scope should not be a problem
context.getFlashScope().put(FLOW_EXECUTION_EXCEPTION_ATTRIBUTE, exception);
context.getFlashScope().put(ROOT_CAUSE_EXCEPTION_ATTRIBUTE, rootCause);

rootCause.printStackTrace();
}
}


context.getFlashScope().put(FLOW_EXECUTION_EXCEPTION_ATTRIBUTE, exception);
context.getFlashScope().put(ROOT_CAUSE_EXCEPTION_ATTRIBUTE, rootCause);

Exception e = (Exception) flowRequestContext.getFlashScope().get("rootCauseException");
//e.printStackTrace(System.out);

StackTraceElement[] stacktraces = e.getStackTrace();

for (int i = 0; i < 4; i++) {
StackTraceElement trace = stacktraces[i];
String className = trace.getClassName();
String fieldName = trace.getFileName();
String metodName = trace.getMethodName();
int linenumber = trace.getLineNumber();
System.out.println("========= trace: " + className + " " + fieldName + " " + metodName + " " + linenumber);
}



<action-state id="exceptionHandle">
<evaluate expression="testBean.handleException(flowRequestContext)" />
<transition on="exception" to="exception"/>
</action-state>

<exception-handler bean="flowExceptionHandler"/>



if (testState instanceof ViewState) {
ViewState viewState = (ViewState) testState;
try {
viewState.getViewFactory().getView(context).render();
} catch (IOException e) {
//Properly handle rendering errors here
}
}



package com.zenius.listener;

import java.util.LinkedList;

import org.springframework.webflow.definition.StateDefinition;
import org.springframework.webflow.engine.ViewState;
import org.springframework.webflow.execution.FlowExecutionListenerAdapter;
import org.springframework.webflow.execution.FlowSession;
import org.springframework.webflow.execution.RequestContext;

public class BackToLastViewStateFlowExecutionListener
extends FlowExecutionListenerAdapter
{

private String viewStatesName = "GLOBAL_BACK_LISTENER_VIEW_STATES";
private String backEventId = "back";

public void setViewStatesName(final String viewStatesName)
{
this.viewStatesName = viewStatesName;
}

public void setBackEventId(final String backEventId)
{
this.backEventId = backEventId;
}

@Override
public void sessionStarted(final RequestContext context,
final FlowSession session)
{
session.getScope().put(viewStatesName, new LinkedList<String>());
}

private LinkedList<String> getViewStates(final RequestContext context)
{
@SuppressWarnings("unchecked")
final LinkedList<String> viewStates =
(LinkedList<String>)context.getFlowScope().get(viewStatesName);

if (viewStates == null)
throw new IllegalStateException("viewStates is null");

return viewStates;
}

@Override
public void stateEntered(final RequestContext context,
final StateDefinition previousState,
final StateDefinition state)
{
// If there's no previous ViewState, there's nothing we can do...
if (!(previousState instanceof ViewState))
return;

// If we're entering the same state (due to a reload or
// binding error), ignore that...
if (previousState.getId().equals(state.getId()))
return;

final LinkedList<String> viewStates = getViewStates(context);

final String previousStateId;

if (context.getLastEvent().getId().equals(backEventId))
{
viewStates.removeLast();
previousStateId = viewStates.isEmpty() ? "" : viewStates.getLast();
}
else
{
previousStateId = previousState.getId();
viewStates.add(previousStateId);
}

context.getFlowScope().put("previousViewStateId", previousStateId);
}

}



[code]
String flowId = exception.getFlowId();
String stateId = exception.getStateId();
Event currentEvent = context.getCurrentEvent();
StateDefinition currentState = context.getCurrentState();
TransitionDefinition currentTransition = context.getCurrentTransition();
State originationgViewState = (State)context.getRequestScope().get("webflow.originatingViewState");
[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值