Author: alexsmirnov
Date: 2007-10-12 19:23:04 -0400 (Fri, 12 Oct 2007)
New Revision: 3356
Removed:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java
branches/3.1.x/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
branches/3.1.x/samples/ajaxPortlet/src/main/java/portal/Bean.java
branches/3.1.x/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
Log:
Merge fix for a
http://jira.jboss.com/jira/browse/RF-1109 from trunk
Merge portlet brige from trunk
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -26,13 +26,12 @@
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.servlet.ServletResponse;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.portlet.application.ComponentsLoader;
import org.ajax4jsf.portlet.application.ComponentsLoaderImpl;
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;
@@ -126,9 +125,9 @@
}
FacesContext facesContext = getFacesContext(request, response);
try {
- setViewId(facesContext);
+// setViewId(facesContext);
execute(facesContext);
- saveView(facesContext);
+// saveView(facesContext);
} catch (Exception e) {
log.error("Error processing execute lifecycle", e);
throw new PortletException("Error processing execute lifecycle ", e);
@@ -137,14 +136,6 @@
}
}
- 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);
- }
/*
* (non-Javadoc)
@@ -176,10 +167,11 @@
// TODO - configure html element and style/class.
writer.println("<div id='" + namespace + "'>");
// writer.flush();
- restoreView(facesContext);
+// restoreView(facesContext);
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
- ajaxContext.getCommonAjaxParameters().put(AbstractExternalContext.ACTION__PARAMETER,
facesContext.getApplication().getViewHandler().getActionURL(facesContext,
facesContext.getViewRoot().getViewId()));
+ ajaxContext.getCommonAjaxParameters().put(AbstractExternalContext.ACTION__PARAMETER,
response.createActionURL().toString());
ajaxContext.getCommonAjaxParameters().put(AbstractExternalContext.PORTLET_MODE_PARAMETER,request.getPortletMode().toString());
+
ajaxContext.getCommonAjaxParameters().put(AbstractExternalContext.NAMESPACE_PARAMETER,
namespace);
render(facesContext);
writer.println("</div>");
PortletSession portletSession = request.getPortletSession(true);
@@ -202,22 +194,6 @@
}
}
- protected void restoreView(FacesContext facesContext) {
- 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,getComponentLoader());
- } else {
- viewId = portletStateHolder.getViewId(facesContext);
- }
- if(null == viewRoot){
- viewRoot = facesContext.getApplication().getViewHandler().createView(facesContext,
viewId);
- }
- facesContext.setViewRoot(viewRoot);
- }
/*
* (non-Javadoc)
@@ -301,10 +277,11 @@
String namespace = null;
if (response instanceof RenderResponse) {
namespace = ((RenderResponse) response).getNamespace();
- } else if (null != externalContext.getRequestParameterMap().get(
- AbstractExternalContext.NAMESPACE_PARAMETER)) {
+ } else if (response instanceof ServletResponse) {
namespace = (String) externalContext.getRequestParameterMap().get(
AbstractExternalContext.NAMESPACE_PARAMETER);
+ } else {
+ throw new IllegalStateException("portlet Namespace not availible at this
phase");
}
return namespace;
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -84,6 +84,10 @@
if(null != actionUrl){
map.put(AbstractExternalContext.ACTION__PARAMETER, actionUrl);
}
+ String portletMode = (String)
facesContext.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.PORTLET_MODE_PARAMETER);
+ if(null != actionUrl){
+ map.put(AbstractExternalContext.PORTLET_MODE_PARAMETER, portletMode);
+ }
return map;
}
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -27,40 +27,30 @@
componentLoader = new ComponentsLoaderImpl();
}
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#restoreView(javax.faces.context.FacesContext,
java.lang.String, java.lang.String)
- */
- public UIViewRoot restoreView(FacesContext context, String viewId,
- String renderKitId) {
- 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,componentLoader);
- }
- // TODO - implement portal-specific view state.
- return viewRoot;
-
+
+ protected SerializedView saveStateInSession(FacesContext context,
+ Object treeStructure, Object state) {
+ PortletViewState windowState =
PortletStateHolder.getInstance(context).getWindowState(context);
+ windowState.setTreeStructure(treeStructure);
+ windowState.setComponentsState(state);
+ windowState.setViewRoot(context.getViewRoot());
+ String viewId = context.getViewRoot().getViewId();
+ windowState.setViewId(viewId);
+ return new SerializedView(viewId,null);
}
- public SerializedView saveSerializedView(FacesContext context) {
- 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);
- serializedView=new SerializedView(viewId,null);
- }
- return serializedView;
+ //@Override
+ protected Object[] restoreStateFromSession(FacesContext context,
+ String viewId, String renderKitId) {
+ Object[] state = new Object[2];
+ PortletViewState windowState =
PortletStateHolder.getInstance(context).getWindowState(context);
+ state[0]=windowState.getTreeStructure();
+ state[1]=windowState.getComponentsState();
+ return state;
}
+ public boolean isSavingStateInClient(FacesContext context) {
+ // Client side view saving is not applicable for portal.
+ return false;
+ }
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -49,13 +49,7 @@
*
* @param context
*/
- private PortletStateHolder(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- Object request = externalContext.getRequest();
- if (request instanceof PortletRequest) {
- PortletRequest portletRequest = (PortletRequest) request;
- lastMode = portletRequest.getPortletMode();
- }
+ private PortletStateHolder() {
}
/**
@@ -74,8 +68,12 @@
instance = (PortletStateHolder) sessionMap.get(STATE_HOLDER);
if (null == instance) {
// Create and store in session new state holder.
- instance = new PortletStateHolder(context);
-
+ instance = new PortletStateHolder();
+ Object request = externalContext.getRequest();
+ if (request instanceof PortletRequest) {
+ PortletRequest portletRequest = (PortletRequest) request;
+ instance.setLastMode(portletRequest.getPortletMode());
+ }
sessionMap.put(STATE_HOLDER, instance);
}
}
@@ -96,14 +94,8 @@
}
// Second - find stored viewId for a current state and namespace.
if (null == viewId) {
- viewId = getWindowStates(context).getViewId();
+ viewId = getWindowState(context).getViewId();
}
- // Third - check a request attribute
- if (null == viewId) {
- viewId = (String) context.getExternalContext()
- .getRequestParameterMap().get(
- AbstractExternalContext.VIEW_ID_PARAMETER);
- }
// If none of above happen, try to get default viewId for a current
// mode.
if (null == viewId) {
@@ -132,16 +124,15 @@
* @param context
* @return
*/
- public PortletWindowStates getWindowStates(FacesContext context) {
- String portletNamespace = AjaxFacesPortlet.getPortletNamespace(context);
+ public PortletViewState getWindowState(FacesContext context) {
PortletMode portletMode = AjaxFacesPortlet.getPortletMode(context);
if (null == portletMode) {
portletMode = lastMode;
}
- StateKey windowKey = new StateKey(portletMode, portletNamespace);
- PortletWindowStates state = (PortletWindowStates) states.get(windowKey);
+ StateKey windowKey = new StateKey(portletMode);
+ PortletViewState state = (PortletViewState) states.get(windowKey);
if (null == state) {
- state = new PortletWindowStates();
+ state = new PortletViewState();
states.put(windowKey, state);
}
return state;
@@ -160,7 +151,14 @@
private PortletMode mode;
private String namespace;
+
+
+ public StateKey(PortletMode mode) {
+ super();
+ this.mode = mode;
+ }
+
/**
* @param mode
* @param namespace
@@ -211,4 +209,18 @@
}
}
+
+ /**
+ * @return the lastMode
+ */
+ public PortletMode getLastMode() {
+ return lastMode;
+ }
+
+ /**
+ * @param lastMode the lastMode to set
+ */
+ public void setLastMode(PortletMode lastMode) {
+ this.lastMode = lastMode;
+ }
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -29,6 +29,11 @@
super(parent);
}
+
+ public void initView(FacesContext context) throws FacesException {
+ super.initView(context);
+ }
+
public UIViewRoot createView(FacesContext facesContext, String viewId) {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
boolean ajaxRequest = ajaxContext.isAjaxRequest(facesContext);
@@ -56,8 +61,8 @@
if (response instanceof RenderResponse) {
RenderResponse renderResponse = (RenderResponse) response;
PortletURL portletURL = renderResponse.createActionURL();
- portletURL.setParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
context.getViewRoot().getViewId());
- portletURL.setParameter(AbstractExternalContext.NAMESPACE_PARAMETER,
renderResponse.getNamespace());
+// portletURL.setParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
context.getViewRoot().getViewId());
+// portletURL.setParameter(AbstractExternalContext.NAMESPACE_PARAMETER,
renderResponse.getNamespace());
return portletURL.toString();
} else if(null!=portalActionURL){
return portalActionURL;
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -41,20 +41,45 @@
private Object componentsState;
private UIViewRoot viewRoot;
+
+ private String viewId;
+
+ private Map requestScopeBeans;
- public void save(FacesContext facesContext) {
- UIViewRoot viewRoot = facesContext.getViewRoot();
- // setViewRoot(viewRoot);
- TreeStrutureNode rootNode = new TreeStrutureNode();
- rootNode.apply(viewRoot);
- setTreeStructure(rootNode);
- setComponentsState(viewRoot.processSaveState(facesContext));
- saveMessages(facesContext);
- //
facesContext.getExternalContext().getSessionMap().put(PortletViewState.SAVED_VIEW_ATTRIBUTE,
- // this);
- }
/**
+ * @return the requestScopeBeans
+ */
+ public Map getRequestScopeBeans() {
+ return requestScopeBeans;
+ }
+
+
+ /**
+ * @param requestScopeBeans the requestScopeBeans to set
+ */
+ public void setRequestScopeBeans(Map requestScopeBeans) {
+ this.requestScopeBeans = requestScopeBeans;
+ }
+
+
+ /**
+ * @return the viewId
+ */
+ public String getViewId() {
+ return viewId;
+ }
+
+
+ /**
+ * @param viewId the viewId to set
+ */
+ public void setViewId(String viewId) {
+ this.viewId = viewId;
+ }
+
+
+ /**
* @param facesContext
*/
public void saveMessages(FacesContext facesContext) {
@@ -69,23 +94,7 @@
}
}
- public UIViewRoot restore(FacesContext facesContext,ComponentsLoader loader) {
- // facesContext.setViewRoot(getViewRoot());
- TreeStrutureNode structure = (TreeStrutureNode) getTreeStructure();
- UIViewRoot root = null;
- if (null != structure) {
- root = (UIViewRoot) structure.restore(loader);
- root.processRestoreState(facesContext, getComponentsState());
- // facesContext.setViewRoot(root);
- if (facesContext.getExternalContext().getRequest() instanceof RenderRequest) {
- restoreMessages(facesContext);
- }
-
- }
- return root;
- }
-
/**
* @param facesContext
*/
@@ -183,62 +192,4 @@
this.treeStructure = treeStructure;
}
- protected static class TreeStrutureNode implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -9038742487716977254L;
-
- private Map facets = new HashMap();
-
- private List children = new ArrayList();
-
- private String type;
-
- private String id;
-
- public void apply(UIComponent component) {
- type = component.getClass().getName();
- id = component.getId();
- Map componentFacets = component.getFacets();
- for (Iterator i = componentFacets.entrySet().iterator(); i
- .hasNext();) {
- Entry element = (Entry) i.next();
- UIComponent f = (UIComponent) element.getValue();
- if (!f.isTransient()) {
- TreeStrutureNode facet = new TreeStrutureNode();
- facet.apply(f);
- facets.put(element.getKey(), facet);
-
- }
- }
- for (Iterator i = component.getChildren().iterator(); i.hasNext();) {
- UIComponent child = (UIComponent) i.next();
- if (!child.isTransient()) {
- TreeStrutureNode t = new TreeStrutureNode();
- t.apply(child);
- children.add(t);
-
- }
- }
- }
-
- public UIComponent restore(ComponentsLoader loader) {
- UIComponent component;
- component = loader.createComponent(type);
- component.setId(id);
- for (Iterator i = facets.entrySet().iterator(); i.hasNext();) {
- Entry element = (Entry) i.next();
- UIComponent facet = ((TreeStrutureNode) element.getValue())
- .restore(loader);
- component.getFacets().put((String) element.getKey(), facet);
- }
- for (Iterator i = children.iterator(); i.hasNext();) {
- TreeStrutureNode node = (TreeStrutureNode) i.next();
- UIComponent child = node.restore(loader);
- component.getChildren().add(child);
- }
- return component;
- }
- }
}
Deleted:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -1,52 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.portlet.application;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import org.apache.commons.collections.map.LRUMap;
-
-/**
- * @author asmirnov
- *
- */
-public class PortletWindowStates implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 3239697059998528947L;
-
- private String viewId;
-
- private Map viewStates;
-
- public PortletWindowStates() {
- viewStates = new LRUMap();
- }
-
- /**
- * @return the viewId
- */
- public String getViewId() {
- return viewId;
- }
-
- /**
- * @param viewId the viewId to set
- */
- public void setViewId(String viewId) {
- this.viewId = viewId;
- }
-
- public PortletViewState getState(String viewId) {
- PortletViewState state = (PortletViewState) viewStates.get(viewId);
- if(null == state){
- state = new PortletViewState();
- viewStates.put(viewId, state);
- }
- return state;
- }
-}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -35,283 +35,289 @@
*
*/
public class PortletContextImpl extends AbstractExternalContext {
-
- private String namespace;
- public PortletContextImpl(PortletContext context, PortletRequest request,
- PortletResponse response) {
- super(context, request, response);
- }
-
- public void setResponseCharacterEncoding(String encoding) {
- // Do nothing
- }
-
- public String getResponseCharacterEncoding() {
- PortletResponse portletResponse = getPortletResponse();
- if (portletResponse instanceof RenderResponse) {
+ private String namespace;
+
+ public PortletContextImpl(PortletContext context, PortletRequest request,
+ PortletResponse response) {
+ super(context, request, response);
+ }
+
+ public void setResponseCharacterEncoding(String encoding) {
+ // Do nothing
+ }
+
+ public String getResponseCharacterEncoding() {
+ PortletResponse portletResponse = getPortletResponse();
+ if (portletResponse instanceof RenderResponse) {
RenderResponse renderResponse = (RenderResponse) portletResponse;
return renderResponse.getCharacterEncoding();
- }else {
+ } else {
return null;
}
- }
-
-
- public String getResponseContentType() {
- PortletResponse portletResponse = getPortletResponse();
- if (portletResponse instanceof RenderResponse) {
+ }
+
+ public String getResponseContentType() {
+ PortletResponse portletResponse = getPortletResponse();
+ if (portletResponse instanceof RenderResponse) {
RenderResponse renderResponse = (RenderResponse) portletResponse;
return renderResponse.getContentType();
- }else {
+ } else {
return null;
}
- }
+ }
- public void setRequestCharacterEncoding(String encoding)
- throws UnsupportedEncodingException {
- PortletRequest portletRequest = getPortletRequest();
- if (portletRequest instanceof ActionRequest) {
- ActionRequest actionRequest = (ActionRequest) portletRequest;
- actionRequest.setCharacterEncoding(encoding);
+ public void setRequestCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException {
+ PortletRequest portletRequest = getPortletRequest();
+ if (portletRequest instanceof ActionRequest) {
+ try {
+ ActionRequest actionRequest = (ActionRequest) portletRequest;
+ actionRequest.setCharacterEncoding(encoding);
+
+ } catch (IllegalStateException e) {
+ // TODO: handle exception
+ }
}
- }
-
- public String getRequestCharacterEncoding() {
- PortletRequest portletRequest = getPortletRequest();
- if (portletRequest instanceof ActionRequest) {
+ }
+
+ public String getRequestCharacterEncoding() {
+ PortletRequest portletRequest = getPortletRequest();
+ if (portletRequest instanceof ActionRequest) {
ActionRequest actionRequest = (ActionRequest) portletRequest;
return actionRequest.getCharacterEncoding();
} else {
return null;
}
- }
-
-
- public String getRequestContentType() {
- return null;
- }
+ }
- private PortletContext getPortletContext() {
- return (PortletContext) getContext();
- }
+ public String getRequestContentType() {
+ return null;
+ }
- private PortletRequest getPortletRequest() {
- return (PortletRequest) getRequest();
- }
+ private PortletContext getPortletContext() {
+ return (PortletContext) getContext();
+ }
- private PortletResponse getPortletResponse() {
- return (PortletResponse) getResponse();
- }
+ private PortletRequest getPortletRequest() {
+ return (PortletRequest) getRequest();
+ }
- public String getInitParameter(String name) {
- return getPortletContext().getInitParameter(name);
- }
+ private PortletResponse getPortletResponse() {
+ return (PortletResponse) getResponse();
+ }
- protected String getNamespace() {
- if (null == namespace) {
- if (getResponse() instanceof RenderResponse) {
- namespace = ((RenderResponse) getResponse()).getNamespace();
- } else if (null != getRequestParameter(NAMESPACE_PARAMETER)) {
- namespace = (String) getRequestParameter(NAMESPACE_PARAMETER);
- } else {
- namespace = "";
- }
+ public String getInitParameter(String name) {
+ return getPortletContext().getInitParameter(name);
}
- return namespace;
- }
- public URL getResource(String path) throws MalformedURLException {
- return getPortletContext().getResource(path);
- }
+ protected String getNamespace() {
+ if (null == namespace) {
+ if (getResponse() instanceof RenderResponse) {
+ namespace = ((RenderResponse) getResponse()).getNamespace();
+ } else {
+ throw new IllegalStateException(
+ "Portlet namespace not availible in processAction phase");
+ }
+ }
+ return namespace;
+ }
- public InputStream getResourceAsStream(String path) {
- return getPortletContext().getResourceAsStream(path);
- }
+ public URL getResource(String path) throws MalformedURLException {
+ return getPortletContext().getResource(path);
+ }
- public Set getResourcePaths(String path) {
- return getPortletContext().getResourcePaths(path);
- }
+ public InputStream getResourceAsStream(String path) {
+ return getPortletContext().getResourceAsStream(path);
+ }
- protected Enumeration enumerateRequestParameterNames() {
- return getPortletRequest().getParameterNames();
- }
+ public Set getResourcePaths(String path) {
+ return getPortletContext().getResourcePaths(path);
+ }
- protected Object getContextAttribute(String name) {
- return getPortletContext().getAttribute(name);
- }
+ protected Enumeration enumerateRequestParameterNames() {
+ return getPortletRequest().getParameterNames();
+ }
- protected Enumeration getContextAttributeNames() {
- return getPortletContext().getAttributeNames();
- }
+ protected Object getContextAttribute(String name) {
+ return getPortletContext().getAttribute(name);
+ }
- protected Enumeration getInitParametersNames() {
- return getPortletContext().getInitParameterNames();
- }
+ protected Enumeration getContextAttributeNames() {
+ return getPortletContext().getAttributeNames();
+ }
- protected Object getRequestAttribute(String name) {
- return getPortletRequest().getAttribute(name);
- }
+ protected Enumeration getInitParametersNames() {
+ return getPortletContext().getInitParameterNames();
+ }
- protected Enumeration getRequestAttributeNames() {
- return getPortletRequest().getAttributeNames();
- }
+ protected Object getRequestAttribute(String name) {
+ return getPortletRequest().getAttribute(name);
+ }
- public Map getRequestParameterValuesMap() {
- return getPortletRequest().getParameterMap();
- }
+ protected Enumeration getRequestAttributeNames() {
+ return getPortletRequest().getAttributeNames();
+ }
- protected Object getRequestParameterValues(String name) {
- return getPortletRequest().getParameterValues(name);
- }
+ public Map getRequestParameterValuesMap() {
+ return getPortletRequest().getParameterMap();
+ }
- protected Object getRequestHeader(String name) {
- return getPortletRequest().getProperty(name);
- }
+ protected Object getRequestParameterValues(String name) {
+ return getPortletRequest().getParameterValues(name);
+ }
- protected Enumeration getRequestHeaderNames() {
- return getPortletRequest().getPropertyNames();
- }
+ protected Object getRequestHeader(String name) {
+ return getPortletRequest().getProperty(name);
+ }
- protected String[] getRequestHeaderValues(String name) {
- Enumeration properties = getPortletRequest().getProperties(name);
- List values = new ArrayList();
- while (properties.hasMoreElements()) {
- Object value = (Object) properties.nextElement();
- values.add(value);
+ protected Enumeration getRequestHeaderNames() {
+ return getPortletRequest().getPropertyNames();
}
- return (String[]) values.toArray(EMPTY_STRING_ARRAY);
- }
- protected Object getRequestParameter(String name) {
- return getPortletRequest().getParameter(name);
- }
+ protected String[] getRequestHeaderValues(String name) {
+ Enumeration properties = getPortletRequest().getProperties(name);
+ List values = new ArrayList();
+ while (properties.hasMoreElements()) {
+ Object value = (Object) properties.nextElement();
+ values.add(value);
+ }
+ return (String[]) values.toArray(EMPTY_STRING_ARRAY);
+ }
- protected Object getSessionAttribute(String name) {
- return
getPortletRequest().getPortletSession(true).getAttribute(name,PortletSession.PORTLET_SCOPE);
- }
+ protected Object getRequestParameter(String name) {
+ return getPortletRequest().getParameter(name);
+ }
- protected Enumeration getSessionAttributeNames() {
- return
getPortletRequest().getPortletSession(true).getAttributeNames(PortletSession.PORTLET_SCOPE);
- }
+ protected Object getSessionAttribute(String name) {
+ return getPortletRequest().getPortletSession(true).getAttribute(name,
+ PortletSession.PORTLET_SCOPE);
+ }
- protected void removeContextAttribute(String name) {
- getPortletContext().removeAttribute(name);
- }
+ protected Enumeration getSessionAttributeNames() {
+ return getPortletRequest().getPortletSession(true).getAttributeNames(
+ PortletSession.PORTLET_SCOPE);
+ }
- protected void removeRequestAttribute(String name) {
- getPortletRequest().removeAttribute(name);
- }
+ protected void removeContextAttribute(String name) {
+ getPortletContext().removeAttribute(name);
+ }
- protected void removeSessionAttribute(String name) {
- getPortletRequest().getPortletSession(true).removeAttribute(name,PortletSession.PORTLET_SCOPE);
- }
+ protected void removeRequestAttribute(String name) {
+ getPortletRequest().removeAttribute(name);
+ }
- protected void setContextAttribute(String name, Object value) {
- getPortletContext().setAttribute(name, value);
- }
+ protected void removeSessionAttribute(String name) {
+ getPortletRequest().getPortletSession(true).removeAttribute(name,
+ PortletSession.PORTLET_SCOPE);
+ }
- protected void setRequestAttribute(String name, Object value) {
- getPortletRequest().setAttribute(name, value);
- }
+ protected void setContextAttribute(String name, Object value) {
+ getPortletContext().setAttribute(name, value);
+ }
- protected void setSessionAttribute(String name, Object value) {
- getPortletRequest().getPortletSession(true).setAttribute(name,
value,PortletSession.PORTLET_SCOPE);
- }
+ protected void setRequestAttribute(String name, Object value) {
+ getPortletRequest().setAttribute(name, value);
+ }
- public void dispatch(String path) throws IOException {
- if (null == path) {
- throw new NullPointerException("Path to new view is null");
+ protected void setSessionAttribute(String name, Object value) {
+ getPortletRequest().getPortletSession(true).setAttribute(name, value,
+ PortletSession.PORTLET_SCOPE);
}
- if (!(getRequest() instanceof RenderRequest && getResponse() instanceof
RenderResponse)) {
- throw new IllegalStateException(
- "Dispatch to new view not at render phase");
+
+ public void dispatch(String path) throws IOException {
+ if (null == path) {
+ throw new NullPointerException("Path to new view is null");
+ }
+ if (!(getRequest() instanceof RenderRequest && getResponse() instanceof
RenderResponse)) {
+ throw new IllegalStateException(
+ "Dispatch to new view not at render phase");
+ }
+ PortletRequestDispatcher dispatcher = getPortletContext()
+ .getRequestDispatcher(path);
+ if (null == dispatcher) {
+ throw new IllegalStateException(
+ "Dispatcher for render request is not created");
+ }
+ try {
+ dispatcher.include((RenderRequest) getRequest(),
+ (RenderResponse) getResponse());
+ } catch (PortletException e) {
+ throw new FacesException(e);
+ }
}
- PortletRequestDispatcher dispatcher = getPortletContext()
- .getRequestDispatcher(path);
- if (null == dispatcher) {
- throw new IllegalStateException(
- "Dispatcher for render request is not created");
+
+ public String encodeActionURL(String url) {
+ if (null == url) {
+ throw new NullPointerException();
+ }
+ return url;
}
- try {
- dispatcher.include((RenderRequest) getRequest(),
- (RenderResponse) getResponse());
- } catch (PortletException e) {
- throw new FacesException(e);
+
+ public String encodeResourceURL(String url) {
+ return getPortletResponse().encodeURL(url);
}
- }
- public String encodeActionURL(String url) {
- if (null == url) {
- throw new NullPointerException();
+ public String getAuthType() {
+ return getPortletRequest().getAuthType();
}
- return url;
- }
- public String encodeResourceURL(String url) {
- return getPortletResponse().encodeURL(url);
- }
+ public String getRemoteUser() {
+ return getPortletRequest().getRemoteUser();
+ }
- public String getAuthType() {
- return getPortletRequest().getAuthType();
- }
+ public String getRequestContextPath() {
+ return getPortletRequest().getContextPath();
+ }
- public String getRemoteUser() {
- return getPortletRequest().getRemoteUser();
- }
+ public Locale getRequestLocale() {
+ return getPortletRequest().getLocale();
+ }
- public String getRequestContextPath() {
- return getPortletRequest().getContextPath();
- }
+ public Iterator getRequestLocales() {
+ return new EnumerationIterator(getPortletRequest().getLocales());
+ }
- public Locale getRequestLocale() {
- return getPortletRequest().getLocale();
- }
+ public String getRequestPathInfo() {
+ String pathInfo = (String) getRequestParameter(VIEW_ID_PARAMETER);
+ if (null == pathInfo) {
+ pathInfo = (String) getRequestAttribute(VIEW_ID_PARAMETER);
+ }
+ return pathInfo;
+ }
- public Iterator getRequestLocales() {
- return new EnumerationIterator(getPortletRequest().getLocales());
- }
+ public String getRequestServletPath() {
+ return null;
+ }
- public String getRequestPathInfo() {
- String pathInfo = (String) getRequestParameter(VIEW_ID_PARAMETER);
- if(null== pathInfo){
- pathInfo = (String) getRequestAttribute(VIEW_ID_PARAMETER);
+ public Object getSession(boolean create) {
+ return getPortletRequest().getPortletSession();
}
- return pathInfo;
- }
- public String getRequestServletPath() {
- return null;
- }
+ public Principal getUserPrincipal() {
+ return getPortletRequest().getUserPrincipal();
+ }
- public Object getSession(boolean create) {
- return getPortletRequest().getPortletSession();
- }
+ public boolean isUserInRole(String role) {
+ return getPortletRequest().isUserInRole(role);
+ }
- public Principal getUserPrincipal() {
- return getPortletRequest().getUserPrincipal();
- }
+ public void log(String message) {
+ getPortletContext().log(message);
+ }
- public boolean isUserInRole(String role) {
- return getPortletRequest().isUserInRole(role);
- }
+ public void log(String message, Throwable exception) {
+ getPortletContext().log(message, exception);
+ }
- public void log(String message) {
- getPortletContext().log(message);
- }
-
- public void log(String message, Throwable exception) {
- getPortletContext().log(message, exception);
- }
-
- public void redirect(String url) throws IOException {
- if (null == url) {
- throw new NullPointerException("Path to redirect is null");
+ public void redirect(String url) throws IOException {
+ if (null == url) {
+ throw new NullPointerException("Path to redirect is null");
+ }
+ if (!(getRequest() instanceof ActionRequest && getResponse() instanceof
ActionResponse)) {
+ throw new IllegalStateException(
+ "Redirect to new url not at action phase");
+ }
+ ((ActionResponse) getResponse()).sendRedirect(url);
}
- if (!(getRequest() instanceof ActionRequest && getResponse() instanceof
ActionResponse)) {
- throw new IllegalStateException(
- "Redirect to new url not at action phase");
- }
- ((ActionResponse) getResponse()).sendRedirect(url);
- }
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -49,7 +49,7 @@
while (names.hasMoreElements() && null == next) {
String name = (String) names.nextElement();
if(name.startsWith(prefix)){
- next = name.substring(0, prefix.length());
+ next = name.substring(prefix.length());
}
}
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -5,7 +5,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
/**
@@ -21,21 +20,20 @@
*/
public ApplyValuesPhase(Lifecycle lifecycle) {
super(lifecycle);
- nextPhase = new UpdateModelPhase(lifecycle);
+ nextPhase = new ProcessValidatorsPhase(lifecycle);
}
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
javax.faces.event.PhaseListener[])
*/
- protected void executeNextPhase(FacesContext context,
- PhaseListener[] listeners) {
- nextPhase.execute(context, listeners);
+ protected void executeNextPhase(FacesContext context) {
+ nextPhase.execute(context);
}
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
+ public void executePhase(FacesContext context) {
context.getViewRoot().processDecodes(context);
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -5,7 +5,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
/**
@@ -24,8 +23,7 @@
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
javax.faces.event.PhaseListener[])
*/
- protected void executeNextPhase(FacesContext context,
- PhaseListener[] listeners) {
+ protected void executeNextPhase(FacesContext context) {
// do nothing.
}
@@ -33,7 +31,7 @@
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
+ public void executePhase(FacesContext context) {
context.getViewRoot().processApplication(context);
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -33,11 +33,11 @@
/**
* Execute phase methods with
* @param context
- * @param listeners
*/
- public void execute(FacesContext context,PhaseListener[] listeners){
+ public void execute(FacesContext context){
int listenerToCall = 0;
- PhaseEvent event = new PhaseEvent(context,getPhaseId(),_lifecycle);
+ PhaseEvent event = new PhaseEvent(context,getPhaseId(),getLifecycle());
+ PhaseListener[] listeners = getLifecycle().getPhaseListeners();
// Execute listeners before phase.
try {
for(;listenerToCall<listeners.length;listenerToCall++){
@@ -71,22 +71,20 @@
}
if(!context.getRenderResponse() && !context.getResponseComplete()){
- executeNextPhase(context,listeners);
+ executeNextPhase(context);
}
}
/**
* @param context
- * @param listeners
*/
- protected abstract void executeNextPhase(FacesContext context,
- PhaseListener[] listeners);
+ protected abstract void executeNextPhase(FacesContext context);
/**
* @param context
*/
- protected abstract void executePhase(FacesContext context);
+ public abstract void executePhase(FacesContext context);
/**
@@ -99,4 +97,12 @@
return 0 == getPhaseId().compareTo(phaseId) || 0 ==
PhaseId.ANY_PHASE.compareTo(phaseId);
}
+
+ /**
+ * @return the lifecycle
+ */
+ public Lifecycle getLifecycle() {
+ return _lifecycle;
+ }
+
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -3,14 +3,23 @@
*/
package org.ajax4jsf.portlet.lifecycle;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
+import javax.portlet.PortletRequest;
+import org.ajax4jsf.portlet.application.PortletStateHolder;
+import org.ajax4jsf.portlet.application.PortletViewState;
+
/**
* @author asmirnov
*
@@ -79,7 +88,27 @@
* @see javax.faces.lifecycle.Lifecycle#execute(javax.faces.context.FacesContext)
*/
public void execute(FacesContext context) throws FacesException {
- executePhase.execute(context, getPhaseListeners());
+ executePhase.execute(context);
+ // TODO - in the portlet mode, save state
+ Object request = context.getExternalContext().getRequest();
+ if(request instanceof PortletRequest){
+ context.getApplication().getStateManager().saveSerializedView(context);
+ }
+ // TODO - save request scope variables and Faces Messages.
+ PortletViewState windowState =
PortletStateHolder.getInstance(context).getWindowState(context);
+ windowState.saveMessages(context);
+ HashMap requestScopeBeans = new HashMap();
+ for (Iterator iterator =
context.getExternalContext().getRequestMap().entrySet().iterator(); iterator.hasNext();)
{
+ Entry entry = (Entry) iterator.next();
+ String paramName = entry.getKey().toString();
+ Object bean = entry.getValue();
+ if(!paramName.contains(".") && bean instanceof Serializable){
+ requestScopeBeans.put(paramName, bean);
+ }
+ }
+ if(requestScopeBeans.size()>0){
+ windowState.setRequestScopeBeans(requestScopeBeans);
+ }
}
/**
@@ -88,7 +117,18 @@
* @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
*/
public void render(FacesContext context) throws FacesException {
- renderPhase.execute(context, getPhaseListeners());
+ // TODO - in the portlet mode, restore state, request scope variables and Faces
Messages.
+ Object request = context.getExternalContext().getRequest();
+ if(request instanceof PortletRequest){
+ executePhase.executePhase(context);
+ PortletViewState windowState =
PortletStateHolder.getInstance(context).getWindowState(context);
+ windowState.restoreMessages(context);
+ Map requestScopeBeans = windowState.getRequestScopeBeans();
+ if(null != requestScopeBeans){
+ context.getExternalContext().getRequestMap().putAll(requestScopeBeans);
+ }
+ }
+ renderPhase.execute(context);
}
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -5,7 +5,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
/**
@@ -27,16 +26,15 @@
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
javax.faces.event.PhaseListener[])
*/
- protected void executeNextPhase(FacesContext context,
- PhaseListener[] listeners) {
- nextPhase.execute(context, listeners);
+ protected void executeNextPhase(FacesContext context) {
+ nextPhase.execute(context);
}
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
+ public void executePhase(FacesContext context) {
context.getViewRoot().processValidators(context);
}
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -8,7 +8,6 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
/**
@@ -27,8 +26,7 @@
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
javax.faces.event.PhaseListener[])
*/
- protected void executeNextPhase(FacesContext context,
- PhaseListener[] listeners) {
+ protected void executeNextPhase(FacesContext context) {
// do nothing.
}
@@ -36,7 +34,7 @@
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
+ public void executePhase(FacesContext context) {
try {
context.getApplication().getViewHandler().
renderView(context, context.getViewRoot());
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -3,17 +3,32 @@
*/
package org.ajax4jsf.portlet.lifecycle;
+import java.util.Iterator;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.servlet.ServletRequest;
+import org.ajax4jsf.portlet.application.PortletStateHolder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* @author asmirnov
- *
+ *
*/
public class RestoreViewPhase extends LifecyclePhase {
-
+
+ private static final Log _log = LogFactory.getLog(RestoreViewPhase.class);
+
private final LifecyclePhase nextPhase;
/**
@@ -24,23 +39,96 @@
nextPhase = new ApplyValuesPhase(lifecycle);
}
- /* (non-Javadoc)
- * @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
javax.faces.event.PhaseListener[])
+ public void execute(FacesContext context) {
+ context.getApplication().getViewHandler().initView(context);
+ super.execute(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
+ * javax.faces.event.PhaseListener[])
*/
- protected void executeNextPhase(FacesContext context,
- PhaseListener[] listeners) {
- nextPhase.execute(context, listeners);
+ protected void executeNextPhase(FacesContext context) {
+ nextPhase.execute(context);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
- // TODO Auto-generated method stub
+ public void executePhase(FacesContext context) {
+ // Check pre-created ViewRoot.
+ UIViewRoot viewRoot = context.getViewRoot();
+ if (null != viewRoot) {
+ if (_log.isDebugEnabled()) {
+ _log.debug("Found created UIViewRoot in facesContext");
+ }
+ viewRoot.setLocale(context.getExternalContext().getRequestLocale());
+ processBindings(context, viewRoot);
+ } else {
+ // Restore or Create new view.
+ String viewId = calculateViewId(context);
+ ViewHandler viewHandler = context.getApplication().getViewHandler();
+ if (isFacesRequest(context)) {
+ // TODO - check for a null and throw exception.
+ viewRoot = viewHandler.restoreView(context, viewId);
+ if (null != viewRoot) {
+ processBindings(context, viewRoot);
+ }
+ } else {
+ viewRoot = viewHandler.createView(context, viewId);
+ }
+ context.setViewRoot(viewRoot);
+ }
+ }
+ private boolean isFacesRequest(FacesContext context) {
+ // Check request for a "postback"
+ String renderKitId = context.getApplication().getViewHandler()
+ .calculateRenderKitId(context);
+ return getRenderKit(context, renderKitId).getResponseStateManager()
+ .isPostback(context);
}
- /* (non-Javadoc)
+ private RenderKit getRenderKit(FacesContext context, String renderKitId) {
+ // TODO - cache renderKitFactory instance.
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ return renderKitFactory.getRenderKit(context, renderKitId);
+ }
+
+ private String calculateViewId(FacesContext context) {
+ String viewId;
+ if (context.getExternalContext().getRequest() instanceof ServletRequest) {
+ viewId = context.getExternalContext().getRequestPathInfo();
+ if (null == viewId) {
+ viewId = context.getExternalContext().getRequestServletPath();
+ }
+
+ } else {
+ viewId = PortletStateHolder.getInstance(context).getViewId(context);
+ }
+ return viewId;
+ }
+
+ private void processBindings(FacesContext context, UIComponent component) {
+ ValueBinding binding = component.getValueBinding("binding");
+ if (null != binding) {
+ binding.setValue(context, component);
+ }
+ for (Iterator iterator = component.getFacetsAndChildren(); iterator
+ .hasNext();) {
+ UIComponent child = (UIComponent) iterator.next();
+ processBindings(context, child);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.portlet.lifecycle.LifecyclePhase#getPhaseId()
*/
protected PhaseId getPhaseId() {
Modified:
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -5,7 +5,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
/**
@@ -26,18 +25,16 @@
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext,
javax.faces.event.PhaseListener[])
*/
- protected void executeNextPhase(FacesContext context,
- PhaseListener[] listeners) {
- nextPhase.execute(context, listeners);
+ protected void executeNextPhase(FacesContext context) {
+ nextPhase.execute(context);
}
/* (non-Javadoc)
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
- // TODO Auto-generated method stub
-
+ public void executePhase(FacesContext context) {
+ context.getViewRoot().processUpdates(context);
}
/* (non-Javadoc)
Modified:
branches/3.1.x/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java
===================================================================
---
branches/3.1.x/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -4,16 +4,12 @@
import java.util.Map;
import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
import org.ajax4jsf.portlet.AbstractAjax4jsfPortletTestCase;
-import org.ajax4jsf.portlet.application.PortletViewState.TreeStrutureNode;
-import junit.framework.TestCase;
-
public class PortletViewStateTestCase extends AbstractAjax4jsfPortletTestCase {
ComponentsLoaderImpl loader;
@@ -32,15 +28,6 @@
super.tearDown();
}
- public final void testSave() {
- setupActionRequest();
- setupTree();
- PortletViewState state = new PortletViewState();
- state.save(facesContext);
- assertNotNull(state.getComponentsState());
- Object treeStructure = state.getTreeStructure();
- assertTrue(treeStructure instanceof TreeStrutureNode);
- }
/**
*
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -75,7 +75,7 @@
private final ComponentsLoader componentLoader;
- private int viewSequence = 0;
+ private volatile int viewSequence = 0;
private Object viewSequenceMutex = "MUTEX";
@@ -146,12 +146,12 @@
}
} });
- if(_log.isDebugEnabled()){
+ if (_log.isDebugEnabled()) {
_log.debug("Create instance of the SeamStateManager");
}
} catch (Exception e) {
seamStateManager = null;
- if(_log.isDebugEnabled()){
+ if (_log.isDebugEnabled()) {
_log.debug("SeamStateManager is not present");
}
}
@@ -225,24 +225,26 @@
ResponseStateManager responseStateManager = getRenderKit(context,
renderKitId).getResponseStateManager();
TreeStrutureNode treeStructure = null;
- Object state = null;
+ Object[] state = null;
if (isSavingStateInClient(context)) {
treeStructure = (TreeStrutureNode) responseStateManager
.getTreeStructureToRestore(context, viewId);
// viewRoot = parent.restoreView(context, viewId, renderKitId);
- state = responseStateManager.getComponentStateToRestore(context);
+ state = (Object[]) responseStateManager
+ .getComponentStateToRestore(context);
} else {
Object[] serializedView = restoreStateFromSession(context, viewId,
renderKitId);
if (null != serializedView) {
treeStructure = (TreeStrutureNode) serializedView[0];
- state = serializedView[1];
+ state = (Object[]) serializedView[1];
}
}
if (null != treeStructure) {
viewRoot = (UIViewRoot) treeStructure.restore(componentLoader);
if (null != viewRoot && null != state) {
- viewRoot.processRestoreState(context, state);
+ viewRoot.processRestoreState(context, state[0]);
+ restoreAdditionalState(context, state[1]);
}
}
return viewRoot;
@@ -324,41 +326,63 @@
SerializedView serializedView = null;
UIViewRoot viewRoot = context.getViewRoot();
if (!viewRoot.isTransient()) {
- TreeStrutureNode treeState = new TreeStrutureNode();
- treeState.apply(context, viewRoot, new HashSet());
- Object state = viewRoot.processSaveState(context);
+ TreeStrutureNode treeStructure = new TreeStrutureNode();
+ treeStructure.apply(context, viewRoot, new HashSet());
+ Object treeState = viewRoot.processSaveState(context);
+ Object state[] = { treeState, getAdditionalState(context) };
if (isSavingStateInClient(context)) {
- serializedView = new SerializedView(treeState, state);
+ serializedView = new SerializedView(treeStructure, state);
} else {
- ExternalContext externalContext = context.getExternalContext();
- Object session = externalContext.getSession(true);
- synchronized (session) {
- LRUMap viewStates = (LRUMap) externalContext
- .getSessionMap().get(VIEW_STATES_MAP);
- if (null == viewStates) {
- viewStates = new LRUMap(
- getNumberOfViews(externalContext));
- externalContext.getSessionMap().put(VIEW_STATES_MAP,
- viewStates);
- }
- Object id = getNextViewId(context);
- LRUMap logicalViewsMap = (LRUMap) viewStates.get(viewRoot
- .getViewId());
- if (null == logicalViewsMap) {
- logicalViewsMap = new LRUMap(
- getNumberOfViews(externalContext));
- }
- // Renew last seen view.
- viewStates.put(viewRoot.getViewId(), logicalViewsMap);
- logicalViewsMap.put(id, new Object[] { treeState, state });
- serializedView = new SerializedView(id, null);
- }
+ serializedView = saveStateInSession(context, treeStructure,
+ state);
}
}
return serializedView;
}
+ /**
+ * @param context
+ * @param treeStructure
+ * @param state
+ * @return
+ */
+ protected SerializedView saveStateInSession(FacesContext context,
+ Object treeStructure, Object state) {
+ SerializedView serializedView;
+ UIViewRoot viewRoot = context.getViewRoot();
+ ExternalContext externalContext = context.getExternalContext();
+ Object session = externalContext.getSession(true);
+ synchronized (session) {
+ LRUMap viewStates = (LRUMap) externalContext.getSessionMap().get(
+ VIEW_STATES_MAP);
+ if (null == viewStates) {
+ viewStates = new LRUMap(getNumberOfViews(externalContext));
+ externalContext.getSessionMap()
+ .put(VIEW_STATES_MAP, viewStates);
+ }
+ Object id = getNextViewId(context);
+ LRUMap logicalViewsMap = (LRUMap) viewStates.get(viewRoot
+ .getViewId());
+ if (null == logicalViewsMap) {
+ logicalViewsMap = new LRUMap(getNumberOfViews(externalContext));
+ }
+ // Renew last seen view.
+ viewStates.put(viewRoot.getViewId(), logicalViewsMap);
+ logicalViewsMap.put(id, new Object[] { treeStructure, state });
+ serializedView = new SerializedView(id, null);
+ }
+ return serializedView;
+ }
+
+ protected Object getAdditionalState(FacesContext context) {
+ return null;
+ }
+
+ protected void restoreAdditionalState(FacesContext context, Object state) {
+
+ }
+
protected Object getNextViewId(FacesContext context) {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
if (ajaxContext.isAjaxRequest(context)) {
@@ -372,8 +396,8 @@
if (viewSequence++ == Character.MAX_VALUE) {
viewSequence = 0;
}
- return UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
}
+ return UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
}
protected int getNumberOfViews(ExternalContext externalContext) {
@@ -394,7 +418,7 @@
/**
* TODO - implement Externalizable to reduce serialized state.
*/
- private static final long serialVersionUID = -9038742487716977254L;
+ private static final long serialVersionUID = -9038742487716977911L;
private static final String NULL_ID = "";
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java 2007-10-12
22:45:06 UTC (rev 3355)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java 2007-10-12
23:23:04 UTC (rev 3356)
@@ -179,7 +179,7 @@
} else {
// Invoke after phase listeners, in reverse order.
- for (int i = phaseListeners.length - 1; i > 0; i--) {
+ for (int i = phaseListeners.length - 1; i >= 0; i--) {
PhaseListener phaseListener = phaseListeners[i];
invokePhaseListener(phaseListener, phaseEvent, beforePhase);
}
Modified: branches/3.1.x/samples/ajaxPortlet/src/main/java/portal/Bean.java
===================================================================
--- branches/3.1.x/samples/ajaxPortlet/src/main/java/portal/Bean.java 2007-10-12 22:45:06
UTC (rev 3355)
+++ branches/3.1.x/samples/ajaxPortlet/src/main/java/portal/Bean.java 2007-10-12 23:23:04
UTC (rev 3356)
@@ -14,6 +14,10 @@
private String text ="";
+ public Bean() {
+ text="start";
+ counter=1;
+ }
/**
* @return the counter
*/
Modified: branches/3.1.x/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- branches/3.1.x/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-10-12
22:45:06 UTC (rev 3355)
+++ branches/3.1.x/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-10-12
23:23:04 UTC (rev 3356)
@@ -21,16 +21,6 @@
<to-view-id>/jsf/start.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
- <render-kit>
- <renderer>
- <description>override the viewroot</description>
- <component-family>javax.faces.ViewRoot</component-family>
- <renderer-type>javax.faces.ViewRoot</renderer-type>
- <renderer-class>
- org.ajax4jsf.portlet.renderkit.portlet.PortletAjaxViewRootRenderer
- </renderer-class>
- </renderer>
- </render-kit>
<application>
<view-handler>
org.ajax4jsf.portlet.application.PortletViewHandler
@@ -46,6 +36,9 @@
<faces-context-factory>
org.ajax4jsf.portlet.context.FacesContextFactoryImpl
</faces-context-factory>
+ <lifecycle-factory>
+ org.ajax4jsf.portlet.lifecycle.PortletLifecycleFactory
+ </lifecycle-factory>
</factory>
<managed-bean>