[ajax4jsf-svn-commits] JBoss Ajax4JSF SVN: r219 - trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application.

ajax4jsf-svn-commits at lists.jboss.org ajax4jsf-svn-commits at lists.jboss.org
Thu May 24 20:16:48 EDT 2007


Author: alexsmirnov
Date: 2007-05-24 20:16:48 -0400 (Thu, 24 May 2007)
New Revision: 219

Modified:
   trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
   trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
   trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
Log:
CODING IN PROGRESS - issue RF-186: Portlet integration for JBoss Portal, portals jsr-168 
http://jira.jboss.com/jira/browse/RF-186

Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java	2007-05-24 17:22:32 UTC (rev 218)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java	2007-05-25 00:16:48 UTC (rev 219)
@@ -7,11 +7,15 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
+import javax.portlet.PortletConfig;
 import javax.portlet.PortletMode;
 import javax.portlet.PortletRequest;
 
+import org.ajax4jsf.portlet.AjaxFacesPortlet;
+import org.ajax4jsf.portlet.context.AbstractExternalContext;
 import org.apache.commons.collections.map.LRUMap;
 
 /**
@@ -19,12 +23,19 @@
  * 
  */
 public class PortletStateHolder implements Serializable {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 3040262189850562853L;
+
     private static final String STATE_HOLDER = PortletStateHolder.class
 	    .getName();
 
     private static final String[] modes = { PortletMode.VIEW.toString(),
 	    PortletMode.EDIT.toString(), PortletMode.HELP.toString() };
 
+    private static final String DEFAULT = "defauil-";
+    
     private PortletMode lastMode = PortletMode.VIEW;
 
     /**
@@ -72,26 +83,69 @@
 	return instance;
     }
 
+    /**
+     * Calculate viewId for a portlet content.
+     * @param context
+     * @return
+     */
     public String getViewId(FacesContext context) {
 	String viewId = null;
 	// First - check for a existing viewId.
 	if(null != context.getViewRoot()){
 	    viewId = context.getViewRoot().getViewId();
 	}
+	// Second - find stored viewId for a current state and namespace.
 	if(null == viewId){
-	    
+	    viewId = getWindowStates(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.
+	PortletConfig config = (PortletConfig) context.getExternalContext().getApplicationMap().get(AjaxFacesPortlet.PORTLET_CONFIG);
+	if (null == viewId && null != config) {
+		PortletMode portletMode = AjaxFacesPortlet.getPortletMode(context);
+		if(null == portletMode){
+		    portletMode = lastMode;
+		}
+		viewId = config.getInitParameter(DEFAULT+portletMode.toString().toLowerCase());
+	}
+	if(null == viewId){
+	    throw new FacesException("could'n determine portlet view id");
+	}
 	return viewId;
     }
     
-    public PortletWindowStates getWindowStates() {
-	return null;
+    /**
+     * Return class contained saved JSF states for a current window.
+     * @param context
+     * @return
+     */
+    public PortletWindowStates getWindowStates(FacesContext context) {
+	String portletNamespace = AjaxFacesPortlet.getPortletNamespace(context);
+	PortletMode portletMode = AjaxFacesPortlet.getPortletMode(context);
+	if(null == portletMode){
+	    portletMode = lastMode;
+	}
+	StateKey windowKey = new StateKey(portletMode,portletNamespace);
+	PortletWindowStates state = (PortletWindowStates) states.get(windowKey);
+	if(null == state){
+	    state = new PortletWindowStates();
+	    states.put(windowKey, state);
+	}
+	return state;
     }
     /**
          * @author asmirnov
          * 
          */
     private static class StateKey implements Serializable {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -1490104706512592990L;
+
 	private PortletMode mode;
 
 	private String namespace;

Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java	2007-05-24 17:22:32 UTC (rev 218)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java	2007-05-25 00:16:48 UTC (rev 219)
@@ -20,11 +20,17 @@
  */
 public class PortletViewState implements Serializable {
     
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 5630637804542426709L;
+
     public static final String SAVED_VIEW_ATTRIBUTE = PortletViewState.class.getName();
     
     private Map messages = new HashMap();
+    private Object treeStructure;
+    private Object componentsState;
     private UIViewRoot viewRoot;
-    private String viewId;
     
     public void save(FacesContext facesContext){
 	UIViewRoot viewRoot = facesContext.getViewRoot();
@@ -102,4 +108,32 @@
         }
     }
 
+    /**
+     * @return the componentsState
+     */
+    public Object getComponentsState() {
+        return componentsState;
+    }
+
+    /**
+     * @param componentsState the componentsState to set
+     */
+    public void setComponentsState(Object componentsState) {
+        this.componentsState = componentsState;
+    }
+
+    /**
+     * @return the treeStructure
+     */
+    public Object getTreeStructure() {
+        return treeStructure;
+    }
+
+    /**
+     * @param treeStructure the treeStructure to set
+     */
+    public void setTreeStructure(Object treeStructure) {
+        this.treeStructure = treeStructure;
+    }
+
 }

Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java	2007-05-24 17:22:32 UTC (rev 218)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java	2007-05-25 00:16:48 UTC (rev 219)
@@ -36,10 +36,11 @@
         this.viewId = viewId;
     }
     
-    public PortletViewState getState() {
+    public PortletViewState getState(String viewId) {
 	PortletViewState state = (PortletViewState) viewStates.get(viewId);
 	if(null == state){
 	    state = new PortletViewState();
+	    viewStates.put(viewId, state);
 	}
 	return state;
     }




More information about the ajax4jsf-svn-commits mailing list