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/09/25 15:31:46 UTC
svn commit: r449680 - in /myfaces/tomahawk/trunk/sandbox/core/src/main:
java/org/apache/myfaces/custom/conversation/ tld/entities/
Author: imario
Date: Mon Sep 25 06:31:45 2006
New Revision: 449680
URL: http://svn.apache.org/viewvc?view=rev&rev=449680
Log:
ConversationTag: added "restart" and "restartAction" to the endConversation tag.
This allows you to immediately restart a conversation at the end of the conversation.
The method (restartAction) has access to the new conversation.
This is usefull if you have to recreate the data for a dataTable - in this case you cant do this in e.g. the saveMethod (if you dont want to clutter your backing with conversation specific code)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.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/tld/entities/end_conversation_attributes.xml
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java?view=diff&rev=449680&r1=449679&r2=449680
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java Mon Sep 25 06:31:45 2006
@@ -27,25 +27,25 @@
/**
* handle conversation related stuff like beans
- * @author imario@apache.org
+ * @author imario@apache.org
*/
public class Conversation
{
private final static Log log = LogFactory.getLog(Conversation.class);
-
+
private final String name;
private final boolean persistence;
- private PersistenceManager persistenceManager;
-
+ private PersistenceManager persistenceManager;
+
// private final Map beans = new TreeMap(new ValueBindingKey());
private final Map beans = new TreeMap();
-
+
protected Conversation(String name, boolean persistence)
{
this.name = name;
this.persistence = persistence;
-
+
if (log.isDebugEnabled())
{
log.debug("start conversation:" + name + "(persistence=" + persistence + ")");
@@ -54,7 +54,7 @@
/**
* Add the given valueBinding to the context map. <br/>
- * This will also resolve the value of the binding.
+ * This will also resolve the value of the binding.
*/
public void putBean(FacesContext context, ValueBinding vb)
{
@@ -96,14 +96,14 @@
{
log.debug("end conversation:" + name);
}
-
+
Iterator iterBeans = beans.values().iterator();
while (iterBeans.hasNext())
{
Object bean = iterBeans.next();
if (bean instanceof ConversationListener)
{
- ((ConversationListener) bean).conversationEnded();
+ ((ConversationListener) bean).conversationEnded();
}
}
beans.clear();
@@ -118,12 +118,14 @@
{
getPersistenceManager().rollback();
}
+
+ getPersistenceManager().purge();
}
}
/**
* Iterate all beans associated to this context
- *
+ *
* @return Iterator of {@link Map.Entry} elements
public Iterator iterateBeanEntries()
{
@@ -140,7 +142,7 @@
{
return beans.get(name);
}
-
+
/**
* returns true if this conversation hold the persistence manager (aka EntityManager)
*/
@@ -155,7 +157,7 @@
{
persistenceManager = ConversationManager.getInstance().createPersistenceManager();
}
-
+
return persistenceManager;
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.java?view=diff&rev=449680&r1=449679&r2=449680
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.java Mon Sep 25 06:31:45 2006
@@ -20,6 +20,8 @@
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.el.ValueBinding;
+import javax.faces.el.MethodBinding;
+import javax.faces.context.FacesContext;
public class ConversationUtils
{
@@ -42,12 +44,12 @@
}
}
while (parent != null);
-
+
return null;
}
/**
- * Find a child start or end conversation component for the given conversation name
+ * Find a child start or end conversation component for the given conversation name
*/
public static AbstractConversationComponent findStartOrEndConversationComponent(UIComponent component, String conversationName)
{
@@ -56,7 +58,7 @@
{
Object child = iterComponents.next();
AbstractConversationComponent conversation;
-
+
if (child instanceof UIStartConversation || child instanceof UIEndConversation)
{
conversation = (AbstractConversationComponent) child;
@@ -74,13 +76,36 @@
}
}
}
-
+
return null;
}
-
+
public static String extractBeanName(ValueBinding vb)
{
String valueBinding = vb.getExpressionString();
return valueBinding.substring(2, valueBinding.length()-1);
}
+
+ /**
+ * end and restart a conversation
+ */
+ static void endAndRestartConversation(FacesContext context, String conversationName, Boolean restart, MethodBinding restartAction)
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance(context);
+ Conversation conversation = conversationManager.getConversation(conversationName);
+
+ conversationManager.endConversation(conversationName);
+
+ if (restart != null && restart.booleanValue() && conversation != null)
+ {
+ conversationManager.startConversation(conversationName, conversation.isPersistence());
+
+ if (restartAction != null)
+ {
+ restartAction.invoke(context, null);
+ }
+ }
+ }
+
+
}
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?view=diff&rev=449680&r1=449679&r2=449680
==============================================================================
--- 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 Mon Sep 25 06:31:45 2006
@@ -35,6 +35,8 @@
private String conversationName;
private Collection onOutcomes;
private String errorOutcome;
+ private Boolean restart;
+ private MethodBinding restartAction;
private boolean _transient = false;
@@ -42,12 +44,16 @@
{
}
- public EndConversationMethodBindingFacade(String conversation, Collection onOutcomes, MethodBinding original, String errorOutcome)
+ public EndConversationMethodBindingFacade(
+ String conversation, Collection onOutcomes, MethodBinding original,
+ String errorOutcome, Boolean restart, MethodBinding restartAction)
{
this.original = original;
this.conversationName = conversation;
this.onOutcomes = onOutcomes;
this.errorOutcome = errorOutcome;
+ this.restart = restart;
+ this.restartAction = restartAction;
}
public String getConversationName()
@@ -89,7 +95,7 @@
{
ConversationManager conversationManager = ConversationManager.getInstance(context);
conversationManager.purgePersistence();
-
+
if (errorOutcome != null)
{
conversationManager.getMessager().setConversationException(context, t);
@@ -110,12 +116,11 @@
{
end = onOutcomes.contains(returnValue);
}
- }
- if (end)
- {
- ConversationManager conversationManager = ConversationManager.getInstance(context);
- conversationManager.endConversation(getConversationName());
+ if (end)
+ {
+ ConversationUtils.endAndRestartConversation(context, conversationName, restart, restartAction);
+ }
}
}
return returnValue;
@@ -139,6 +144,8 @@
conversationName = (String) state[1];
onOutcomes = (Collection) state[2];
errorOutcome = (String) state[3];
+ restart = (Boolean) state[4];
+ restartAction = (MethodBinding) UIComponentBase.restoreAttachedState(context, state[5]);
}
public Object saveState(FacesContext context)
@@ -148,7 +155,9 @@
UIComponentBase.saveAttachedState(context, original),
conversationName,
onOutcomes,
- errorOutcome
+ errorOutcome,
+ restart,
+ UIComponentBase.saveAttachedState(context, restartAction)
};
}
}
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?view=diff&rev=449680&r1=449679&r2=449680
==============================================================================
--- 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 Mon Sep 25 06:31:45 2006
@@ -16,28 +16,46 @@
package org.apache.myfaces.custom.conversation;
import javax.faces.component.UIComponent;
+import javax.faces.el.MethodBinding;
/**
* Ends a conversation
- *
+ *
* @author imario@apache.org
*/
public class EndConversationTag extends AbstractConversationTag
{
private String onOutcome;
private String errorOutcome;
+ private String restart;
+ private String restartAction;
public String getComponentType()
{
return UIEndConversation.COMPONENT_TYPE;
}
-
+
protected void setProperties(UIComponent component)
{
super.setProperties(component);
- setStringProperty(component, "onOutcome", getOnOutcome());
+
+ UIEndConversation endConversation = (UIEndConversation) component;
+
+ setStringProperty(component, "onOutcome", getOnOutcome());
setStringProperty(component, "errorOutcome", getErrorOutcome());
- }
+ setBooleanProperty(component, "restart", getRestart());
+
+ if (isValueReference(getRestartAction()))
+ {
+ MethodBinding mb = getFacesContext().getApplication().createMethodBinding(
+ getRestartAction(), null);
+ endConversation.setRestartAction(mb);
+ }
+ else
+ {
+ throw new IllegalArgumentException("argument 'restartAction' must be a method binding");
+ }
+ }
public String getOnOutcome()
{
@@ -57,5 +75,25 @@
public void setErrorOutcome(String errorOutcome)
{
this.errorOutcome = errorOutcome;
+ }
+
+ public String getRestart()
+ {
+ return restart;
+ }
+
+ public void setRestart(String restart)
+ {
+ this.restart = restart;
+ }
+
+ public String getRestartAction()
+ {
+ return restartAction;
+ }
+
+ public void setRestartAction(String restartAction)
+ {
+ this.restartAction = restartAction;
}
}
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?view=diff&rev=449680&r1=449679&r2=449680
==============================================================================
--- 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 Mon Sep 25 06:31:45 2006
@@ -36,6 +36,8 @@
private String onOutcome;
private String errorOutcome;
+ private Boolean restart;
+ private MethodBinding restartAction;
private boolean inited = false;
@@ -64,14 +66,22 @@
command.addActionListener(actionListener);
*/
MethodBinding original = command.getAction();
- command.setAction(new EndConversationMethodBindingFacade(getName(), getOnOutcomes(), original, getErrorOutcome()));
+ command.setAction(new EndConversationMethodBindingFacade(
+ getName(),
+ getOnOutcomes(),
+ original,
+ getErrorOutcome(),
+ getRestart(),
+ getRestartAction()));
inited = true;
}
}
else
{
- ConversationManager conversationManager = ConversationManager.getInstance();
- conversationManager.endConversation(getName());
+ ConversationUtils.endAndRestartConversation(context,
+ getName(),
+ getRestart(),
+ getRestartAction());
}
}
@@ -93,6 +103,8 @@
inited = ((Boolean) states[1]).booleanValue();
onOutcome = (String) states[2];
errorOutcome = (String) states[3];
+ restart = (Boolean) states[4];
+ restartAction = (MethodBinding) restoreAttachedState(context, states[5]);
}
public Object saveState(FacesContext context)
@@ -102,7 +114,9 @@
super.saveState(context),
inited ? Boolean.TRUE : Boolean.FALSE,
onOutcome,
- errorOutcome
+ errorOutcome,
+ restart,
+ saveAttachedState(context, restartAction)
};
}
@@ -142,5 +156,34 @@
public void setErrorOutcome(String errorOutcome)
{
this.errorOutcome = errorOutcome;
+ }
+
+ public Boolean getRestart()
+ {
+ if (restart != null)
+ {
+ return restart;
+ }
+ ValueBinding vb = getValueBinding("restart");
+ if (vb == null)
+ {
+ return null;
+ }
+ return (Boolean) vb.getValue(getFacesContext());
+ }
+
+ public void setRestart(Boolean restart)
+ {
+ this.restart = restart;
+ }
+
+ public MethodBinding getRestartAction()
+ {
+ return restartAction;
+ }
+
+ public void setRestartAction(MethodBinding restartAction)
+ {
+ this.restartAction = restartAction;
}
}
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?view=diff&rev=449680&r1=449679&r2=449680
==============================================================================
--- 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 Mon Sep 25 06:31:45 2006
@@ -13,4 +13,20 @@
<description>
on exception use the given outcome for further navigation
</description>
+</attribute>
+<attribute>
+ <name>restart</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ true|false|valueBinding - true if the conversation should be restarted immediately
+ </description>
+</attribute>
+<attribute>
+ <name>restartAction</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ the action which should be called in case of a restart
+ </description>
</attribute>