Author: alexsmirnov
Date: 2007-10-25 15:03:35 -0400 (Thu, 25 Oct 2007)
New Revision: 3552
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.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/component/UIPortletViewRoot.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java
trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml
Log:
Continue to implement JSR-301 bridge.
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2007-10-25
19:03:21 UTC (rev 3551)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2007-10-25
19:03:35 UTC (rev 3552)
@@ -4,6 +4,7 @@
package org.ajax4jsf.portlet;
import java.io.PrintWriter;
+import java.util.ResourceBundle;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
@@ -21,6 +22,8 @@
import javax.portlet.faces.BridgeException;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.portlet.application.PortletStateHolder;
+import org.ajax4jsf.portlet.application.PortletViewState;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -75,6 +78,11 @@
FacesContext facesContext = getFacesContext(request, response);
try {
execute(facesContext);
+ facesContext.getApplication().getStateManager().saveSerializedView(facesContext);
+ // TODO - save request scope variables and Faces Messages.
+ PortletViewState windowState =
PortletStateHolder.getInstance(facesContext).getWindowState(facesContext);
+ windowState.saveMessages(facesContext);
+ windowState.saveBeans(facesContext);
// saveView(facesContext);
} catch (Exception e) {
log.error("Error processing execute lifecycle", e);
@@ -101,11 +109,23 @@
response.setContentType(contenttype);
}
- PrintWriter writer = response.getWriter();
+ // set portlet title if its set.
+ ResourceBundle bundle =
+ portletConfig.getResourceBundle(request.getLocale());
+ if (bundle != null) {
+ String title = null;
+ try {
+ title = bundle.getString("javax.portlet.title");
+ response.setTitle(title);
+ } catch (Exception e) {
+ // Ignore MissingResourceException
+ }
+ }
+// PrintWriter writer = response.getWriter();
String namespace = response.getNamespace();
// Write anchor for update portlet pages by ajax.
// TODO - configure html element and style/class.
- writer.println("<div id='" + namespace + "'>");
+// writer.println("<div id='" + namespace + "'>");
// writer.flush();
AjaxContext ajaxContext = AjaxContext
.getCurrentInstance(facesContext);
@@ -117,8 +137,17 @@
request.getPortletMode().toString());
ajaxContext.getCommonAjaxParameters().put(
AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
+ ajaxContext.getCommonAjaxParameters().put(
+ AbstractExternalContext.PORTLET_NAME_PARAMETER,
getPortletConfig().getPortletName());
+ PortletViewState windowState =
PortletStateHolder.getInstance(facesContext).getWindowState(facesContext);
+ windowState.restoreMessages(facesContext);
+ windowState.restoreBeans(facesContext);
+ if(null == facesContext.getViewRoot()){
+ execute(facesContext);
+ }
+//
render(facesContext);
- writer.println("</div>");
+// writer.println("</div>");
PortletSession portletSession = request.getPortletSession(true);
// Store namespace value in portlet scope session.
// ServletContext, in case of ajax requests,
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-25
19:03:21 UTC (rev 3551)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-10-25
19:03:35 UTC (rev 3552)
@@ -63,7 +63,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;
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-25
19:03:21 UTC (rev 3551)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-10-25
19:03:35 UTC (rev 3552)
@@ -187,4 +187,16 @@
this.treeStructure = treeStructure;
}
+
+ public void saveBeans(FacesContext facesContext) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public void restoreBeans(FacesContext facesContext) {
+ // TODO Auto-generated method stub
+
+ }
+
}
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/component/UIPortletViewRoot.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/component/UIPortletViewRoot.java 2007-10-25
19:03:21 UTC (rev 3551)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/component/UIPortletViewRoot.java 2007-10-25
19:03:35 UTC (rev 3552)
@@ -20,6 +20,8 @@
PortletNamingContainer, Serializable {
+ public static final String PORTLET_VIEW_ROOT_RENDERER =
"org.ajax4jsf.portlet.ViewRoot";
+
public UIPortletViewRoot() {
super();
}
@@ -45,4 +47,10 @@
}
return containerClientId;
}
+
+ @Override
+ public String getRendererType() {
+ // Override defauilt ViewRoot renderer type.
+ return PORTLET_VIEW_ROOT_RENDERER;
+ }
}
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-25
19:03:21 UTC (rev 3551)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java 2007-10-25
19:03:35 UTC (rev 3552)
@@ -90,25 +90,25 @@
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);
- }
+// 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);
+// }
}
/**
@@ -118,16 +118,16 @@
*/
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);
- }
- }
+// 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/renderkit/portlet/PortletAjaxViewRootRenderer.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java 2007-10-25
19:03:21 UTC (rev 3551)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java 2007-10-25
19:03:35 UTC (rev 3552)
@@ -23,24 +23,22 @@
public class PortletAjaxViewRootRenderer extends AjaxViewRootRenderer {
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(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
- if(!ajaxContext.isAjaxRequest() && null !=namespace && null !=
ajaxRequestParameter){
- // Navigation case, encode portlet window marker
- writer.startElement(HTML.DIV_ELEM, component);
- writer.writeAttribute(HTML.id_ATTRIBUTE, namespace, HTML.id_ATTRIBUTE);
- }
+ Object namespace = context.getExternalContext().encodeNamespace("");
+ // encode portlet window marker
+ writer.startElement(HTML.DIV_ELEM, component);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, namespace, HTML.id_ATTRIBUTE);
super.doEncodeBegin(writer, context, component);
}
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
super.doEncodeEnd(writer, context, component);
+ // Encode portlet window marker
+ writer.endElement(HTML.DIV_ELEM);
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- Object namespace =
context.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.NAMESPACE_PARAMETER);
+ Object namespace = context.getExternalContext().encodeNamespace("");
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);
+ // Navigation case, set response back to AJAX
ajaxContext.setAjaxRequest(true);
ajaxContext.addRenderedArea(namespace.toString());
AjaxRendererUtils.encodeAreas(context, component);
Modified: trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml
===================================================================
--- trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml 2007-10-25
19:03:21 UTC (rev 3551)
+++ trunk/extensions/portlet/src/main/resources/META-INF/faces-config.xml 2007-10-25
19:03:35 UTC (rev 3552)
@@ -23,7 +23,7 @@
override the viewroot
</description>
<component-family>javax.faces.ViewRoot</component-family>
- <renderer-type>javax.faces.ViewRoot</renderer-type>
+ <renderer-type>org.ajax4jsf.portlet.ViewRoot</renderer-type>
<renderer-class>org.ajax4jsf.portlet.renderkit.portlet.PortletAjaxViewRootRenderer</renderer-class>
</renderer>
</render-kit>