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 2006/06/20 22:11:39 UTC
svn commit: r415789 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/conversation/
core/src/main/resources-facesconfig/META-INF/ core/src/main/tld/
core/src/main/tld/entities/ examples/src/main/webapp/conversation/
Author: imario
Date: Tue Jun 20 13:11:38 2006
New Revision: 415789
URL: http://svn.apache.org/viewvc?rev=415789&view=rev
Log:
ensureConversation: check if a named conversation is running, else redirect to another view
endConversation: errorOutcome, outcome to use in case of an exception
ConversationMessager: interface to deal with messages for the user, impl DefaultConversationMessager
Tests needed
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml (with props)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationTag.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java
myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/end_conversation_attributes.xml
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardFinish.jsp
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage3.jsp
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java Tue Jun 20 13:11:38 2006
@@ -166,7 +166,6 @@
/**
* Get the current conversation. The current conversation is the one last seen by the startConversation tag.
- * @return
*/
public Conversation getCurrentConversation()
{
@@ -177,12 +176,24 @@
/**
* see if there is a conversation
*/
- public boolean hasConversation()
+ public boolean hasConversations()
{
synchronized (mutex)
{
touch();
return conversations.size() > 0;
+ }
+ }
+
+ /**
+ * check if the given conversation exists
+ */
+ public boolean hasConversation(String name)
+ {
+ synchronized (mutex)
+ {
+ touch();
+ return conversations.get(name) != null;
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java Tue Jun 20 13:11:38 2006
@@ -41,14 +41,18 @@
public final static String CONVERSATION_CONTEXT_PARAM = "conversationContext";
private final static String INIT_PERSISTENCE_MANAGER_FACOTRY = "org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY";
+ private final static String INIT_MESSAGER = "org.apache.myfaces.conversation.MESSAGER";
+
private final static String CONVERSATION_MANAGER_KEY = "org.apache.myfaces.ConversationManager";
private final static String CONVERSATION_CONTEXT_REQ = "org.apache.myfaces.ConversationManager.conversationContext";
private static long NEXT_CONVERSATION_CONTEXT = 1;
private PersistenceManagerFactory persistenceManagerFactory;
+ private ConversationMessager conversationMessager;
private final Map conversationContexts = new HashMap();
+
// private final List registeredEndConversations = new ArrayList(10);
private class ContextWiperThread extends Thread
@@ -109,10 +113,9 @@
{
throw new IllegalStateException("ConversationServletFilter not called. Please configure the filter org.apache.myfaces.custom.conversation.ConversationServletFilter in your web.xml to cover your faces requests.");
}
-
- // create manager
- conversationManager = new ConversationManager();
-
+
+ conversationManager = createConversationManager();
+
// initialize environmental systems
RequestParameterProviderManager.getInstance(context).register(new ConversationRequestParameterProvider());
@@ -123,6 +126,19 @@
return conversationManager;
}
+ protected static ConversationManager createConversationManager()
+ {
+ ConversationManager conversationManager;
+
+ // create manager
+ conversationManager = new ConversationManager();
+
+ // initialize the messager
+ conversationManager.createMessager();
+
+ return conversationManager;
+ }
+
/**
* Get the conversation manager from the http session. This will <b>not</b> create a conversation manager if none exists.
*/
@@ -231,7 +247,7 @@
/**
* Start a conversation
- * @see ConversationContext#startConversation(String)
+ * @see ConversationContext#startConversation(String, boolean)
*/
public void startConversation(String name, boolean persistence)
{
@@ -252,7 +268,7 @@
{
conversationContext.endConversation(name);
- if (!conversationContext.hasConversation())
+ if (!conversationContext.hasConversations())
{
destroyConversationContext(conversationContextId);
}
@@ -275,6 +291,19 @@
}
/**
+ * check if the given conversation is active
+ */
+ public boolean hasConversation(String name)
+ {
+ ConversationContext conversationContext = getConversationContext();
+ if (conversationContext == null)
+ {
+ return false;
+ }
+ return conversationContext.hasConversation(name);
+ }
+
+ /**
* Get the current conversation context.
* @return null if there is no context active
*/
@@ -340,6 +369,49 @@
}
/**
+ * Get the Messager used to inform the user about anomalies.<br />
+ * The factory can be configured in your web.xml using the init parameter named
+ * <code>org.apache.myfaces.conversation.MESSAGER</code>
+ */
+ protected ConversationMessager getMessager()
+ {
+ return conversationMessager;
+ }
+
+ /**
+ * Create the Messager used to inform the user about anomalies.<br />
+ * The factory can be configured in your web.xml using the init parameter named
+ * <code>org.apache.myfaces.conversation.MESSAGER</code>
+ */
+ protected void createMessager()
+ {
+ String conversationMessagerName = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(INIT_MESSAGER);
+ if (conversationMessagerName == null)
+ {
+ conversationMessager = new DefaultConversationMessager();
+ }
+ else
+ {
+ try
+ {
+ conversationMessager = (ConversationMessager) ClassUtils.classForName(conversationMessagerName).newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new FacesException("error creating messager: " + conversationMessagerName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new FacesException("error creating messager: " + conversationMessagerName, e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new FacesException("error creating messager: " + conversationMessagerName, e);
+ }
+ }
+ }
+
+ /**
* Get the persistenceManagerFactory.<br />
* The factory can be configured in your web.xml using the init parameter named
* <code>org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY</code>
@@ -348,7 +420,7 @@
{
if (persistenceManagerFactory == null)
{
- String persistenceManagerFactoryName = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("INIT_PERSISTENCE_MANAGER_FACOTRY");
+ String persistenceManagerFactoryName = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(INIT_PERSISTENCE_MANAGER_FACOTRY);
if (persistenceManagerFactoryName == null)
{
throw new IllegalArgumentException("please configure '" + INIT_PERSISTENCE_MANAGER_FACOTRY + "' in your web.xml");
@@ -370,7 +442,7 @@
throw new FacesException("error creating persistenceManagerFactory named: " + persistenceManagerFactoryName, e);
}
}
-
+
return persistenceManagerFactory;
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java?rev=415789&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java Tue Jun 20 13:11:38 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.conversation;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * methods required to inform the user about some anomalies
+ *
+ * @author imario@apache.org
+ */
+public interface ConversationMessager
+{
+ /**
+ * exception happened e.g. during endConversation action
+ */
+ public void setConversationException(FacesContext context, Throwable t);
+
+ /**
+ * message about a not active conversation (close before the redirect)
+ */
+ public void setConversationNotActive(FacesContext context, String name);
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationMessager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java?rev=415789&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java Tue Jun 20 13:11:38 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.conversation;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * methods required to inform the user about some anomalies
+ *
+ * @author imario@apache.org
+ */
+public class DefaultConversationMessager implements ConversationMessager
+{
+ public void setConversationException(FacesContext context, Throwable t)
+ {
+ context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, t.getLocalizedMessage(), getThrowableText(t)));
+ }
+
+ public void setConversationNotActive(FacesContext context, String name)
+ {
+ String message = "Conversation not active";
+ String messageDtl = "Conversation not active. Please start over. (Conversation Name:" + name + ")";
+
+ context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, message, messageDtl));
+ }
+
+ protected String getThrowableText(Throwable t)
+ {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ pw.close();
+ return sw.toString();
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/DefaultConversationMessager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java Tue Jun 20 13:11:38 2006
@@ -15,19 +15,18 @@
*/
package org.apache.myfaces.custom.conversation;
-import java.util.Collection;
-import java.util.Set;
-
import javax.faces.component.StateHolder;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
import javax.faces.el.MethodNotFoundException;
+import javax.faces.FacesException;
+import java.util.Collection;
/**
* a facade for the original method binding to deal with end conversation conditions
- *
+ *
* @author imario@apache.org
*/
public class EndConversationMethodBindingFacade extends MethodBinding implements StateHolder
@@ -35,20 +34,22 @@
private MethodBinding original;
private String conversationName;
private Collection onOutcomes;
-
- private boolean _transient = false;
+ private String errorOutcome;
- public EndConversationMethodBindingFacade()
- {
- }
-
- public EndConversationMethodBindingFacade(String conversation, Collection onOutcomes, MethodBinding original)
+ private boolean _transient = false;
+
+ public EndConversationMethodBindingFacade()
+ {
+ }
+
+ public EndConversationMethodBindingFacade(String conversation, Collection onOutcomes, MethodBinding original, String errorOutcome)
{
this.original = original;
this.conversationName = conversation;
this.onOutcomes = onOutcomes;
+ this.errorOutcome = errorOutcome;
}
-
+
public String getConversationName()
{
return conversationName;
@@ -84,6 +85,20 @@
}
ok = true;
}
+ catch (Throwable t)
+ {
+ if (errorOutcome != null)
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance(context);
+ conversationManager.getMessager().setConversationException(context, t);
+
+ returnValue = errorOutcome;
+ }
+ else
+ {
+ throw new FacesException(t);
+ }
+ }
finally
{
boolean end = true;
@@ -94,13 +109,13 @@
end = onOutcomes.contains(returnValue);
}
}
-
+
if (end)
{
ConversationManager conversationManager = ConversationManager.getInstance(context);
conversationManager.endConversation(getConversationName());
}
- }
+ }
return returnValue;
}
@@ -108,7 +123,7 @@
{
_transient = newTransientValue;
}
-
+
public boolean isTransient()
{
return _transient;
@@ -117,19 +132,21 @@
public void restoreState(FacesContext context, Object states)
{
Object[] state = (Object[]) states;
-
+
original = (MethodBinding) UIComponentBase.restoreAttachedState(context, state[0]);
conversationName = (String) state[1];
onOutcomes = (Collection) state[2];
+ errorOutcome = (String) state[3];
}
public Object saveState(FacesContext context)
{
return new Object[]
- {
+ {
UIComponentBase.saveAttachedState(context, original),
conversationName,
- onOutcomes
- };
+ onOutcomes,
+ errorOutcome
+ };
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationTag.java?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationTag.java Tue Jun 20 13:11:38 2006
@@ -25,6 +25,7 @@
public class EndConversationTag extends AbstractConversationTag
{
private String onOutcome;
+ private String errorOutcome;
public String getComponentType()
{
@@ -35,6 +36,7 @@
{
super.setProperties(component);
setStringProperty(component, "onOutcome", getOnOutcome());
+ setStringProperty(component, "errorOutcome", getErrorOutcome());
}
public String getOnOutcome()
@@ -45,5 +47,15 @@
public void setOnOutcome(String onOutcome)
{
this.onOutcome = onOutcome;
+ }
+
+ public String getErrorOutcome()
+ {
+ return errorOutcome;
+ }
+
+ public void setErrorOutcome(String errorOutcome)
+ {
+ this.errorOutcome = errorOutcome;
}
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java?rev=415789&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java Tue Jun 20 13:11:38 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.conversation;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * Checks if a conversation is active, else redirects to another view
+ *
+ * @author imario@apache.org
+ */
+public class EnsureConversationTag extends AbstractConversationTag
+{
+ private String redirectTo;
+
+ public String getComponentType()
+ {
+ return UIEnsureConversation.COMPONENT_TYPE;
+ }
+
+ protected void setProperties(UIComponent component)
+ {
+ super.setProperties(component);
+ setStringProperty(component, "redirectTo", getRedirectTo());
+ }
+
+ public String getRedirectTo()
+ {
+ return redirectTo;
+ }
+
+ public void setRedirectTo(String redirectTo)
+ {
+ this.redirectTo = redirectTo;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEndConversation.java Tue Jun 20 13:11:38 2006
@@ -15,31 +15,31 @@
*/
package org.apache.myfaces.custom.conversation;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
+import org.apache.myfaces.shared_tomahawk.util.StringUtils;
import javax.faces.component.UICommand;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
-
-import org.apache.myfaces.shared_tomahawk.util.StringUtils;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
/**
* end a conversation
- *
+ *
* @author imario@apache.org
*/
public class UIEndConversation extends AbstractConversationComponent
{
- public static final String COMPONENT_TYPE = "org.apache.myfaces.EndConversation";
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.EndConversation";
+
+ private String onOutcome;
+ private String errorOutcome;
- private String onOutcome;
-
- private boolean inited = false;
+ private boolean inited = false;
- /*
+ /*
public static class ConversationEndAction extends AbstractConversationActionListener
{
public void doConversationAction(AbstractConversationComponent abstractConversationComponent)
@@ -48,11 +48,11 @@
}
}
*/
-
- public void encodeBegin(FacesContext context) throws IOException
+
+ public void encodeBegin(FacesContext context) throws IOException
{
super.encodeBegin(context);
-
+
UICommand command = ConversationUtils.findParentCommand(this);
if (command != null)
{
@@ -64,7 +64,7 @@
command.addActionListener(actionListener);
*/
MethodBinding original = command.getAction();
- command.setAction(new EndConversationMethodBindingFacade(getName(), getOnOutcomes(), original));
+ command.setAction(new EndConversationMethodBindingFacade(getName(), getOnOutcomes(), original, getErrorOutcome()));
inited = true;
}
}
@@ -82,7 +82,7 @@
{
return null;
}
-
+
return Arrays.asList(StringUtils.trim(StringUtils.splitShortString(onOutcome, ',')));
}
@@ -92,26 +92,28 @@
super.restoreState(context, states[0]);
inited = ((Boolean) states[1]).booleanValue();
onOutcome = (String) states[2];
+ errorOutcome = (String) states[2];
}
public Object saveState(FacesContext context)
{
return new Object[]
- {
+ {
super.saveState(context),
- inited?Boolean.TRUE:Boolean.FALSE,
- onOutcome
- };
+ inited ? Boolean.TRUE : Boolean.FALSE,
+ onOutcome,
+ errorOutcome
+ };
}
public String getOnOutcome()
{
- if (onOutcome!= null)
+ if (onOutcome != null)
{
return onOutcome;
}
ValueBinding vb = getValueBinding("onOutcome");
- if( vb == null )
+ if (vb == null)
{
return null;
}
@@ -121,5 +123,24 @@
public void setOnOutcome(String onOutcome)
{
this.onOutcome = onOutcome;
+ }
+
+ public String getErrorOutcome()
+ {
+ if (errorOutcome != null)
+ {
+ return errorOutcome;
+ }
+ ValueBinding vb = getValueBinding("errorOutcome");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (String) vb.getValue(getFacesContext());
+ }
+
+ public void setErrorOutcome(String errorOutcome)
+ {
+ this.errorOutcome = errorOutcome;
}
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java?rev=415789&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java Tue Jun 20 13:11:38 2006
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.conversation;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * <p>
+ * check if a conversation is active.
+ * </p>
+ * <p>
+ * The way this is done here is sub-optimal, once we are on jsf 1.2 it should be possible to
+ * check this before ANY rendering - and maybe to invoke a navigation then
+ * </p>
+ *
+ * @author imario@apache.org
+ */
+public class UIEnsureConversation extends AbstractConversationComponent
+{
+ private final static Log log = LogFactory.getLog(UIEnsureConversation.class);
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.EnsureConversation";
+
+ private String redirectTo;
+
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ super.encodeBegin(context);
+
+ checkConversation(context, getName());
+ }
+
+ public void decode(FacesContext context)
+ {
+ super.decode(context);
+
+ try
+ {
+ checkConversation(context, getName());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object[] states = (Object[]) state;
+
+ super.restoreState(context, states[0]);
+ redirectTo = (String) states[1];
+ }
+
+ public Object saveState(FacesContext context)
+ {
+ return new Object[]
+ {
+ super.saveState(context),
+ redirectTo
+ };
+ }
+
+ protected void checkConversation(FacesContext context, String name) throws IOException
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance();
+ if (!conversationManager.hasConversation(name))
+ {
+ conversationManager.getMessager().setConversationNotActive(context, getName());
+
+ Object response = context.getExternalContext().getResponse();
+ if (response instanceof HttpServletResponse)
+ {
+ ((HttpServletResponse) response).sendRedirect(getRedirectTo());
+
+ context.responseComplete();
+ return;
+ }
+
+ log.error("conversation " + getName() + " not active, but we cant redirect as " + response + " is not a HttpServletResponse");
+ }
+ }
+
+ public String getRedirectTo()
+ {
+ if (redirectTo != null)
+ {
+ return redirectTo;
+ }
+ ValueBinding vb = getValueBinding("redirectTo");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (String) vb.getValue(getFacesContext());
+ }
+
+ public void setRedirectTo(String redirectTo)
+ {
+ this.redirectTo = redirectTo;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml Tue Jun 20 13:11:38 2006
@@ -135,7 +135,11 @@
<component-type>org.apache.myfaces.Conversation</component-type>
<component-class>org.apache.myfaces.custom.conversation.UIConversation</component-class>
</component>
-
+ <component>
+ <component-type>org.apache.myfaces.EnsureConversation</component-type>
+ <component-class>org.apache.myfaces.custom.conversation.UIEnsureConversation</component-class>
+ </component>
+
<component>
<component-type>org.apache.myfaces.HtmlSelectManyPicklist</component-type>
<component-class>org.apache.myfaces.custom.picklist.HtmlSelectManyPicklist</component-class>
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/end_conversation_attributes.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/end_conversation_attributes.xml?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/end_conversation_attributes.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/end_conversation_attributes.xml Tue Jun 20 13:11:38 2006
@@ -5,4 +5,12 @@
<description>
end the conversation only if the action outcome matches the given onOutcome. This can be a comma separated list.
</description>
+</attribute>
+<attribute>
+ <name>errorOutcome</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ on exception use the given outcome for further navigation
+ </description>
</attribute>
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml?rev=415789&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml Tue Jun 20 13:11:38 2006
@@ -0,0 +1,8 @@
+<attribute>
+ <name>redirectTo</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ redirect to the given view if the conversation is not running
+ </description>
+</attribute>
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Tue Jun 20 13:11:38 2006
@@ -127,6 +127,7 @@
<!ENTITY html_timed_notifier_attributes SYSTEM "entities/html_timed_notifier_attributes.xml">
<!ENTITY start_conversation_attributes SYSTEM "entities/start_conversation_attributes.xml">
<!ENTITY end_conversation_attributes SYSTEM "entities/end_conversation_attributes.xml">
+<!ENTITY ensure_conversation_attributes SYSTEM "entities/ensure_conversation_attributes.xml">
<!ENTITY standard_conversation_attributes SYSTEM "entities/standard_conversation_attributes.xml">
<!ENTITY conversation_attributes SYSTEM "entities/conversation_attributes.xml">
<!ENTITY ext_escape_attribute SYSTEM "entities-share/ext_escape_attribute.xml">
@@ -1129,6 +1130,15 @@
&standard_conversation_attributes;
&conversation_attributes;
+ </tag>
+ <tag>
+ <name>ensureConversation</name>
+ <tag-class>org.apache.myfaces.custom.conversation.EnsureConversationTag</tag-class>
+ <body-content>JSP</body-content>
+ <description>Ensures a named conversation is running</description>
+
+ &ensure_conversation_attributes;
+ &standard_conversation_attributes;
</tag>
<tag>
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardFinish.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardFinish.jsp?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardFinish.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardFinish.jsp Tue Jun 20 13:11:38 2006
@@ -30,6 +30,8 @@
<body>
<f:view>
+<s:ensureConversation name="wizard" redirectTo="/conversation/wizardPage1.jsp" />
+
<t:htmlTag value="h1">Registration Wizard</t:htmlTag>
<h:outputLink value="home.jsf"><h:outputText value="Menu" /></h:outputLink>
@@ -48,6 +50,11 @@
<h:commandButton value="Save" action="#{wizardController.save}">
<s:endConversation name="wizard" onOutcome="success"/>
</h:commandButton>
+
+ <h:commandButton value="End conversation and jump into the mid of a new one" action="wizardPage2">
+ <s:endConversation name="wizard" />
+ </h:commandButton>
+
</h:panelGroup>
</f:facet>
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp Tue Jun 20 13:11:38 2006
@@ -30,6 +30,8 @@
<body>
<f:view>
+<s:ensureConversation name="wizard" redirectTo="/conversation/wizardPage1.jsp" />
+
<t:htmlTag value="h1">Registration Wizard</t:htmlTag>
<h:outputLink value="home.jsf"><h:outputText value="Menu" /></h:outputLink>
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage3.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage3.jsp?rev=415789&r1=415788&r2=415789&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage3.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage3.jsp Tue Jun 20 13:11:38 2006
@@ -30,6 +30,8 @@
<body>
<f:view>
+<s:ensureConversation name="wizard" redirectTo="/conversation/wizardPage1.jsp" />
+
<t:htmlTag value="h1">Registration Wizard</t:htmlTag>
<h:outputLink value="home.jsf"><h:outputText value="Menu" /></h:outputLink>