You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2007/03/02 21:02:52 UTC
svn commit: r513922 - in
/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion: jsf/
lib/ urlParamNav/
Author: imario
Date: Fri Mar 2 12:02:51 2007
New Revision: 513922
URL: http://svn.apache.org/viewvc?view=rev&rev=513922
Log:
added UrlParameterNavigationHandler, this NavigationHandler allows you
to configure navigation cases with valuebindings.
Since I do not know how this solution interfere with other frameworks
its disable by default, the user has to add a NavigationHandler and
ViewHandler manually to the faces-config.xml
Added:
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/ExternalContextWrapper.java
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/FacesContextWrapper.java
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterNavigationHandler.java
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterViewHandler.java
Removed:
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/jsf/
myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/lib/
Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/ExternalContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/ExternalContextWrapper.java?view=auto&rev=513922
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/ExternalContextWrapper.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/ExternalContextWrapper.java Fri Mar 2 12:02:51 2007
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.fusion.urlParamNav;
+
+import javax.faces.context.ExternalContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Locale;
+import java.util.Iterator;
+import java.util.Set;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.security.Principal;
+
+public class ExternalContextWrapper extends ExternalContext
+{
+ private final ExternalContext externalContext;
+
+ public ExternalContextWrapper(ExternalContext externalContext)
+ {
+ this.externalContext = externalContext;
+ }
+
+ public void dispatch(String path)
+ throws IOException
+ {
+ externalContext.dispatch(path);
+ }
+
+ public String encodeActionURL(String url)
+ {
+ return externalContext.encodeActionURL(url);
+ }
+
+ public String encodeNamespace(String name)
+ {
+ return externalContext.encodeNamespace(name);
+ }
+
+ public String encodeResourceURL(String url)
+ {
+ return externalContext.encodeResourceURL(url);
+ }
+
+ public Map getApplicationMap()
+ {
+ return externalContext.getApplicationMap();
+ }
+
+ public String getAuthType()
+ {
+ return externalContext.getAuthType();
+ }
+
+ public Object getContext()
+ {
+ return externalContext.getContext();
+ }
+
+ public String getInitParameter(String name)
+ {
+ return externalContext.getInitParameter(name);
+ }
+
+ public Map getInitParameterMap()
+ {
+ return externalContext.getInitParameterMap();
+ }
+
+ public String getRemoteUser()
+ {
+ return externalContext.getRemoteUser();
+ }
+
+ public Object getRequest()
+ {
+ return externalContext.getRequest();
+ }
+
+ public String getRequestContextPath()
+ {
+ return externalContext.getRequestContextPath();
+ }
+
+ public Map getRequestCookieMap()
+ {
+ return externalContext.getRequestCookieMap();
+ }
+
+ public Map getRequestHeaderMap()
+ {
+ return externalContext.getRequestHeaderMap();
+ }
+
+ public Map getRequestHeaderValuesMap()
+ {
+ return externalContext.getRequestHeaderValuesMap();
+ }
+
+ public Locale getRequestLocale()
+ {
+ return externalContext.getRequestLocale();
+ }
+
+ public Iterator getRequestLocales()
+ {
+ return externalContext.getRequestLocales();
+ }
+
+ public Map getRequestMap()
+ {
+ return externalContext.getRequestMap();
+ }
+
+ public Map getRequestParameterMap()
+ {
+ return externalContext.getRequestParameterMap();
+ }
+
+ public Iterator getRequestParameterNames()
+ {
+ return externalContext.getRequestParameterNames();
+ }
+
+ public Map getRequestParameterValuesMap()
+ {
+ return externalContext.getRequestParameterValuesMap();
+ }
+
+ public String getRequestPathInfo()
+ {
+ return externalContext.getRequestPathInfo();
+ }
+
+ public String getRequestServletPath()
+ {
+ return externalContext.getRequestServletPath();
+ }
+
+ public URL getResource(String path)
+ throws MalformedURLException
+ {
+ return externalContext.getResource(path);
+ }
+
+ public InputStream getResourceAsStream(String path)
+ {
+ return externalContext.getResourceAsStream(path);
+ }
+
+ public Set getResourcePaths(String path)
+ {
+ return externalContext.getResourcePaths(path);
+ }
+
+ public Object getResponse()
+ {
+ return externalContext.getResponse();
+ }
+
+ public Object getSession(boolean create)
+ {
+ return externalContext.getSession(create);
+ }
+
+ public Map getSessionMap()
+ {
+ return externalContext.getSessionMap();
+ }
+
+ public Principal getUserPrincipal()
+ {
+ return externalContext.getUserPrincipal();
+ }
+
+ public boolean isUserInRole(String role)
+ {
+ return externalContext.isUserInRole(role);
+ }
+
+ public void log(String message)
+ {
+ externalContext.log(message);
+ }
+
+ public void log(String message, Throwable exception)
+ {
+ externalContext.log(message, exception);
+ }
+
+ public void redirect(String url)
+ throws IOException
+ {
+ externalContext.redirect(url);
+ }
+}
Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/FacesContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/FacesContextWrapper.java?view=auto&rev=513922
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/FacesContextWrapper.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/FacesContextWrapper.java Fri Mar 2 12:02:51 2007
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.fusion.urlParamNav;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.render.RenderKit;
+import javax.faces.component.UIViewRoot;
+import java.util.Iterator;
+
+public class FacesContextWrapper extends FacesContext
+{
+ private final FacesContext context;
+
+ public FacesContextWrapper(FacesContext context)
+ {
+ this.context = context;
+ }
+
+ public Application getApplication()
+ {
+ return context.getApplication();
+ }
+
+ public Iterator getClientIdsWithMessages()
+ {
+ return context.getClientIdsWithMessages();
+ }
+
+ public ExternalContext getExternalContext()
+ {
+ return context.getExternalContext();
+ }
+
+ public FacesMessage.Severity getMaximumSeverity()
+ {
+ return context.getMaximumSeverity();
+ }
+
+ public Iterator getMessages()
+ {
+ return context.getMessages();
+ }
+
+ public Iterator getMessages(String clientId)
+ {
+ return context.getMessages(clientId);
+ }
+
+ public RenderKit getRenderKit()
+ {
+ return context.getRenderKit();
+ }
+
+ public boolean getRenderResponse()
+ {
+ return context.getRenderResponse();
+ }
+
+ public boolean getResponseComplete()
+ {
+ return context.getResponseComplete();
+ }
+
+ public ResponseStream getResponseStream()
+ {
+ return context.getResponseStream();
+ }
+
+ public void setResponseStream(ResponseStream responseStream)
+ {
+ context.setResponseStream(responseStream);
+ }
+
+ public ResponseWriter getResponseWriter()
+ {
+ return context.getResponseWriter();
+ }
+
+ public void setResponseWriter(ResponseWriter responseWriter)
+ {
+ context.setResponseWriter(responseWriter);
+ }
+
+ public UIViewRoot getViewRoot()
+ {
+ return context.getViewRoot();
+ }
+
+ public void setViewRoot(UIViewRoot root)
+ {
+ context.setViewRoot(root);
+ }
+
+ public void addMessage(String clientId, FacesMessage message)
+ {
+ context.addMessage(clientId, message);
+ }
+
+ public void release()
+ {
+ context.release();
+ }
+
+ public void renderResponse()
+ {
+ context.renderResponse();
+ }
+
+ public void responseComplete()
+ {
+ context.responseComplete();
+ }
+}
Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterNavigationHandler.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterNavigationHandler.java?view=auto&rev=513922
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterNavigationHandler.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterNavigationHandler.java Fri Mar 2 12:02:51 2007
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.fusion.urlParamNav;
+
+import javax.faces.application.NavigationHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import java.io.IOException;
+
+/**
+ * <p>
+ * This navigation handler replace all value bindings from the url a redirect will be issued to.
+ * </p>
+ * <p>
+ * Since we do not know how this interfere with other framweworks you have to enable it
+ * for your application manually.<br />
+ * So to make this handler work you have to:
+ * <ul>
+ * <li>add this navigation handler to your faces-config.xml</li>
+ * <li>add the {@link UrlParameterViewHandler} to your faces-config.xml</li>
+ * <li>configure the navigation case to use <redirect/> flag.<br />
+ * This is quite natural as without redirect there are not url parameter</li>
+ * </ul>
+ * </p>
+ */
+public class UrlParameterNavigationHandler extends NavigationHandler
+{
+ private final NavigationHandler original;
+
+ public UrlParameterNavigationHandler(final NavigationHandler original)
+ {
+ this.original = original;
+ }
+
+ public void handleNavigation(final FacesContext context, String fromAction, String outcome)
+ {
+ original.handleNavigation(new FacesContextWrapper(context)
+ {
+ public ExternalContext getExternalContext()
+ {
+ return new ExternalContextWrapper(super.getExternalContext())
+ {
+ public void redirect(String url) throws IOException
+ {
+ super.redirect(interceptRedirect(context, url));
+ }
+ };
+ }
+ }, fromAction, outcome);
+ }
+
+ protected String interceptRedirect(FacesContext context, String url)
+ {
+ int pos = url.indexOf("#{");
+ if (pos > -1 && url.indexOf("}", pos) > -1)
+ {
+ ValueBinding vb = context.getApplication().createValueBinding(url);
+ return (String) vb.getValue(context);
+ }
+
+ return url;
+ }
+}
Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterViewHandler.java?view=auto&rev=513922
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterViewHandler.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/urlParamNav/UrlParameterViewHandler.java Fri Mar 2 12:02:51 2007
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2007, Your Corporation. All Rights Reserved.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.fusion.urlParamNav;
+
+import javax.faces.FacesException;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+import java.util.Locale;
+
+/**
+ * <p/>
+ * This view handler helps to preserve any url parameter you configured in your navigation
+ * </p>
+ *
+ * @see org.apache.myfaces.fusion.urlParamNav.UrlParameterNavigationHandler
+ */
+public class UrlParameterViewHandler extends ViewHandler
+{
+ private final ViewHandler original;
+
+ public UrlParameterViewHandler(final ViewHandler original)
+ {
+ this.original = original;
+ }
+
+ public Locale calculateLocale(FacesContext context)
+ {
+ return original.calculateLocale(context);
+ }
+
+ public String calculateRenderKitId(FacesContext context)
+ {
+ return original.calculateRenderKitId(context);
+ }
+
+ public UIViewRoot createView(FacesContext context, String viewId)
+ {
+ return original.createView(context, viewId);
+ }
+
+ public String getActionURL(FacesContext context, String viewId)
+ {
+ if (viewId != null)
+ {
+ int pos = viewId.indexOf('?');
+ if (pos > -1)
+ {
+ String realViewId = viewId.substring(0, pos);
+ String params = viewId.substring(pos);
+
+ return original.getActionURL(context, realViewId) + params;
+ }
+ }
+ return original.getActionURL(context, viewId);
+ }
+
+ public String getResourceURL(FacesContext context, String path)
+ {
+ return original.getResourceURL(context, path);
+ }
+
+ public void renderView(FacesContext context, UIViewRoot viewToRender)
+ throws IOException, FacesException
+ {
+ original.renderView(context, viewToRender);
+ }
+
+ public UIViewRoot restoreView(FacesContext context, String viewId)
+ {
+ return original.restoreView(context, viewId);
+ }
+
+ public void writeState(FacesContext context)
+ throws IOException
+ {
+ original.writeState(context);
+ }
+}
\ No newline at end of file