Author: maschmid
Date: 2013-03-25 04:37:08 -0400 (Mon, 25 Mar 2013)
New Revision: 15466
Removed:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesPage.java
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/contexts/Contexts.java
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/core/ConversationPropagation.java
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesManager.java
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamViewHandler.java
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/navigation/Pages.java
branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/PhaseListenerTest.java
Log:
bz921660 removing FacesPage, moving conversation restoration to pre restore view
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/contexts/Contexts.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/contexts/Contexts.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/contexts/Contexts.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -115,12 +115,6 @@
{
log.debug("Page Context will be lazilly created");
FacesLifecycle.resumePage();
- Map<String, String> parameters =
facesContext.getExternalContext().getRequestParameterMap();
- ConversationPropagation.instance().restoreConversationId(parameters);
- boolean conversationFound = Manager.instance().restoreConversation();
-
pageContext.get().set("org.jboss.seam.jsf.SeamPhaseListener.conversationFound",
conversationFound);
-
- FacesLifecycle.resumeConversation(facesContext.getExternalContext());
}
}
}
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/core/ConversationPropagation.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/core/ConversationPropagation.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/core/ConversationPropagation.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -54,7 +54,6 @@
{
restoreNaturalConversationId(parameters);
restoreSyntheticConversationId(parameters);
- restorePageContextConversationId();
getPropagationFromRequestParameter(parameters);
handlePropagationType(parameters);
}
@@ -73,26 +72,6 @@
}
}
- private void restorePageContextConversationId()
- {
- if ( Contexts.isPageContextActive() && isMissing(conversationId) )
- {
- //checkPageContext is a workaround for a bug in MySQL server-side state saving
-
- //if it is not passed as a request parameter,
- //try to get it from the page context
- org.jboss.seam.faces.FacesPage page =
org.jboss.seam.faces.FacesPage.instance();
- conversationId = page.getConversationId();
- parentConversationId = null;
- validateLongRunningConversation = page.isConversationLongRunning();
- }
-
- else
- {
- log.trace("Found conversation id in request parameter: " +
conversationId);
- }
- }
-
private void restoreNaturalConversationId(Map parameters)
{
conversationName = getRequestParameterValue(parameters,
CONVERSATION_NAME_PARAMETER);
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesManager.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesManager.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesManager.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -99,16 +99,6 @@
}
redirect(url, parameters, true, true);
}
-
- @Override
- protected void storeConversationToViewRootIfNecessary()
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( facesContext!=null &&
(FacesLifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE ||
FacesLifecycle.getPhaseId()==PhaseId.RESTORE_VIEW) )
- {
- FacesPage.instance().storeConversation();
- }
- }
@Override
protected String generateInitialConversationId()
Deleted:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesPage.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesPage.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/faces/FacesPage.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -1,173 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.Serializable;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.core.Manager;
-//import org.jboss.seam.pageflow.Pageflow;
-import org.jboss.seam.web.Session;
-
-/**
- * Book-keeping component that persists information
- * about the conversation associated with the current
- * page.
- *
- * @author Gavin King
- *
- */
-(a)Name("org.jboss.seam.faces.facesPage")
-@BypassInterceptors
-@Install(precedence=BUILT_IN,
classDependencies="javax.faces.context.FacesContext")
-(a)Scope(ScopeType.PAGE)
-public class FacesPage implements Serializable
-{
- private static final long serialVersionUID = 4807114041808347239L;
- private String pageflowName;
- private Integer pageflowCounter;
- private String pageflowNodeName;
-
- private String conversationId;
- private boolean conversationIsLongRunning;
-
- //private Map<String, Object> pageParameters;
-
- public String getConversationId()
- {
- return conversationId;
- }
-
- public void discardTemporaryConversation()
- {
- conversationId = null;
- conversationIsLongRunning = false;
- }
-
- public void discardNestedConversation(String outerConversationId)
- {
- conversationId = outerConversationId;
- conversationIsLongRunning = true;
- }
-
- public void storeConversation(String conversationId)
- {
- this.conversationId = conversationId;
- conversationIsLongRunning = true;
- }
-
- public void storePageflow()
- {
-// if ( Init.instance().isJbpmInstalled() )
-// {
-// Pageflow pageflow = Pageflow.instance();
-// if ( pageflow.isInProcess() /*&&
!pageflow.getProcessInstance().hasEnded()*/ &&
Manager.instance().isLongRunningConversation() )
-// {
-// pageflowName =
pageflow.getSubProcessInstance().getProcessDefinition().getName();
-// pageflowNodeName = pageflow.getNode().getName();
-// pageflowCounter = pageflow.getPageflowCounter();
-// }
-// else
-// {
-// pageflowName = null;
-// pageflowNodeName = null;
-// pageflowCounter = null;
-// }
-// }
- }
-
- public static FacesPage instance()
- {
- if ( !Contexts.isPageContextActive() )
- {
- throw new IllegalStateException("No page context active");
- }
- return (FacesPage) Component.getInstance(FacesPage.class, ScopeType.PAGE);
- }
-
- public boolean isConversationLongRunning()
- {
- return conversationIsLongRunning;
- }
-
- public Integer getPageflowCounter()
- {
- return pageflowCounter;
- }
-
- public String getPageflowName()
- {
- return pageflowName;
- }
-
- public String getPageflowNodeName()
- {
- return pageflowNodeName;
- }
-
- public void storeConversation()
- {
- Manager manager = Manager.instance();
-
- //we only need to execute this code when we are in the
- //RENDER_RESPONSE phase, ie. not before redirects
-
- Session session = Session.getInstance();
- boolean sessionInvalid = session!=null && session.isInvalid();
- if ( !sessionInvalid && manager.isLongRunningConversation() )
- {
- storeConversation( manager.getCurrentConversationId() );
- }
- else if ( !sessionInvalid && manager.isNestedConversation() )
- {
- discardNestedConversation( manager.getParentConversationId() );
- }
- else
- {
- discardTemporaryConversation();
- }
-
- /*if ( !sessionInvalid && Init.instance().isClientSideConversations() )
- {
- // if we are using client-side conversations, put the
- // map containing the conversation context variables
- // into the view root (or remove it for a temp
- // conversation context)
- Contexts.getConversationContext().flush();
- }*/
-
- }
-
- /*public Map<String, Object> getPageParameters()
- {
- return pageParameters==null ? Collections.EMPTY_MAP : pageParameters;
- }
-
- public void setPageParameters(Map<String, Object> pageParameters)
- {
- this.pageParameters = pageParameters.isEmpty() ? null : pageParameters;
- }
-
- /**
- * Used by test harness
- *
- * @param name the page parameter name
- * @param value the value
- */
- /*public void setPageParameter(String name, Object value)
- {
- if (pageParameters==null)
- {
- pageParameters = new HashMap<String, Object>();
- }
- pageParameters.put(name, value);
- }*/
-
-}
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -34,7 +34,6 @@
import org.jboss.seam.exception.Exceptions;
import org.jboss.seam.faces.FacesManager;
import org.jboss.seam.faces.FacesMessages;
-import org.jboss.seam.faces.FacesPage;
import org.jboss.seam.faces.Switcher;
import org.jboss.seam.faces.Validation;
import org.jboss.seam.log.LogProvider;
@@ -116,6 +115,19 @@
{
beforeServletPhase(event);
}
+
+ // We resume conversation after handleTransactionsBeforePhase,
+ // so that Conversation-scoped entityManager has a transaction to enlist
+ if (event.getPhaseId() == RESTORE_VIEW) {
+ FacesContext facesContext = event.getFacesContext();
+ Map<String, String> parameters =
facesContext.getExternalContext().getRequestParameterMap();
+ ConversationPropagation.instance().restoreConversationId(parameters);
+ boolean conversationFound = Manager.instance().restoreConversation();
+
+
Contexts.getEventContext().set("org.jboss.seam.jsf.SeamPhaseListener.conversationFound",
conversationFound);
+ FacesLifecycle.resumeConversation(facesContext.getExternalContext());
+ }
+
raiseEventsBeforePhase(event);
}
catch (Exception e)
@@ -384,18 +396,15 @@
* Restore the page and conversation contexts during a JSF request
*/
protected void afterRestoreView(FacesContext facesContext)
- {
- boolean conversationFound = Contexts.isPageContextActive() ?
Contexts.getPageContext().isSet("org.jboss.seam.jsf.SeamPhaseListener.conversationFound")
: false;
- FacesLifecycle.resumePage();
- Map parameters = facesContext.getExternalContext().getRequestParameterMap();
- if (!conversationFound) // there is exceptional case when restoring of conversation
wasn't called while page context was lazily initialized
- {
- ConversationPropagation.instance().restoreConversationId(parameters);
- conversationFound = Manager.instance().restoreConversation();
- }
- FacesLifecycle.resumeConversation( facesContext.getExternalContext() );
- postRestorePage(facesContext, parameters, conversationFound);
-
+ {
+ boolean conversationFound = Contexts.isEventContextActive() ?
Contexts.getEventContext().isSet("org.jboss.seam.jsf.SeamPhaseListener.conversationFound")
: false;
+
+ if (!Contexts.isPageContextActive()) {
+ FacesLifecycle.resumePage();
+ }
+
+ Map parameters = facesContext.getExternalContext().getRequestParameterMap();
+ postRestorePage(facesContext, parameters, conversationFound);
}
public void raiseEventsBeforePhase(PhaseEvent event)
@@ -491,9 +500,6 @@
FacesManager.instance().prepareBackswitch(facesContext);
}
- FacesPage.instance().storeConversation();
- FacesPage.instance().storePageflow();
-
PersistenceContexts persistenceContexts = PersistenceContexts.instance();
if (persistenceContexts != null)
{
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamViewHandler.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamViewHandler.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/jsf/SeamViewHandler.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -99,18 +99,22 @@
if (!getSource().equals(Source.BOOKMARKABLE) &&
!getSource().equals(Source.REDIRECT) )
{
- if ( !conversation.isNested() || conversation.isLongRunning() )
+ if (conversation.isLongRunning())
{
return new FacesUrlTransformer(actionUrl, facesContext)
.appendConversationIdIfNecessary(conversationIdParameter,
conversation.getId())
.getUrl();
}
- else
+ else if (conversation.isNested())
{
return new FacesUrlTransformer(actionUrl, facesContext)
.appendConversationIdIfNecessary(conversationIdParameter,
conversation.getParentId())
.getUrl();
}
+ else
+ {
+ return actionUrl;
+ }
} else {
return actionUrl;
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -78,6 +78,7 @@
protected MockHttpSession session;
private Map<String, Map> conversationViewRootAttributes;
protected Filter seamFilter;
+ protected String conversationIdParameter = "conversationId";
private static ServletContext realServletContext = null;
@@ -122,7 +123,7 @@
protected String getConversationIdParameter()
{
- return "conversationId";
+ return conversationIdParameter;
}
/**
@@ -741,6 +742,12 @@
setParameter(getConversationIdParameter(), conversationId);
}
phases.beforePhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW,
MockLifecycle.INSTANCE));
+
+ // We cannot get conversationIdParameter before restore view phase, as Manager
is in
+ // event context, which is not active yet, so we hope we set this in the first
request
+ // and we assume it won't change. In other cases, you may just override
getConversationIdParameter();
+ conversationIdParameter = Manager.instance().getConversationIdParameter();
+
try
{
UIViewRoot viewRoot =
facesContext.getApplication().getViewHandler().createView(facesContext, getViewId());
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/navigation/Pages.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/navigation/Pages.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/navigation/Pages.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -568,21 +568,9 @@
{
noConversation();
- //stuff from jPDL takes precedence
- org.jboss.seam.faces.FacesPage facesPage =
org.jboss.seam.faces.FacesPage.instance();
- String pageflowName = facesPage.getPageflowName();
- String pageflowNodeName = facesPage.getPageflowNodeName();
-
String noConversationViewId = null;
- if (pageflowName==null || pageflowNodeName==null)
- {
- String viewId = Pages.getCurrentViewId();
- noConversationViewId = getNoConversationViewId(viewId);
- }
- else
- {
- //noConversationViewId =
Pageflow.instance().getNoConversationViewId(pageflowName, pageflowNodeName);
- }
+ String viewId = Pages.getCurrentViewId();
+ noConversationViewId = getNoConversationViewId(viewId);
if (noConversationViewId!=null)
{
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/PhaseListenerTest.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/PhaseListenerTest.java 2013-03-25
08:28:30 UTC (rev 15465)
+++
branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/PhaseListenerTest.java 2013-03-25
08:37:08 UTC (rev 15466)
@@ -26,16 +26,17 @@
import org.jboss.seam.core.ResourceLoader;
import org.jboss.seam.faces.FacesManager;
import org.jboss.seam.faces.FacesMessages;
-import org.jboss.seam.faces.FacesPage;
import org.jboss.seam.faces.Validation;
import org.jboss.seam.jsf.SeamPhaseListener;
import org.jboss.seam.jsf.SeamStateManager;
import org.jboss.seam.mock.MockApplication;
import org.jboss.seam.mock.MockExternalContext;
import org.jboss.seam.mock.MockFacesContext;
+import org.jboss.seam.mock.MockHttpServletRequest;
import org.jboss.seam.mock.MockLifecycle;
import org.jboss.seam.navigation.Pages;
import org.jboss.seam.servlet.ServletRequestSessionMap;
+import org.jboss.seam.web.ServletContexts;
import org.jboss.seam.web.Session;
import org.testng.annotations.Test;
@@ -49,7 +50,6 @@
appContext.set( Seam.getComponentName(Init.class), init );
installComponent(appContext, FacesManager.class);
installComponent(appContext, ConversationEntries.class);
- installComponent(appContext, FacesPage.class);
installComponent(appContext, Conversation.class);
installComponent(appContext, FacesMessages.class);
installComponent(appContext, Pages.class);
@@ -58,6 +58,7 @@
installComponent(appContext, Session.class);
installComponent(appContext, ConversationPropagation.class);
installComponent(appContext, ResourceLoader.class);
+ installComponent(appContext, ServletContexts.class);
}
private void installComponent(Context appContext, Class clazz)
@@ -93,7 +94,7 @@
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
- assert !Contexts.isConversationContextActive();
+ assert Contexts.isConversationContextActive();
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW,
MockLifecycle.INSTANCE ) );
@@ -115,9 +116,7 @@
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE,
MockLifecycle.INSTANCE ) );
- // there is one additional item - conversationFound
- assert facesContext.getViewRoot().getViewMap().size()==2;
- assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() +
Seam.getComponentName(FacesPage.class) ) ).getConversationId()==null;
+ assert facesContext.getViewRoot().getViewMap().size()==0;
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
@@ -144,7 +143,8 @@
{
MockFacesContext facesContext = createFacesContext();
- getPageMap(facesContext).put( getPrefix() + Seam.getComponentName(FacesPage.class),
new FacesPage() { @Override public String getConversationId() { return "2"; }
});
+ MockHttpServletRequest request =
(MockHttpServletRequest)facesContext.getExternalContext().getRequest();
+ request.getParameters().put("conversationId", new String[]
{"2"});
List<String> conversationIdStack = new ArrayList<String>();
conversationIdStack.add("2");
@@ -165,7 +165,7 @@
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
- assert !Contexts.isConversationContextActive();
+ assert Contexts.isConversationContextActive();
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW,
MockLifecycle.INSTANCE ) );
@@ -196,10 +196,9 @@
facesContext.getApplication().getStateManager().saveView(facesContext);
+ assert Manager.instance().getCurrentConversationId().equals("2");
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE,
MockLifecycle.INSTANCE ) );
- assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() +
Seam.getComponentName(FacesPage.class) ) ).getConversationId().equals("2");
-
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isApplicationContextActive();
@@ -228,7 +227,7 @@
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
- assert !Contexts.isConversationContextActive();
+ assert Contexts.isConversationContextActive();
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW,
MockLifecycle.INSTANCE ) );
@@ -259,7 +258,7 @@
facesContext.getApplication().getStateManager().saveView(facesContext);
- assert facesContext.getViewRoot().getViewMap().size()==2;
+ assert facesContext.getViewRoot().getViewMap().size()==0;
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE,
MockLifecycle.INSTANCE ) );
@@ -285,7 +284,7 @@
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
- assert !Contexts.isConversationContextActive();
+ assert Contexts.isConversationContextActive();
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW,
MockLifecycle.INSTANCE ) );
@@ -327,7 +326,7 @@
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
- assert !Contexts.isConversationContextActive();
+ assert Contexts.isConversationContextActive();
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW,
MockLifecycle.INSTANCE ) );
@@ -336,8 +335,8 @@
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE,
MockLifecycle.INSTANCE ) );
- assert facesContext.getViewRoot().getViewMap().size()==2;
- assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() +
Seam.getComponentName(FacesPage.class) ) ).getConversationId()==null;
+ assert facesContext.getViewRoot().getViewMap().size()==0;
+ //assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() +
Seam.getComponentName(FacesPage.class) ) ).getConversationId()==null;
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();