Author: alexsmirnov
Date: 2007-10-11 21:04:40 -0400 (Thu, 11 Oct 2007)
New Revision: 3336
Removed:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
Log:
Portlet framework start worked with Jboss Portal 2.6
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -27,40 +27,26 @@
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) {
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -96,14 +96,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 +126,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 +153,14 @@
private PortletMode mode;
private String namespace;
+
+
+ public StateKey(PortletMode mode) {
+ super();
+ this.mode = mode;
+ }
+
/**
* @param mode
* @param namespace
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/SessionAttributesNames.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ApplyValuesPhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -20,7 +20,7 @@
*/
public ApplyValuesPhase(Lifecycle lifecycle) {
super(lifecycle);
- nextPhase = new UpdateModelPhase(lifecycle);
+ nextPhase = new ProcessValidatorsPhase(lifecycle);
}
/* (non-Javadoc)
@@ -33,7 +33,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().processDecodes(context);
}
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/InvokeApplicationPhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -31,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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/LifecyclePhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -84,7 +84,7 @@
/**
* @param context
*/
- protected abstract void executePhase(FacesContext context);
+ public abstract void executePhase(FacesContext context);
/**
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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
*
@@ -80,6 +89,26 @@
*/
public void execute(FacesContext context) throws FacesException {
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,6 +117,17 @@
* @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
*/
public void render(FacesContext context) throws FacesException {
+ // 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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/ProcessValidatorsPhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -34,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) {
context.getViewRoot().processValidators(context);
}
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RenderResponsePhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -34,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:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -7,6 +7,7 @@
import javax.el.ELContext;
import javax.el.ValueExpression;
+import javax.faces.FactoryFinder;
import javax.faces.application.ViewHandler;
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
@@ -14,16 +15,20 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
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;
@@ -36,33 +41,44 @@
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) {
nextPhase.execute(context);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see
org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
*/
- protected void executePhase(FacesContext context) {
+ public void executePhase(FacesContext context) {
// Check pre-created ViewRoot.
UIViewRoot viewRoot = context.getViewRoot();
ELContext elContext = context.getELContext();
- if(null != viewRoot){
- if(_log.isDebugEnabled()){
+ if (null != viewRoot) {
+ if (_log.isDebugEnabled()) {
_log.debug("Found created UIViewRoot in facesContext");
}
viewRoot.setLocale(context.getExternalContext().getRequestLocale());
- processBindings(elContext,viewRoot);
+ processBindings(elContext, viewRoot);
} else {
// Restore or Create new view.
String viewId = calculateViewId(context);
ViewHandler viewHandler = context.getApplication().getViewHandler();
- if(isFacesRequest(context)){
+ if (isFacesRequest(context)) {
+ // TODO - check for a null and throw exception.
viewRoot = viewHandler.restoreView(context, viewId);
- if(null != viewRoot){
+ if (null != viewRoot) {
processBindings(elContext, viewRoot);
}
} else {
@@ -73,30 +89,49 @@
}
private boolean isFacesRequest(FacesContext context) {
- // TODO Auto-generated method stub
- return false;
+ // Check request for a "postback"
+ String renderKitId = context.getApplication().getViewHandler()
+ .calculateRenderKitId(context);
+ return getRenderKit(context, renderKitId).getResponseStateManager()
+ .isPostback(context);
}
+ 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 = context.getExternalContext().getRequestPathInfo();
- if(null == viewId){
- viewId = context.getExternalContext().getRequestServletPath();
+ 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(ELContext elContext, UIComponent component) {
ValueExpression binding = component.getValueExpression("binding");
- if(null != binding){
+ if (null != binding) {
binding.setValue(elContext, component);
}
- for (Iterator iterator = component.getFacetsAndChildren(); iterator.hasNext();) {
+ for (Iterator iterator = component.getFacetsAndChildren(); iterator
+ .hasNext();) {
UIComponent child = (UIComponent) iterator.next();
processBindings(elContext, child);
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.portlet.lifecycle.LifecyclePhase#getPhaseId()
*/
protected PhaseId getPhaseId() {
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/UpdateModelPhase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -33,9 +33,8 @@
/* (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:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java
===================================================================
---
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -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:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-11
19:00:36 UTC (rev 3335)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-12
01:04:40 UTC (rev 3336)
@@ -225,24 +225,25 @@
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 +325,66 @@
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)) {
Modified: trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java
===================================================================
--- trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java 2007-10-11 19:00:36 UTC (rev
3335)
+++ trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java 2007-10-12 01:04:40 UTC (rev
3336)
@@ -14,6 +14,10 @@
private String text ="";
+ public Bean() {
+ text="start";
+ counter=1;
+ }
/**
* @return the counter
*/
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-10-11 19:00:36
UTC (rev 3335)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-10-12 01:04:40
UTC (rev 3336)
@@ -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>