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/10/31 14:52:48 UTC

svn commit: r469482 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/conversation/ core/src/main/tld/entities/ examples/src/main/webapp/conversation/

Author: imario
Date: Tue Oct 31 05:52:47 2006
New Revision: 469482

URL: http://svn.apache.org/viewvc?view=rev&rev=469482
Log:
* added "action" attribute to ensureConversation which allows you to use the JSF navigation (w/ or w/o method-binding) in case of a not running conversation
* changed exception throw by s:conversation to a log.debug if bean can't be elevated in case of a not running conversation

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp

Modified: 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?view=diff&rev=469482&r1=469481&r2=469482
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EnsureConversationTag.java Tue Oct 31 05:52:47 2006
@@ -15,26 +15,49 @@
  */
 package org.apache.myfaces.custom.conversation;
 
+import org.apache.myfaces.shared_tomahawk.el.SimpleActionMethodBinding;
+
 import javax.faces.component.UIComponent;
+import javax.faces.el.MethodBinding;
 
 /**
  * Checks if a conversation is active, else redirects to another view
- * 
+ *
  * @author imario@apache.org
  */
 public class EnsureConversationTag extends AbstractConversationTag
 {
 	private String redirectTo;
+	private String action;
 
 	public String getComponentType()
 	{
 		return UIEnsureConversation.COMPONENT_TYPE;
 	}
-	
+
     protected void setProperties(UIComponent component)
     {
         super.setProperties(component);
-        setStringProperty(component, "redirectTo", getRedirectTo());
+		UIEnsureConversation ensureConversation = (UIEnsureConversation) component;
+
+		setStringProperty(component, "redirectTo", getRedirectTo());
+		if (getAction() != null)
+		{
+			if (isValueReference(getAction()))
+			{
+				MethodBinding mb = getFacesContext().getApplication().createMethodBinding(
+					getAction(), null);
+				ensureConversation.setAction(mb);
+			}
+			else
+			{
+				ensureConversation.setAction(new SimpleActionMethodBinding(getAction()));
+			}
+		}
+		else
+		{
+				ensureConversation.setAction(null);
+		}
     }
 
 	public String getRedirectTo()
@@ -45,5 +68,15 @@
 	public void setRedirectTo(String redirectTo)
 	{
 		this.redirectTo = redirectTo;
+	}
+
+	public String getAction()
+	{
+		return action;
+	}
+
+	public void setAction(String action)
+	{
+		this.action = action;
 	}
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java?view=diff&rev=469482&r1=469481&r2=469482
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java Tue Oct 31 05:52:47 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.myfaces.custom.conversation;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.IOException;
 
 import javax.faces.context.FacesContext;
@@ -22,33 +25,36 @@
 
 /**
  * add a bean under context control
- * 
+ *
  * @author imario@apache.org
  */
 public class UIConversation extends AbstractConversationComponent
 {
+	private final static Log log = LogFactory.getLog(UIConversation.class);
+
 	public static final String COMPONENT_TYPE = "org.apache.myfaces.Conversation";
 
 	public void encodeBegin(FacesContext context) throws IOException
 	{
 		super.encodeBegin(context);
-		
+
 		elevateBean(context);
 	}
 
 	public void elevateBean(FacesContext context)
 	{
+		ValueBinding vb = getValueBinding("value");
+		String name = ConversationUtils.extractBeanName(vb);
+
 		Conversation conversation = ConversationManager.getInstance().getConversation(getName());
 		if (conversation == null)
 		{
-			throw new IllegalStateException("no conversation named '" + getName() + "' running");
+			log.debug("no conversation named '" + getName() + "' running - can't elevate bean '" + name);
+			return;
 		}
 
-		ValueBinding vb = getValueBinding("value");
 		conversation.putBean(context, vb);
-		
-		String name = ConversationUtils.extractBeanName(vb);
-		
+
 		// remove it from the other contexts
 		context.getExternalContext().getRequestMap().remove(name);
 		context.getExternalContext().getSessionMap().remove(name);

Modified: 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?view=diff&rev=469482&r1=469481&r2=469482
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java Tue Oct 31 05:52:47 2006
@@ -19,6 +19,7 @@
 
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
+import javax.faces.el.MethodBinding;
 import java.io.IOException;
 
 /**
@@ -37,6 +38,7 @@
 	public static final String COMPONENT_TYPE = "org.apache.myfaces.EnsureConversation";
 
 	private String redirectTo;
+	private MethodBinding action;
 
 	public void encodeBegin(FacesContext context) throws IOException
 	{
@@ -65,6 +67,7 @@
 
 		super.restoreState(context, states[0]);
 		redirectTo = (String) states[1];
+		action = (MethodBinding) restoreAttachedState(context, states[2]);
 	}
 
 	public Object saveState(FacesContext context)
@@ -72,7 +75,8 @@
 		return new Object[]
 			{
 				super.saveState(context),
-				redirectTo
+				redirectTo,
+				action
 			};
 	}
 
@@ -83,19 +87,29 @@
 		{
 			conversationManager.getMessager().setConversationNotActive(context, getName());
 
-			String actionUrl = context.getApplication().getViewHandler().getActionURL(
-						context, getRedirectTo());
-			String encodedActionUrl = context.getExternalContext().encodeActionURL(actionUrl);
-
-			// XXX: figure out a way to avoid this ==>
-			RedirectTrackerManager manager = RedirectTrackerManager.getInstance(context);
-			if (manager != null)
+			if (getAction() != null)
 			{
-				encodedActionUrl = manager.trackRedirect(context, encodedActionUrl);
+				String actionResult = (String) getAction().invoke(context, null);
+
+				// hopefully the user configured the navigation as redirect ...
+				context.getApplication().getNavigationHandler().handleNavigation(context, null, actionResult);
 			}
-			// XXX: figure out a way to avoid this <==
+			else
+			{
+				String actionUrl = context.getApplication().getViewHandler().getActionURL(
+							context, getRedirectTo());
+				String encodedActionUrl = context.getExternalContext().encodeActionURL(actionUrl);
+
+				// XXX: figure out a way to avoid this ==>
+				RedirectTrackerManager manager = RedirectTrackerManager.getInstance(context);
+				if (manager != null)
+				{
+					encodedActionUrl = manager.trackRedirect(context, encodedActionUrl);
+				}
+				// XXX: figure out a way to avoid this <==
 
-			context.getExternalContext().redirect(encodedActionUrl);
+				context.getExternalContext().redirect(encodedActionUrl);
+			}
 
 			return;
 		}
@@ -118,5 +132,15 @@
 	public void setRedirectTo(String redirectTo)
 	{
 		this.redirectTo = redirectTo;
+	}
+
+	public MethodBinding getAction()
+	{
+		return action;
+	}
+
+	public void setAction(MethodBinding action)
+	{
+		this.action = action;
 	}
 }

Modified: 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?view=diff&rev=469482&r1=469481&r2=469482
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ensure_conversation_attributes.xml Tue Oct 31 05:52:47 2006
@@ -5,4 +5,12 @@
     <description>
        redirect to the given view if the conversation is not running
     </description>
+</attribute>
+<attribute>
+	<name>action</name>
+	<required>false</required>
+	<rtexprvalue>false</rtexprvalue>
+	<description>
+		the action which should be called in case of a not running conversation
+	</description>
 </attribute>

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?view=diff&rev=469482&r1=469481&r2=469482
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/conversation/wizardPage2.jsp Tue Oct 31 05:52:47 2006
@@ -30,7 +30,7 @@
 <body>
 <f:view>
 
-<s:ensureConversation name="wizard" redirectTo="/conversation/wizardPage1.jsp" />
+<s:ensureConversation name="wizard" action="wizardPage1" />
 
 <t:htmlTag value="h1">Registration Wizard</t:htmlTag>
 
@@ -51,19 +51,19 @@
 			<h:commandButton value="Next >>" action="wizardPage3" />
 		</h:panelGroup>
 	</f:facet>
-	
+
     <h:outputText value="Street: " />
     <h:inputText id="street" value="#{wizardData.street}" required="true"/>
-    
+
     <h:outputText value="City: " />
     <h:inputText id="city" value="#{wizardData.city}" required="true"/>
-    
+
     <h:outputText value="State: " />
     <h:inputText id="state" value="#{wizardData.state}" required="true"/>
 
     <h:outputText value="Province: " />
     <h:inputText id="province" value="#{wizardData.province}" />
-    
+
     <h:outputText value="Postal: " />
     <h:inputText id="postal" value="#{wizardData.postal}" required="true"/>
 </h:panelGrid>