Author: alexsmirnov
Date: 2007-05-07 21:18:42 -0400 (Mon, 07 May 2007)
New Revision: 184
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
Removed:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java
trunk/samples/tomahawkCompability/src/main/webapp/pages/tabbedPanel.jsp
Log:
start implementation of the special Portlet state manager.
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-05-07
22:57:59 UTC (rev 183)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -28,6 +28,7 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
+import org.ajax4jsf.portlet.application.PortletViewState;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -165,6 +166,7 @@
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.PORTLET_MODE_PARAMETER,request.getPortletMode().toString());
render(facesContext);
writer.println("</div>");
PortletSession portletSession = request.getPortletSession(true);
Deleted: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java 2007-05-07
22:57:59 UTC (rev 183)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -1,103 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.portlet;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-/**
- * @author asmirnov
- *
- */
-public class PortletViewState {
-
- public static final String SAVED_VIEW_ATTRIBUTE = PortletViewState.class.getName();
-
- private Map messages = new HashMap();
- private UIViewRoot viewRoot;
-
- public void save(FacesContext facesContext){
- UIViewRoot viewRoot = facesContext.getViewRoot();
- setViewRoot(viewRoot);
- Iterator idsWithMessages = facesContext.getClientIdsWithMessages();
- while (idsWithMessages.hasNext()) {
- String id = (String) idsWithMessages.next();
- Iterator messages = facesContext.getMessages(id);
- while (messages.hasNext()) {
- FacesMessage message = (FacesMessage) messages.next();
- addMessage(id, message);
- }
- }
-// facesContext.getExternalContext().getSessionMap().put(PortletViewState.SAVED_VIEW_ATTRIBUTE,
this);
- }
-
- public void restore(FacesContext facesContext) {
- facesContext.setViewRoot(getViewRoot());
- Iterator idsWithMessages = getClientIdsWithMessages();
- while (idsWithMessages.hasNext()) {
- String id = (String) idsWithMessages.next();
- Iterator messages = getMessages(id);
- while (messages.hasNext()) {
- FacesMessage message = (FacesMessage) messages.next();
- facesContext.addMessage(id, message);
- }
- }
-
- }
-
- /**
- * @return the _messages
- */
- public Map getMessages() {
- return messages;
- }
- /**
- * @param _messages the _messages to set
- */
- public void setMessages(Map _messages) {
- this.messages = _messages;
- }
- /**
- * @return the _viewRoot
- */
- public UIViewRoot getViewRoot() {
- return viewRoot;
- }
- /**
- * @param root the _viewRoot to set
- */
- public void setViewRoot(UIViewRoot root) {
- viewRoot = root;
- }
-
- public void addMessage(String clientId, FacesMessage message) {
- List list = (List) messages.get(clientId);
- if (list == null) {
- list = new ArrayList();
- messages.put(clientId, list);
- }
- list.add(message);
- }
-
- public Iterator getClientIdsWithMessages() {
- return (messages.keySet().iterator());
- }
-
- public Iterator getMessages(String clientId) {
- List list = (List) messages.get(clientId);
- if (list != null) {
- return (list.iterator());
- } else {
- return (Collections.EMPTY_LIST.iterator());
- }
- }
-
-}
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java
(rev 0)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortalStateManager.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -0,0 +1,83 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.application;
+
+import java.io.IOException;
+import java.util.Map;
+import javax.faces.FactoryFinder;
+import javax.faces.application.StateManager;
+import javax.faces.application.StateManager.SerializedView;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.ResponseStateManager;
+import org.ajax4jsf.framework.ajax.AjaxStateManager;
+import org.apache.commons.collections.map.LRUMap;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortalStateManager extends AjaxStateManager {
+
+ private static final String VIEW_STATES_MAP = PortalStateManager.class.getName();
+ /**
+ *
+ */
+ public PortalStateManager(StateManager parentStateManager) {
+ super(parentStateManager);
+ }
+
+ /* (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);
+ }
+ // TODO - implement portal-specific view state.
+ return viewRoot;
+
+ }
+
+ public SerializedView saveSerializedView(FacesContext context) {
+ SerializedView serializedView = null;
+ if(isSavingStateInClient(context)){
+ serializedView = super.saveSerializedView(context);
+ }
+ // TODO - implement portal-specific view state saving.
+ return serializedView;
+ }
+
+ public void writeState(FacesContext context, SerializedView state) throws IOException
{
+ String renderKitId = context.getViewRoot().getRenderKitId();
+ RenderKit renderKit = context.getRenderKit();
+ if(null == renderKit){
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = renderKitFactory.getRenderKit(context, renderKitId);
+ }
+ ResponseStateManager responseStateManager = renderKit.getResponseStateManager();
+ responseStateManager.writeState(context, state);
+ }
+
+ private Map getStatesMap(FacesContext context){
+ Map stateMap;
+ ExternalContext externalContext = context.getExternalContext();
+ Map sessionMap = externalContext.getSessionMap();
+ Object session = externalContext.getSession(false);
+ synchronized (session) {
+ stateMap = (Map) sessionMap.get(VIEW_STATES_MAP);
+ if(null == stateMap){
+ stateMap = new LRUMap();
+ sessionMap.put(VIEW_STATES_MAP, sessionMap);
+ }
+ }
+ return stateMap;
+ }
+
+}
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-05-07
22:57:59 UTC (rev 183)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -13,7 +13,6 @@
import javax.portlet.RenderResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
import org.ajax4jsf.framework.ajax.AjaxViewHandler;
-import org.ajax4jsf.portlet.PortletViewState;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
/**
@@ -56,7 +55,7 @@
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.NAMESPACE_PARAMETER,
renderResponse.getNamespace());
return portletURL.toString();
} else if(null!=portalActionURL){
return portalActionURL;
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
(rev 0)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -0,0 +1,103 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.application;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletViewState {
+
+ public static final String SAVED_VIEW_ATTRIBUTE = PortletViewState.class.getName();
+
+ private Map messages = new HashMap();
+ private UIViewRoot viewRoot;
+
+ public void save(FacesContext facesContext){
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ setViewRoot(viewRoot);
+ Iterator idsWithMessages = facesContext.getClientIdsWithMessages();
+ while (idsWithMessages.hasNext()) {
+ String id = (String) idsWithMessages.next();
+ Iterator messages = facesContext.getMessages(id);
+ while (messages.hasNext()) {
+ FacesMessage message = (FacesMessage) messages.next();
+ addMessage(id, message);
+ }
+ }
+// facesContext.getExternalContext().getSessionMap().put(PortletViewState.SAVED_VIEW_ATTRIBUTE,
this);
+ }
+
+ public void restore(FacesContext facesContext) {
+ facesContext.setViewRoot(getViewRoot());
+ Iterator idsWithMessages = getClientIdsWithMessages();
+ while (idsWithMessages.hasNext()) {
+ String id = (String) idsWithMessages.next();
+ Iterator messages = getMessages(id);
+ while (messages.hasNext()) {
+ FacesMessage message = (FacesMessage) messages.next();
+ facesContext.addMessage(id, message);
+ }
+ }
+
+ }
+
+ /**
+ * @return the _messages
+ */
+ public Map getMessages() {
+ return messages;
+ }
+ /**
+ * @param _messages the _messages to set
+ */
+ public void setMessages(Map _messages) {
+ this.messages = _messages;
+ }
+ /**
+ * @return the _viewRoot
+ */
+ public UIViewRoot getViewRoot() {
+ return viewRoot;
+ }
+ /**
+ * @param root the _viewRoot to set
+ */
+ public void setViewRoot(UIViewRoot root) {
+ viewRoot = root;
+ }
+
+ public void addMessage(String clientId, FacesMessage message) {
+ List list = (List) messages.get(clientId);
+ if (list == null) {
+ list = new ArrayList();
+ messages.put(clientId, list);
+ }
+ list.add(message);
+ }
+
+ public Iterator getClientIdsWithMessages() {
+ return (messages.keySet().iterator());
+ }
+
+ public Iterator getMessages(String clientId) {
+ List list = (List) messages.get(clientId);
+ if (list != null) {
+ return (list.iterator());
+ } else {
+ return (Collections.EMPTY_LIST.iterator());
+ }
+ }
+
+}
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-05-07
22:57:59 UTC (rev 183)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -104,6 +104,7 @@
*/
public static final String NAMESPACE_PARAMETER
="org.ajax4jsf.portlet.NAMESPACE";
public static final String ACTION__PARAMETER =
"org.ajax4jsf.portlet.ACTION_URL";
+ public static final Object PORTLET_MODE_PARAMETER =
"org.ajax4jsf.portlet.MODE";
// TODO - optimization.
private Map applicationMap;
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java 2007-05-07
22:57:59 UTC (rev 183)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java 2007-05-08
01:18:42 UTC (rev 184)
@@ -8,6 +8,7 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.framework.ajax.AjaxContext;
+import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
@@ -21,7 +22,7 @@
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
Object namespace =
context.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.NAMESPACE_PARAMETER);
- Object ajaxRequestParameter =
context.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.NAMESPACE_PARAMETER);
+ Object ajaxRequestParameter =
context.getExternalContext().getRequestParameterMap().get(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
if(!ajaxContext.isAjaxRequest() && null !=namespace && null !=
ajaxRequestParameter){
// Navigation case, encode portlet window marker
writer.startElement(HTML.DIV_ELEM, component);
@@ -34,7 +35,7 @@
super.doEncodeEnd(writer, context, component);
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
Object namespace =
context.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.NAMESPACE_PARAMETER);
- Object ajaxRequestParameter =
context.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.NAMESPACE_PARAMETER);
+ Object ajaxRequestParameter =
context.getExternalContext().getRequestParameterMap().get(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
if(!ajaxContext.isAjaxRequest() && null !=namespace && null !=
ajaxRequestParameter){
// Navigation case, encode portlet window marker
writer.endElement(HTML.DIV_ELEM);
Modified: trunk/samples/tomahawkCompability/src/main/webapp/pages/tabbedPanel.jsp
===================================================================
--- trunk/samples/tomahawkCompability/src/main/webapp/pages/tabbedPanel.jsp 2007-05-07
22:57:59 UTC (rev 183)
+++ trunk/samples/tomahawkCompability/src/main/webapp/pages/tabbedPanel.jsp 2007-05-08
01:18:42 UTC (rev 184)
@@ -31,7 +31,7 @@
</a4j:form>
<h2>Same form without user-provided ID</h2>
<f:subview id="subview">
- <a4j:form ajaxSubmit="true" reRender="counterB">
+ <a4j:form ajaxSubmit="true" reRender="counterB"
onsubmit="alert('onsubmit');">
<h:panelGrid columns="2" border="1">
<h:commandButton action="#{beanB.inc}" value="Increment" />
<h:commandLink value="Decrement"
action="#{beanB.dec}"></h:commandLink>