dev@javaserverfaces.java.net

Re: [179-NavigationImplovements] Seeking review

From: Roger Kitain <Roger.Kitain_at_Sun.COM>
Date: Fri, 30 Jan 2009 16:21:30 -0500

r=rogerk

Ed Burns wrote:
> Issue: 179 implicit navigation
>
> This was requested by JBoss during the specification of
> 487-BookmarkableLinks.
>
>
> SECTION: Modified Files
> ----------------------------
> M jsf-api/src/javax/faces/application/NavigationCase.java
>
> - add get{Action,Resource}URL(). We'll need it this way for portlets.
>
> M jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java
>
> - Add NavigationCaseImpl that does the right thing for
> get{Action,Resource}URL().
>
> M jsf-ri/src/com/sun/faces/config/processor/NavigationConfigProcessor.java
>
> - Make sure to use the new NavigationCaseImpl.
>
> M jsf-ri/systest-per-webapp/implicit-navigation/web/page01.xhtml
>
> - Test it out.
>
>
> SECTION: Diffs
> ----------------------------
> Index: jsf-api/src/javax/faces/application/NavigationCase.java
> ===================================================================
> --- jsf-api/src/javax/faces/application/NavigationCase.java (revision 6312)
> +++ jsf-api/src/javax/faces/application/NavigationCase.java (working copy)
> @@ -40,6 +40,9 @@
>
> package javax.faces.application;
>
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
> /**
> * <p class="changed_added_2_0"><strong>NavigationCase</strong>
> * represents a <code>&lt;navigation-case&gt;</code> in the navigation
> @@ -96,8 +99,43 @@
>
> // ---------------------------------------------------------- Public Methods
>
> + /**
> + * <p class="changed_added_2_0">Construct an absolute URL to this
> + * <code>NavigationCase</code> instance using {_at_link
> + * javax.faces.context.ExternalContext#encodeActionURL} on the path
> + * portion of the url. The default implementation of this method
> + * return <code>null</code>. Implementations must override this
> + * method to perform the correct action as specified.</p>
> + *
> + * @since 2.0
> + *
> + * @throws MalformedURLException if the process of constructing the
> + * URL causes this exception to be thrown.
> + */
>
> + public URL getActionURL() throws MalformedURLException {
> + return null;
> + }
> +
> /**
> + * <p class="changed_added_2_0">Construct an absolute URL to this
> + * <code>NavigationCase</code> instance using {_at_link
> + * javax.faces.context.ExternalContext#encodeResourceURL} on the path
> + * portion of the url. The default implementation of this method
> + * return <code>null</code>. Implementations must override this
> + * method to perform the correct action as specified.</p>
> + *
> + * @since 2.0
> + *
> + * @throws MalformedURLException if the process of constructing the
> + * URL causes this exception to be thrown.
> + */
> +
> + public URL getResourceURL() throws MalformedURLException {
> + return null;
> + }
> +
> + /**
> * <p class="changed_added_2_0">Return the
> * <code>&lt;from-view-id&gt;</code> of the
> * <code>&lt;navigation-rule&gt;</code> inside which this
> Index: jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java
> ===================================================================
> --- jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java (revision 6312)
> +++ jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java (working copy)
> @@ -40,6 +40,7 @@
>
> package com.sun.faces.application;
>
> +import java.net.URL;
> import javax.faces.FacesException;
> import javax.faces.FactoryFinder;
> import javax.faces.application.ApplicationFactory;
> @@ -58,6 +59,7 @@
> import com.sun.faces.util.MessageUtils;
> import com.sun.faces.util.Util;
> import com.sun.faces.util.FacesLogger;
> +import java.net.MalformedURLException;
> import javax.faces.application.ConfigurableNavigationHandler;
> import javax.faces.application.FacesMessage;
>
> @@ -464,7 +466,7 @@
> viewIdToTest = viewIdToTest + outcome.substring(questionMark);
> }
> caseStruct.viewId = viewIdToTest;
> - caseStruct.navCase = new NavigationCase(currentViewId,
> + caseStruct.navCase = new NavigationCaseImpl(currentViewId,
> fromAction, outcome, viewIdToTest, isRedirect);
> }
>
> @@ -532,5 +534,58 @@
> String viewId;
> NavigationCase navCase;
> }
> +
> + public static class NavigationCaseImpl extends NavigationCase {
>
> + public NavigationCaseImpl(String fromViewId, String fromAction, String fromOutcome, String toViewId, boolean redirect) {
> + super(fromViewId, fromAction, fromOutcome, toViewId, redirect);
> + }
> +
> + private String getFile(FacesContext context,
> + ExternalContext extContext) {
> + String
> + file = extContext.getRequestContextPath(),
> + mapping = Util.getFacesMapping(context);
> +
> + if (Util.isPrefixMapped(mapping)) {
> + file = file + mapping + this.getToViewId();
> + } else {
> + String viewId = this.getToViewId();
> + int i = 0;
> + if (-1 != (i = viewId.lastIndexOf("."))) {
> + viewId = viewId.substring(0, i) + mapping;
> + }
> + file = file + viewId;
> + }
> + return file;
> + }
> +
> + @Override
> + public URL getResourceURL() throws MalformedURLException {
> + FacesContext context = FacesContext.getCurrentInstance();
> + ExternalContext extContext = context.getExternalContext();
> + URL result = null;
> + result = new URL(extContext.getRequestScheme(),
> + extContext.getRequestServerName(),
> + extContext.getRequestServerPort(),
> + extContext.encodeResourceURL(getFile(context, extContext)));
> +
> + return result;
> + }
> +
> + @Override
> + public URL getActionURL() throws MalformedURLException {
> + FacesContext context = FacesContext.getCurrentInstance();
> + ExternalContext extContext = context.getExternalContext();
> + URL result = null;
> + result = new URL(extContext.getRequestScheme(),
> + extContext.getRequestServerName(),
> + extContext.getRequestServerPort(),
> + extContext.encodeActionURL(getFile(context, extContext)));
> +
> + return result;
> + }
> +
> + }
> +
> }
> Index: jsf-ri/src/com/sun/faces/config/processor/NavigationConfigProcessor.java
> ===================================================================
> --- jsf-ri/src/com/sun/faces/config/processor/NavigationConfigProcessor.java (revision 6312)
> +++ jsf-ri/src/com/sun/faces/config/processor/NavigationConfigProcessor.java (working copy)
> @@ -41,6 +41,7 @@
> package com.sun.faces.config.processor;
>
> import com.sun.faces.application.ApplicationAssociate;
> +import com.sun.faces.application.NavigationHandlerImpl.NavigationCaseImpl;
> import javax.faces.application.NavigationCase;
> import com.sun.faces.util.FacesLogger;
> import org.w3c.dom.Document;
> @@ -229,7 +230,7 @@
> }
>
> NavigationCase cnc =
> - new NavigationCase(fromViewId,
> + new NavigationCaseImpl(fromViewId,
> action,
> outcome,
> toViewId,
> Index: jsf-ri/systest-per-webapp/implicit-navigation/web/page01.xhtml
> ===================================================================
> --- jsf-ri/systest-per-webapp/implicit-navigation/web/page01.xhtml (revision 6312)
> +++ jsf-ri/systest-per-webapp/implicit-navigation/web/page01.xhtml (working copy)
> @@ -11,6 +11,12 @@
>
> <h:form prependId="false">
>
> + <p>Action URL to this page: <h:outputText
> + value="#{implicitNavigationBean.currentActionUrl}" /></p>
> +
> + <p>Resource URL to this page: <h:outputText
> + value="#{implicitNavigationBean.currentResourceUrl}" /></p>
> +
> <p>[page01] <h:commandButton value="page02" action="/page02" /></p>
>
> </h:form>
>
>
>
>