public static String getOutcomeTargetLinkHref (
FacesContext facesContext, UIOutcomeTarget component) throws IOException
{
String fragment = (String) component.getAttributes().get ("fragment");
String href = component.getOutcome();
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
// The href for an HtmlOutcomeTargetLink is outcome#fragment.
href = ((href == null) ? STR_EMPTY : href.trim());
// Get the correct URL for the outcome.
NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
if (!(nh instanceof ConfigurableNavigationHandler))
{
throw new FacesException("navigation handler must be instance of ConfigurabeNavigationHandler for use h:link or h:button");
}
ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) nh;
//fromAction is null because there
NavigationCase navigationCase = navigationHandler.getNavigationCase(facesContext, null, href);
// when navigation case is null, force the "link" to be rendered as text
if (navigationCase == null)
{
return null;
}
href = navigationCase.getToViewId(facesContext);
if (fragment != null)
{
fragment = fragment.trim();
if (fragment.length() > 0)
{
href += "#" + fragment;
}
}
Map<String, List<String>> parameters = new HashMap<String,List<String>>();
for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
{
UIComponent child = (UIComponent)it.next();
if (child instanceof UIParameter)
{
// check for the disable attribute (since 2.0)
if (((UIParameter) child).isDisable())
{
// ignore this UIParameter and continue
continue;
}
String name = ((UIParameter)child).getName();
Object value = ((UIParameter)child).getValue();
if (parameters.containsKey(name))
{
parameters.get(name).add(value.toString());
}
else
{
ArrayList<String> list = new ArrayList<String>(1);
list.add(value.toString());
parameters.put(name, list);
}
}
}
if (navigationCase.isIncludeViewParams()) {
parameters.putAll (navigationCase.getParameters());
}
// In theory the precedence order to deal with params is this:
// component parameters, navigation-case parameters, view parameters
// getBookmarkableURL deal with this details.
href = viewHandler.getBookmarkableURL(facesContext, href, parameters, navigationCase.isIncludeViewParams() || component.isIncludeViewParams());
return href;
}