388 result.navCase = cnc;
389 return result;
390 }
391 }
392 }
393
394 for (int i = 0; i < size; i++) {
395 cnc = (ConfigNavigationCase) caseList.get(i);
396 cncFromAction = cnc.getFromAction();
397 fromOutcome = cnc.getFromOutcome();
398 toViewId = cnc.getToViewId();
399 if ((cncFromAction != null) && (fromOutcome == null)) {
400 if (cncFromAction.equals(fromAction)) {
401 result.viewId = toViewId;
402 result.navCase = cnc;
403 return result;
404 }
405 }
406 }
407
408 for (int i = 0; i < size; i++) {
409 cnc = (ConfigNavigationCase) caseList.get(i);
410 cncFromAction = cnc.getFromAction();
411 fromOutcome = cnc.getFromOutcome();
412 toViewId = cnc.getToViewId();
413 if ((cncFromAction == null) && (fromOutcome == null)) {
414 result.viewId = toViewId;
415 result.navCase = cnc;
416 return result;
417 }
418 }
419
420 return null;
421 }
422
423 /** *//**
424 * @author robin
425 */
426 class CaseStruct {
427
428 /** *//**
429 * Field viewId.
430 */
431 protected String viewId;
432
433 /** *//**
434 * Field navCase.
435 */
436 protected ConfigNavigationCase navCase;
437 }
438
439}
440
来看看其中的关键部分,149行起: UIViewRoot newRoot = null;
if (flag) {
//当检查URL通过时,使用CaseStruct,即faces-config.xml中的配置跳转
newRoot = viewHandler
.createView(context, caseStruct.viewId);
} else {
//未通过URL检查时,直接到权限不足页面或你指定的页面
newRoot = viewHandler.createView(context,
"/backForward.jsp");
}
context.setViewRoot(newRoot);
当然别忘了在faces-config.xml中加入自定义Application Navigation的配置,如下:
1<faces-config>
2 <application>
3 <navigation-handler id="navigationWithAuth">
4 com.***.framework.NavigationHandleWithAuthImpl
5 </navigation-handler>
6 </application>
7
8
9
10
11</faces-config>
注意:
在NavigationHandler中,当发现检查URL权限未能通过时,千万不要直接去修改当前的那个CaseStruts,因为JSF自己会缓存整个跳转的配置,以提高执行效率,请使用viewHandler.createView()来创建一个新CaseStruts,否则会发生跳转不正常的情况。

