JBoss Ajax4JSF SVN: r222 - in trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet: application and 1 other directory.
by ajax4jsf-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-05-29 20:10:55 -0400 (Tue, 29 May 2007)
New Revision: 222
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
Log:
CODING IN PROGRESS - issue RF-186: Portlet integration for JBoss Portal, portals jsr-168
http://jira.jboss.com/jira/browse/RF-186
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-05-28 14:09:55 UTC (rev 221)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-05-30 00:10:55 UTC (rev 222)
@@ -29,7 +29,9 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
+import org.ajax4jsf.portlet.application.PortletStateHolder;
import org.ajax4jsf.portlet.application.PortletViewState;
+import org.ajax4jsf.portlet.application.PortletWindowStates;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -119,7 +121,7 @@
try {
setViewId(facesContext);
execute(facesContext);
- saveView(facesContext, response);
+ saveView(facesContext);
} catch (Exception e) {
log.error("Error processing execute lifecycle", e);
throw new PortletException("Error processing execute lifecycle ", e);
@@ -128,13 +130,13 @@
}
}
- protected void saveView(FacesContext facesContext, ActionResponse response) {
- PortletViewState state = new PortletViewState();
- state.save(facesContext);
- facesContext.getExternalContext().getSessionMap().put(
- PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
- // response.setRenderParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
- // viewRoot.getViewId());
+ protected void saveView(FacesContext facesContext) {
+ PortletStateHolder portletStateHolder = PortletStateHolder.getInstance(facesContext);
+ PortletWindowStates states = portletStateHolder.getWindowStates(facesContext);
+ String viewId = facesContext.getViewRoot().getViewId();
+ states.setViewId(viewId);
+ PortletViewState state = states.getState(viewId);
+ state.save(facesContext);
}
/*
@@ -194,15 +196,20 @@
}
protected void restoreView(FacesContext facesContext) {
- Map sessionMap = facesContext.getExternalContext().getSessionMap();
- PortletViewState state = (PortletViewState) sessionMap
- .get(PortletViewState.SAVED_VIEW_ATTRIBUTE);
- if (null != state) {
- state.restore(facesContext);
- // sessionMap.remove(PortletViewState.SAVED_VIEW_ATTRIBUTE);
+ PortletStateHolder portletStateHolder = PortletStateHolder.getInstance(facesContext);
+ PortletWindowStates states = portletStateHolder.getWindowStates(facesContext);
+ String viewId = states.getViewId();
+ UIViewRoot viewRoot = null;
+ if(null != viewId){
+ PortletViewState viewState = states.getState(viewId);
+ viewRoot = viewState.restore(facesContext);
} else {
- setViewId(facesContext);
+ viewId = portletStateHolder.getViewId(facesContext);
}
+ if(null == viewRoot){
+ viewRoot = facesContext.getApplication().getViewHandler().createView(facesContext, viewId);
+ }
+ facesContext.setViewRoot(viewRoot);
}
/*
@@ -264,44 +271,14 @@
}
protected void setViewId(FacesContext context) {
- String viewId = null;
- Map sessionMap = context.getExternalContext().getSessionMap();
- PortletViewState state = (PortletViewState) sessionMap
- .get(PortletViewState.SAVED_VIEW_ATTRIBUTE);
- if (null != state) {
- viewId = state.getViewRoot().getViewId();
- }
- if (null == viewId) {
- Map requestParameterMap = context.getExternalContext()
- .getRequestParameterMap();
- viewId = (String) requestParameterMap
- .get(AbstractExternalContext.VIEW_ID_PARAMETER);
- } else if (log.isDebugEnabled()) {
- log.debug("Detect viewId from saved view state as " + viewId);
- }
- if (null == viewId) {
- viewId = getInitParameter("default-view");
- if (log.isDebugEnabled()) {
- log.debug("Set viewId to default value from portlet parameter "
- + viewId);
- }
- } else if (log.isDebugEnabled()) {
- log.debug("Detect viewId from request parameter as " + viewId);
- }
- if (null == viewId) {
- throw new IllegalArgumentException(
- "Initial view id must be set as portlet parameter");
- }
- // Store for simulate servlet environment compability.
+ PortletStateHolder portletStateHolder = PortletStateHolder.getInstance(context);
+ String viewId = portletStateHolder.getViewId(context);
context.getExternalContext().getRequestMap().put(
AbstractExternalContext.VIEW_ID_PARAMETER, viewId);
UIViewRoot viewRoot = context.getViewRoot();
- if (null == viewRoot) {
- viewRoot = context.getApplication().getViewHandler().createView(
- context, viewId);
- context.setViewRoot(viewRoot);
+ if (null != viewRoot) {
+ viewRoot.setViewId(viewId);
}
- viewRoot.setViewId(viewId);
}
/**
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-05-28 14:09:55 UTC (rev 221)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-05-30 00:10:55 UTC (rev 222)
@@ -39,6 +39,11 @@
UIViewRoot viewRoot = null;
if(isSavingStateInClient(context)){
viewRoot = super.restoreView(context, viewId, renderKitId);
+ } else {
+ PortletStateHolder portletStateHolder = PortletStateHolder.getInstance(context);
+ PortletWindowStates windowStates = portletStateHolder.getWindowStates(context);
+ PortletViewState viewState = windowStates.getState(viewId);
+ viewRoot = viewState.restore(context);
}
// TODO - implement portal-specific view state.
return viewRoot;
@@ -49,21 +54,18 @@
SerializedView serializedView = null;
if(isSavingStateInClient(context)){
serializedView = super.saveSerializedView(context);
+ } else {
+ // TODO - implement portal-specific view state saving.
+ PortletStateHolder portletStateHolder = PortletStateHolder.getInstance(context);
+ PortletWindowStates windowStates = portletStateHolder.getWindowStates(context);
+ String viewId = context.getViewRoot().getViewId();
+ windowStates.setViewId(viewId);
+ PortletViewState viewState = windowStates.getState(viewId);
+ viewState.save(context);
}
- // TODO - implement portal-specific view state saving.
return serializedView;
}
- public void writeState(FacesContext context, SerializedView state) throws IOException {
- String renderKitId = context.getViewRoot().getRenderKitId();
- RenderKit renderKit = context.getRenderKit();
- if(null == renderKit){
- RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- renderKit = renderKitFactory.getRenderKit(context, renderKitId);
- }
- ResponseStateManager responseStateManager = renderKit.getResponseStateManager();
- responseStateManager.writeState(context, state);
- }
private Map getStatesMap(FacesContext context){
Map stateMap;
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-05-28 14:09:55 UTC (rev 221)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-05-30 00:10:55 UTC (rev 222)
@@ -40,10 +40,10 @@
public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException {
super.renderView(context, root);
// Save view to use in portlet rendering phases
- PortletViewState state = new PortletViewState();
- state.save(context);
- context.getExternalContext().getSessionMap().put(
- PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
+// PortletViewState state = new PortletViewState();
+// state.save(context);
+// context.getExternalContext().getSessionMap().put(
+// PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
}
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-05-28 14:09:55 UTC (rev 221)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-05-30 00:10:55 UTC (rev 222)
@@ -17,6 +17,8 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
+import javax.portlet.ActionRequest;
+import javax.portlet.RenderRequest;
/**
* @author asmirnov
@@ -47,6 +49,15 @@
rootNode.apply(viewRoot);
setTreeStructure(rootNode);
setComponentsState(viewRoot.processSaveState(facesContext));
+ saveMessages(facesContext);
+ // facesContext.getExternalContext().getSessionMap().put(PortletViewState.SAVED_VIEW_ATTRIBUTE,
+ // this);
+ }
+
+ /**
+ * @param facesContext
+ */
+ public void saveMessages(FacesContext facesContext) {
Iterator idsWithMessages = facesContext.getClientIdsWithMessages();
while (idsWithMessages.hasNext()) {
String id = (String) idsWithMessages.next();
@@ -56,12 +67,29 @@
addMessage(id, message);
}
}
- // facesContext.getExternalContext().getSessionMap().put(PortletViewState.SAVED_VIEW_ATTRIBUTE,
- // this);
}
- public void restore(FacesContext facesContext) {
- facesContext.setViewRoot(getViewRoot());
+ public UIViewRoot restore(FacesContext facesContext) {
+ // facesContext.setViewRoot(getViewRoot());
+ TreeStrutureNode structure = (TreeStrutureNode) getTreeStructure();
+ UIViewRoot root = null;
+ if (null != structure) {
+ root = (UIViewRoot) structure.restore();
+ root.processRestoreState(facesContext, getComponentsState());
+ // facesContext.setViewRoot(root);
+ if (facesContext.getExternalContext().getRequest() instanceof RenderRequest) {
+ restoreMessages(facesContext);
+
+ }
+
+ }
+ return root;
+ }
+
+ /**
+ * @param facesContext
+ */
+ public void restoreMessages(FacesContext facesContext) {
Iterator idsWithMessages = getClientIdsWithMessages();
while (idsWithMessages.hasNext()) {
String id = (String) idsWithMessages.next();
@@ -71,7 +99,6 @@
facesContext.addMessage(id, message);
}
}
-
}
/**
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-05-28 14:09:55 UTC (rev 221)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-05-30 00:10:55 UTC (rev 222)
@@ -14,6 +14,11 @@
*/
public class PortletWindowStates implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3239697059998528947L;
+
private String viewId;
private Map viewStates;