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/04/27 22:08:33 UTC
svn commit: r397623 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/conversation/
examples/src/main/webapp/
Author: imario
Date: Thu Apr 27 13:08:31 2006
New Revision: 397623
URL: http://svn.apache.org/viewcvs?rev=397623&view=rev
Log:
now using a variableResolver - works better
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java (with props)
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/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/ConversationUtils.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationViewHandler.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/UIStartConversation.java
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pageConversation.jsp
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java?rev=397623&r1=397622&r2=397623&view=diff
==============================================================================
--- 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 Thu Apr 27 13:08:31 2006
@@ -30,7 +30,8 @@
{
private final String name;
- private final Map beans = new TreeMap(new ValueBindingKey());
+ // private final Map beans = new TreeMap(new ValueBindingKey());
+ private final Map beans = new TreeMap();
protected Conversation(String name)
{
@@ -43,7 +44,17 @@
*/
public void putBean(FacesContext context, ValueBinding vb)
{
- beans.put(vb, vb.getValue(context));
+ String name = ConversationUtils.extractBeanName(vb);
+ if (name.indexOf('.') > -1)
+ {
+ throw new IllegalArgumentException("you cant put a property under conversation control. name: " + name);
+ }
+ if (beans.containsKey(name))
+ {
+ // already there
+ return;
+ }
+ beans.put(name, vb.getValue(context));
}
/**
@@ -79,9 +90,19 @@
* Iterate all beans associated to this context
*
* @return Iterator of {@link Map.Entry} elements
- */
public Iterator iterateBeanEntries()
{
return beans.entrySet().iterator();
+ }
+ */
+
+ public boolean hasBean(String name)
+ {
+ return beans.containsKey(name);
+ }
+
+ public Object getBean(String name)
+ {
+ return beans.get(name);
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java?rev=397623&r1=397622&r2=397623&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 Thu Apr 27 13:08:31 2006
@@ -140,7 +140,6 @@
/**
* inject all beans from the conversation context to their configured scope
- */
protected void injectConversationBeans(FacesContext context)
{
Set alreadyAdded = new TreeSet(new ValueBindingKey());
@@ -158,5 +157,20 @@
}
}
}
+ }
+ */
+
+ public Object findBean(String name)
+ {
+ for (int i = conversationStack.size(); i>0; i--)
+ {
+ Conversation conversation = (Conversation) conversationStack.get(i-1);
+ if (conversation.hasBean(name))
+ {
+ return conversation.getBean(name);
+ }
+ }
+
+ return null;
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java?rev=397623&r1=397622&r2=397623&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 Thu Apr 27 13:08:31 2006
@@ -214,7 +214,6 @@
/**
* Inject all beans of the current conversation
* @see ConversationContext#injectConversationBeans(FacesContext)
- */
protected void injectConversationBeans(FacesContext context)
{
ConversationContext conversationContext = getConversationContext();
@@ -225,6 +224,7 @@
conversationContext.injectConversationBeans(context);
}
+ */
/**
* check if we have a conversation context
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationUtils.java?rev=397623&r1=397622&r2=397623&view=diff
==============================================================================
--- 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 Thu Apr 27 13:08:31 2006
@@ -19,6 +19,7 @@
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
+import javax.faces.el.ValueBinding;
public class ConversationUtils
{
@@ -75,5 +76,11 @@
}
return null;
+ }
+
+ public static String extractBeanName(ValueBinding vb)
+ {
+ String valueBinding = vb.getExpressionString();
+ return valueBinding.substring(2, valueBinding.length()-1);
}
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java?rev=397623&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java Thu Apr 27 13:08:31 2006
@@ -0,0 +1,46 @@
+/*
+ * 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;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.VariableResolver;
+
+public class ConversationVariableResolver extends VariableResolver
+{
+ private final VariableResolver original;
+
+ public ConversationVariableResolver(VariableResolver original)
+ {
+ this.original = original;
+ }
+
+ public Object resolveVariable(FacesContext context, String name) throws EvaluationException
+ {
+ ConversationManager conversationManager = ConversationManager.getInstance(context);
+ if (conversationManager.hasConversationContext())
+ {
+ Object bean = conversationManager.getConversationContext().findBean(name);
+ if (bean != null)
+ {
+ return bean;
+ }
+ }
+
+ return original.resolveVariable(context, name);
+ }
+
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationVariableResolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationViewHandler.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationViewHandler.java?rev=397623&r1=397622&r2=397623&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationViewHandler.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationViewHandler.java Thu Apr 27 13:08:31 2006
@@ -55,7 +55,7 @@
public UIViewRoot createView(FacesContext context, String viewId)
{
- injectConversationBeans(context);
+ // injectConversationBeans(context);
return original.createView(context, viewId);
}
@@ -109,7 +109,7 @@
public UIViewRoot restoreView(FacesContext context, String viewId)
{
- injectConversationBeans(context);
+ // injectConversationBeans(context);
return original.restoreView(context, viewId);
}
@@ -158,10 +158,10 @@
* <ul>
* <li>{@link #renderView(FacesContext, UIViewRoot)}</li>
* </ul>
- */
protected void injectConversationBeans(FacesContext context)
{
ConversationManager conversationManager = ConversationManager.getInstance(context);
conversationManager.injectConversationBeans(context);
}
+ */
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIConversation.java?rev=397623&r1=397622&r2=397623&view=diff
==============================================================================
--- 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 Thu Apr 27 13:08:31 2006
@@ -46,5 +46,11 @@
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/UIStartConversation.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java?rev=397623&r1=397622&r2=397623&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIStartConversation.java Thu Apr 27 13:08:31 2006
@@ -20,6 +20,7 @@
import javax.faces.application.ViewHandler;
import javax.faces.component.UICommand;
import javax.faces.context.FacesContext;
+import javax.faces.el.VariableResolver;
/**
* start a conversation
@@ -73,8 +74,11 @@
return;
}
- ViewHandler original = context.getApplication().getViewHandler();
- context.getApplication().setViewHandler(new ConversationViewHandler(original));
+ ViewHandler originalVH = context.getApplication().getViewHandler();
+ context.getApplication().setViewHandler(new ConversationViewHandler(originalVH));
+
+ VariableResolver originalVR = context.getApplication().getVariableResolver();
+ context.getApplication().setVariableResolver(new ConversationVariableResolver(originalVR));
context.getExternalContext().getApplicationMap().put(CONVERSATION_SYSTEM_SETUP, Boolean.TRUE);
}
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pageConversation.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pageConversation.jsp?rev=397623&r1=397622&r2=397623&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pageConversation.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pageConversation.jsp Thu Apr 27 13:08:31 2006
@@ -29,9 +29,11 @@
</head>
<body>
<f:view>
-<h:form>
+
<s:startConversation name="page" />
-<s:conversation name="page" value="#{convData.input}" />
+<s:conversation name="page" value="#{convData}" />
+
+<h:form>
<h:panelGrid columns="2">
<h:outputText value="Enter something into this field: " />
<h:inputText value="#{convData.input}" />