throw new FacesException("Navigation handler must be an instance of " +
"ConfigurableNavigationHandler for using h:link or h:button");
}
ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) nh;
// fromAction is null because there is no action method that was called to get the outcome
NavigationCase navigationCase = navigationHandler.getNavigationCase(facesContext, null, outcome);
// when navigation case is null, force the "link" to be rendered as text
if (navigationCase == null) {
return null;
}
// handle URL parameters
Map<String, List<String>> parameters = new HashMap<String, List<String>>();
List<UIParameter> validParams = getValidUIParameterChildren(
facesContext, component.getChildren(), true, false);
for (UIParameter param : validParams) {
String name = param.getName();
Object value = param.getValue();
if (parameters.containsKey(name)) {
parameters.get(name).add(value.toString());
} else {
List<String> list = new ArrayList<String>(1);
list.add(value.toString());
parameters.put(name, list);
}
}
// handle NavigationCase parameters
Map<String, List<String>> navigationCaseParams = navigationCase.getParameters();
if (navigationCaseParams != null) {
parameters.putAll(navigationCaseParams);
}
// In theory the precedence order to deal with params is this:
// component parameters, navigation-case parameters, view parameters
// getBookmarkableURL deal with this details.
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
String href = viewHandler.getBookmarkableURL(facesContext,
navigationCase.getToViewId(facesContext), parameters,
navigationCase.isIncludeViewParams() || component.isIncludeViewParams());
// handle fragment (viewId#fragment)
String fragment = (String) component.getAttributes().get("fragment");
if (fragment != null) {
fragment = fragment.trim();