Author: alexsmirnov
Date: 2007-04-25 15:12:35 -0400 (Wed, 25 Apr 2007)
New Revision: 123
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.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/context/ServletContextImpl.java
trunk/a4j-portlet/src/main/resources/META-INF/faces-config.xml
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java
trunk/framework/src/main/java/org/ajax4jsf/framework/resource/FacesResourceContext.java
trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js
trunk/pom.xml
trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/ajaxportlet-object.xml
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/portlet.xml
trunk/samples/ajaxPortlet/src/main/webapp/jsf/repeater.xhtml
trunk/samples/ajaxPortlet/src/main/webapp/jsf/start.xhtml
Log:
Ajax Portlet is worked !
Fix AJSF-42
Fix illegal permissions in IE-7 on non-AJAX responses.
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-04-25
00:24:54 UTC (rev 122)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -27,6 +27,7 @@
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import org.ajax4jsf.framework.ajax.AjaxContext;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -39,9 +40,8 @@
private static final Log log = LogFactory.getLog(AjaxFacesPortlet.class);
/**
- * Stored portlet config.
- */
-
+ * Stored portlet config.
+ */
private Lifecycle lifecycle;
private FacesContextFactory facesContextFactory;
@@ -106,36 +106,30 @@
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
if (log.isDebugEnabled()) {
- log.debug("Process action in portlet " +
getPortletConfig().getPortletName()+" for mode "+request.getPortletMode());
+ log.debug("Process action in portlet "
+ + getPortletConfig().getPortletName() + " for mode "
+ + request.getPortletMode());
}
FacesContext facesContext = getFacesContext(request, response);
try {
setViewId(facesContext);
execute(facesContext);
- saveView(facesContext,response);
+ saveView(facesContext, response);
} catch (Exception e) {
log.error("Error processing execute lifecycle", e);
- throw new PortletException("Error processing execute lifecycle ",e);
+ throw new PortletException("Error processing execute lifecycle ", e);
} finally {
facesContext.release();
}
}
- protected void saveView(FacesContext facesContext,ActionResponse response) {
+ protected void saveView(FacesContext facesContext, ActionResponse response) {
PortletViewState state = new PortletViewState();
- UIViewRoot viewRoot = facesContext.getViewRoot();
- state.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();
- state.addMessage(id, message);
- }
- }
- facesContext.getExternalContext().getSessionMap().put(PortletViewState.SAVED_VIEW_ATTRIBUTE,
state);
- response.setRenderParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
viewRoot.getViewId());
+ state.save(facesContext);
+ facesContext.getExternalContext().getSessionMap().put(
+ PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
+ // response.setRenderParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
+ // viewRoot.getViewId());
}
/*
@@ -147,7 +141,8 @@
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
if (log.isDebugEnabled()) {
- log.debug("Process do view in portlet " +
getPortletConfig().getPortletName());
+ log.debug("Process do view in portlet "
+ + getPortletConfig().getPortletName());
}
FacesContext facesContext = getFacesContext(request, response);
try {
@@ -161,22 +156,32 @@
}
response.setContentType(contenttype);
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='"+response.getNamespace()+"'>");
-// writer.flush();
+ writer.println("<div id='" + namespace + "'>");
+ // writer.flush();
restoreView(facesContext);
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
+ ajaxContext.getCommonAjaxParameters().put(AbstractExternalContext.ACTION__PARAMETER,
facesContext.getApplication().getViewHandler().getActionURL(facesContext,
facesContext.getViewRoot().getViewId()));
render(facesContext);
writer.println("</div>");
- PortletSession portletSession = request.getPortletSession(false);
- // Store namespace value in portlet scope session. ServletContext, in case of ajax
requests,
+ PortletSession portletSession = request.getPortletSession(true);
+ // Store namespace value in portlet scope session.
+ // ServletContext, in case of ajax requests,
// will restore session prefiv by it's value.
- if(null!=portletSession){
- portletSession.setAttribute(AbstractExternalContext.NAMESPACE_PARAMETER,
response.getNamespace());
- }
+ portletSession.setAttribute(
+ AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
+ if (log.isDebugEnabled()) {
+ log.debug("Finish rendering portlet for namespace "+namespace);
+ }
+ // Disable portlet caching.
+ // TODO - detect ajax components on page, static views can be cached.
+ response.setProperty(RenderResponse.EXPIRATION_CACHE, "0");
} catch (Exception e) {
log.error("Error processing execute lifecycle", e);
- throw new PortletException("Error processing execute lifecycle ",e);
+ throw new PortletException("Error processing execute lifecycle ", e);
} finally {
facesContext.release();
}
@@ -184,20 +189,12 @@
protected void restoreView(FacesContext facesContext) {
Map sessionMap = facesContext.getExternalContext().getSessionMap();
- PortletViewState state = (PortletViewState)
sessionMap.get(PortletViewState.SAVED_VIEW_ATTRIBUTE);
+ PortletViewState state = (PortletViewState) sessionMap
+ .get(PortletViewState.SAVED_VIEW_ATTRIBUTE);
if (null != state) {
- facesContext.setViewRoot(state.getViewRoot());
- Iterator idsWithMessages = state.getClientIdsWithMessages();
- while (idsWithMessages.hasNext()) {
- String id = (String) idsWithMessages.next();
- Iterator messages = state.getMessages(id);
- while (messages.hasNext()) {
- FacesMessage message = (FacesMessage) messages.next();
- facesContext.addMessage(id, message);
- }
- }
- sessionMap.remove(PortletViewState.SAVED_VIEW_ATTRIBUTE);
- }else {
+ state.restore(facesContext);
+ // sessionMap.remove(PortletViewState.SAVED_VIEW_ATTRIBUTE);
+ } else {
setViewId(facesContext);
}
}
@@ -211,7 +208,8 @@
protected void doEdit(RenderRequest arg0, RenderResponse arg1)
throws PortletException, IOException {
if (log.isDebugEnabled()) {
- log.debug("Process do edit in portlet " +
getPortletConfig().getPortletName());
+ log.debug("Process do edit in portlet "
+ + getPortletConfig().getPortletName());
}
}
@@ -224,11 +222,11 @@
protected void doHelp(RenderRequest arg0, RenderResponse arg1)
throws PortletException, IOException {
if (log.isDebugEnabled()) {
- log.debug("Process do help in portlet " +
getPortletConfig().getPortletName());
+ log.debug("Process do help in portlet "
+ + getPortletConfig().getPortletName());
}
}
-
/**
* Get currenf JSF lifecycle instance.
*
@@ -258,38 +256,54 @@
protected void render(FacesContext context) throws FacesException {
getLifecycle().render(context);
}
-
+
protected void setViewId(FacesContext context) {
- Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
- String viewId = (String)
requestParameterMap.get(AbstractExternalContext.VIEW_ID_PARAMETER);
- if(null == viewId){
+ String viewId = null;
+ Map sessionMap = context.getExternalContext().getSessionMap();
+ PortletViewState state = (PortletViewState) sessionMap
+ .get(PortletViewState.SAVED_VIEW_ATTRIBUTE);
+ if (null != state) {
+ viewId = state.getViewRoot().getViewId();
+ }
+ if (null == viewId) {
+ Map requestParameterMap = context.getExternalContext()
+ .getRequestParameterMap();
+ viewId = (String) requestParameterMap
+ .get(AbstractExternalContext.VIEW_ID_PARAMETER);
+ } else if (log.isDebugEnabled()) {
+ log.debug("Detect viewId from saved view state as " + viewId);
+ }
+ if (null == viewId) {
viewId = getInitParameter("default-view");
if (log.isDebugEnabled()) {
- log.debug("Set viewId to default value from portlet parameter "+viewId);
+ log.debug("Set viewId to default value from portlet parameter "
+ + viewId);
}
} else if (log.isDebugEnabled()) {
- log.debug("Detect viewId from request parameter as "+viewId);
+ log.debug("Detect viewId from request parameter as " + viewId);
}
- if(null == viewId){
- throw new IllegalArgumentException("Initial view id must be set as portlet
parameter");
+ if (null == viewId) {
+ throw new IllegalArgumentException(
+ "Initial view id must be set as portlet parameter");
}
// Store for simulate servlet environment compability.
- context.getExternalContext().getRequestMap().put(AbstractExternalContext.VIEW_ID_PARAMETER,
viewId);
+ context.getExternalContext().getRequestMap().put(
+ AbstractExternalContext.VIEW_ID_PARAMETER, viewId);
UIViewRoot viewRoot = context.getViewRoot();
- if(null == viewRoot){
- viewRoot = context.getApplication().getViewHandler().createView(context, viewId);
+ if (null == viewRoot) {
+ viewRoot = context.getApplication().getViewHandler().createView(
+ context, viewId);
context.setViewRoot(viewRoot);
}
viewRoot.setViewId(viewId);
}
-
+
/**
- * @param facesContext
- * @return
- */
+ * @param facesContext
+ * @return
+ */
public static String getPortletID(FacesContext facesContext) {
- ExternalContext externalContext = facesContext
- .getExternalContext();
+ ExternalContext externalContext = facesContext.getExternalContext();
Object response = externalContext.getResponse();
String namespace = null;
if (response instanceof RenderResponse) {
@@ -301,6 +315,4 @@
}
return namespace;
}
-
-
}
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-04-25
00:24:54 UTC (rev 122)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -80,6 +80,10 @@
if (null != namespace) {
map.put(AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
}
+ String actionUrl = (String)
facesContext.getExternalContext().getRequestParameterMap().get(AbstractExternalContext.ACTION__PARAMETER);
+ if(null != actionUrl){
+ map.put(AbstractExternalContext.ACTION__PARAMETER, actionUrl);
+ }
return map;
}
}
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java 2007-04-25
00:24:54 UTC (rev 122)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletViewState.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -11,6 +11,7 @@
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
/**
* @author asmirnov
@@ -22,6 +23,36 @@
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
*/
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-04-25
00:24:54 UTC (rev 122)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -3,11 +3,17 @@
*/
package org.ajax4jsf.portlet.application;
+import java.io.IOException;
+import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.portlet.PortletURL;
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;
/**
@@ -22,14 +28,38 @@
super(parent);
}
+ public UIViewRoot createView(FacesContext facesContext, String viewId) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
+ boolean ajaxRequest = ajaxContext.isAjaxRequest(facesContext);
+ UIViewRoot root = super.createView(facesContext, viewId);
+ if(ajaxRequest && null != ajaxContext.getViewIdHolder()){
+ // Store new viewId for a portlet.
+ }
+ return root;
+ }
+
+ public void renderView(FacesContext context, UIViewRoot root) throws IOException,
FacesException {
+ super.renderView(context, root);
+ // Save view to use in portlet rendering phases
+ PortletViewState state = new PortletViewState();
+ state.save(context);
+ context.getExternalContext().getSessionMap().put(
+ PortletViewState.SAVED_VIEW_ATTRIBUTE, state);
+
+ }
+
public String getActionURL(FacesContext context, String url) {
- Object response = context.getExternalContext().getResponse();
+ ExternalContext externalContext = context.getExternalContext();
+ String portalActionURL = (String)
externalContext.getRequestParameterMap().get(AbstractExternalContext.ACTION__PARAMETER);
+ Object response = externalContext.getResponse();
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());
return portletURL.toString();
+ } else if(null!=portalActionURL){
+ return portalActionURL;
} else {
return super.getActionURL(context, url);
}
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-04-25
00:24:54 UTC (rev 122)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -103,6 +103,7 @@
* Name of request parameter to store namsepace of the current portlet instance.
*/
public static final String NAMESPACE_PARAMETER
="org.ajax4jsf.portlet.NAMESPACE";
+ public static final String ACTION__PARAMETER =
"org.ajax4jsf.portlet.ACTION_URL";
// TODO - optimization.
private Map applicationMap;
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-25
00:24:54 UTC (rev 122)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -27,12 +27,17 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* @author asmirnov
*
*/
public class ServletContextImpl extends AbstractExternalContext {
+
+ private static final Log _log = LogFactory.getLog(ServletContextImpl.class);
+
private String namespace;
/**
@@ -61,7 +66,12 @@
Object requestParameter = getRequestParameter(NAMESPACE_PARAMETER);
if (null != requestParameter) {
namespace = (String) requestParameter;
- }
+ if (_log.isDebugEnabled()) {
+ _log.debug("Namespace for a portlet instance is "+namespace);
+ }
+ } else {
+ throw new FacesException("AJAX call to portlet without namespace
parameter");
+ }
}
return namespace;
}
@@ -187,11 +197,15 @@
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements() && null == sessionPrefix) {
String name = (String) attributeNames.nextElement();
+ Object attribute = session.getAttribute(name);
if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE
&& PortletSessionUtil.decodeAttributeName(name).equals(
NAMESPACE_PARAMETER)
- && namespase.equals(session.getAttribute(name))) {
+ && namespase.equals(attribute)) {
sessionPrefix = name.substring(0, name.length()-NAMESPACE_PARAMETER.length());
+ if (_log.isDebugEnabled()) {
+ _log.debug("Prefix for a PORTLET_SCOPE session attributes:
"+sessionPrefix);
+ }
}
}
if(null == sessionPrefix){
Added:
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
(rev 0)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/renderkit/portlet/PortletAjaxViewRootRenderer.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.renderkit.portlet;
+
+import java.io.IOException;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.framework.ajax.AjaxContext;
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
+import org.ajax4jsf.portlet.context.AbstractExternalContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+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(AbstractExternalContext.NAMESPACE_PARAMETER);
+ 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);
+ }
+ super.doEncodeBegin(writer, context, component);
+ }
+
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ 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);
+ if(!ajaxContext.isAjaxRequest() && null !=namespace && null !=
ajaxRequestParameter){
+ // Navigation case, encode portlet window marker
+ writer.endElement(HTML.DIV_ELEM);
+ ajaxContext.setAjaxRequest(true);
+ ajaxContext.addRenderedArea(namespace.toString());
+ AjaxRendererUtils.encodeAreas(context, component);
+ }
+ }
+}
Modified: trunk/a4j-portlet/src/main/resources/META-INF/faces-config.xml
===================================================================
--- trunk/a4j-portlet/src/main/resources/META-INF/faces-config.xml 2007-04-25 00:24:54 UTC
(rev 122)
+++ trunk/a4j-portlet/src/main/resources/META-INF/faces-config.xml 2007-04-25 19:12:35 UTC
(rev 123)
@@ -9,4 +9,16 @@
<factory>
<faces-context-factory>org.ajax4jsf.portlet.context.FacesContextFactoryImpl</faces-context-factory>
</factory>
+ <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>
+
</faces-config>
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java 2007-04-25
00:24:54 UTC (rev 122)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -204,7 +204,7 @@
}
if( null == taglib.getJspVersion()){
// Jsf 1.2 can use JSP 2.1 only, other - 2.0
- taglib.setJspVersion(library.getJsfVersion().equals(Library.JSF12)?"2.1":"2.0");
+ taglib.setJspVersion(library.getJsfVersion().equals(Library.JSF12)?"2.1":"1.2");
}
if (null == taglib.getUri()) {
String url = project.getUrl();
Modified:
trunk/framework/src/main/java/org/ajax4jsf/framework/resource/FacesResourceContext.java
===================================================================
---
trunk/framework/src/main/java/org/ajax4jsf/framework/resource/FacesResourceContext.java 2007-04-25
00:24:54 UTC (rev 122)
+++
trunk/framework/src/main/java/org/ajax4jsf/framework/resource/FacesResourceContext.java 2007-04-25
19:12:35 UTC (rev 123)
@@ -25,135 +25,197 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
/**
* @author asmirnov(a)exadel.com (latest modification by $Author: nick_belaevski $)
* @version $Revision: 1.1.2.2 $ $Date: 2007/01/11 16:52:14 $
- *
+ *
*/
public class FacesResourceContext extends ResourceContext {
- FacesContext facesContext;
-
- ExternalContext externalContext;
-
- HttpServletResponse response;
- /**
- * @param facesContext
- */
- public FacesResourceContext(FacesContext facesContext) {
-
- this.facesContext = facesContext;
- this.externalContext = facesContext.getExternalContext();
- this.response = (HttpServletResponse) externalContext.getResponse();
- }
+ FacesContext facesContext;
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#setHeader(java.lang.String,
java.lang.String)
- */
- public void setHeader(String name, String value) {
- response.setHeader(name,value);
+ ExternalContext externalContext;
- }
+ HttpServletResponse response;
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#setIntHeader(java.lang.String,
int)
- */
- public void setIntHeader(String name, int value) {
- response.setIntHeader(name,value);
+ /**
+ * @param facesContext
+ */
+ public FacesResourceContext(FacesContext facesContext) {
+ this.facesContext = facesContext;
+ this.externalContext = facesContext.getExternalContext();
+ Object facesResponse = externalContext.getResponse();
+ if (facesResponse instanceof HttpServletResponse) {
+ this.response = (HttpServletResponse) facesResponse;
}
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#setDateHeader(java.lang.String,
long)
- */
- public void setDateHeader(String name, long value) {
- response.setDateHeader(name,value);
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.resource.ResourceContext#setHeader(java.lang.String,
+ * java.lang.String)
+ */
+ public void setHeader(String name, String value) {
+ if (null != response) {
+ response.setHeader(name, value);
}
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#getOutputStream()
- */
- public OutputStream getOutputStream() throws IOException {
- return response.getOutputStream();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.resource.ResourceContext#setIntHeader(java.lang.String,
+ * int)
+ */
+ public void setIntHeader(String name, int value) {
+ if (null != response) {
+ response.setIntHeader(name, value);
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#getWriter()
- */
- public PrintWriter getWriter() throws IOException {
- // TODO Auto-generated method stub
- return response.getWriter();
}
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#getQueryString()
- */
- public String getQueryString() {
- return ((HttpServletRequest) externalContext.getRequest()).getQueryString();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.resource.ResourceContext#setDateHeader(java.lang.String,
+ * long)
+ */
+ public void setDateHeader(String name, long value) {
+ if (null != response) {
+ response.setDateHeader(name, value);
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.resource.ResourceContext#getPathInfo()
- */
- public String getPathInfo() {
- return externalContext.getRequestPathInfo();
}
+ }
- /* (non-Javadoc)
- * @see
org.ajax4jsf.framework.resource.ResourceContext#getSessionAttribute(java.lang.String)
- */
- public Object getSessionAttribute(String name) {
- return externalContext.getSessionMap().get(name);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.resource.ResourceContext#getOutputStream()
+ */
+ public OutputStream getOutputStream() throws IOException {
+ if (null != response) {
+ return response.getOutputStream();
- public InputStream getResourceAsStream(String path) {
-
- return externalContext.getResourceAsStream(path);
+ } else {
+ // May be non-servlet (Portlet?) environment. Try to use reflection
+ OutputStream stream = null;
+ Object response = externalContext.getResponse();
+ try {
+ Method gW = response.getClass()
+ .getMethod("getOutputStream", new Class[0]);
+ stream = (OutputStream) gW.invoke(response, new Object[0]);
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+ return stream;
+
}
+ }
- public String getRequestParameter(String data_parameter) {
-
- return (String) externalContext.getRequestParameterMap().get(data_parameter);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.resource.ResourceContext#getWriter()
+ */
+ public PrintWriter getWriter() throws IOException {
+ if (null != response) {
+ return response.getWriter();
- public void setContentType(String contentType) {
- response.setContentType(contentType);
-
+ } else {
+ // May be non-servlet (Portlet?) environment. Try to use reflection
+ PrintWriter writer = null;
+ Object response = externalContext.getResponse();
+ try {
+ Method gW = response.getClass()
+ .getMethod("getWriter", new Class[0]);
+ writer = (PrintWriter) gW.invoke(response, new Object[0]);
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+ return writer;
+
}
+ }
- public String getInitParameter(String name) {
- // TODO Auto-generated method stub
- return externalContext.getInitParameter(name);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.resource.ResourceContext#getQueryString()
+ */
+ public String getQueryString() {
+ return ((HttpServletRequest) externalContext.getRequest())
+ .getQueryString();
+ }
- public String getServletPath() {
- // TODO Auto-generated method stub
- return externalContext.getRequestServletPath();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.resource.ResourceContext#getPathInfo()
+ */
+ public String getPathInfo() {
+ return externalContext.getRequestPathInfo();
+ }
- public void release() {
- super.release();
- externalContext = null;
- response = null;
- facesContext.release();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.resource.ResourceContext#getSessionAttribute(java.lang.String)
+ */
+ public Object getSessionAttribute(String name) {
+ return externalContext.getSessionMap().get(name);
+ }
- // added by nick 11.01.2007 - getters for contexts added
- public FacesContext getFacesContext() {
- return facesContext;
- }
-
- public ExternalContext getExternalContext() {
- return externalContext;
- }
- // by nick
+ public InputStream getResourceAsStream(String path) {
+
+ return externalContext.getResourceAsStream(path);
+ }
+
+ public String getRequestParameter(String data_parameter) {
+
+ return (String) externalContext.getRequestParameterMap().get(
+ data_parameter);
+ }
+
+ public void setContentType(String contentType) {
+ response.setContentType(contentType);
+
+ }
+
+ public String getInitParameter(String name) {
+ // TODO Auto-generated method stub
+ return externalContext.getInitParameter(name);
+ }
+
+ public String getServletPath() {
+ // TODO Auto-generated method stub
+ return externalContext.getRequestServletPath();
+ }
+
+ public void release() {
+ super.release();
+ externalContext = null;
+ response = null;
+ facesContext.release();
+ }
+
+ // added by nick 11.01.2007 - getters for contexts added
+ public FacesContext getFacesContext() {
+ return facesContext;
+ }
+
+ public ExternalContext getExternalContext() {
+ return externalContext;
+ }
+ // by nick
}
Modified: trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js 2007-04-25 00:24:54 UTC (rev
122)
+++ trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js 2007-04-25 19:12:35 UTC (rev
123)
@@ -579,6 +579,16 @@
window.location.reload(true);
} else {
var isIE = _SARISSA_IS_IE;
+ // maksimkaszynski
+ //Prevent "Permission denied in IE7"
+ //Reset calling principal
+ if (isIE) {
+ var oldDocOpen = window.document.open;
+ window.document.open = function() {
+ oldDocOpen.apply(this, arguments);
+ }
+ }
+ // /maksimkaszynski
window.setTimeout(function() {
var isDocOpen=false;
try {
@@ -645,7 +655,8 @@
LOG.debug("Hidden JSF state fields: "+idsSpan);
if(idsSpan != null){
// For a portal case, replace content in the current window only.
- var namespace = options['org.ajax4jsf.portlet.NAMESPACE'];
+ var namespace = options.parameters['org.ajax4jsf.portlet.NAMESPACE'];
+ LOG.debug("Namespace for hidden view-state input fields is
"+namespace);
var anchor =
namespace?window.document.getElementById(namespace):window.document;
var inputs = anchor.getElementsByTagName("input");
var newinputs = req.getElementsByTagName("input",idsSpan);
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2007-04-25 00:24:54 UTC (rev 122)
+++ trunk/pom.xml 2007-04-25 19:12:35 UTC (rev 123)
@@ -174,6 +174,7 @@
<module>framework</module>
<module>test</module>
<module>cdk</module>
+ <module>a4j-portlet</module>
</modules>
<profiles>
<profile>
@@ -195,12 +196,6 @@
</modules>
</profile>
<profile>
- <id>portlet</id>
- <modules>
- <module>a4j-portlet</module>
- </modules>
- </profile>
- <profile>
<id>assembly</id>
<build>
<plugins>
Modified: trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java
===================================================================
--- trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java 2007-04-25 00:24:54 UTC (rev
122)
+++ trunk/samples/ajaxPortlet/src/main/java/portal/Bean.java 2007-04-25 19:12:35 UTC (rev
123)
@@ -3,6 +3,8 @@
*/
package portal;
+import javax.faces.context.FacesContext;
+
/**
* @author asmirnov
*
@@ -45,4 +47,7 @@
return null;
}
+ public String getNamespace(){
+ return
FacesContext.getCurrentInstance().getExternalContext().encodeNamespace("");
+ }
}
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/ajaxportlet-object.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/ajaxportlet-object.xml 2007-04-25
00:24:54 UTC (rev 122)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/ajaxportlet-object.xml 2007-04-25
19:12:35 UTC (rev 123)
@@ -32,6 +32,20 @@
<deployment>
<parent-ref>default</parent-ref>
<if-exists>overwrite</if-exists>
+ <page>
+ <page-name>otherAjaxPortlet</page-name>
+ <window>
+ <window-name>otherAjaxportletWindow</window-name>
+ <instance-ref>AjaxPortletInstance</instance-ref>
+ <default>true</default>
+ <region>center</region>
+ <height>0</height>
+ </window>
+ </page>
+ </deployment>
+ <deployment>
+ <parent-ref>default</parent-ref>
+ <if-exists>overwrite</if-exists>
<instance>
<instance-name>AjaxPortletSecondInstance</instance-name>
<component-ref>ajaxPortletApp.ajaxPortlet</component-ref>
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-04-25 00:24:54
UTC (rev 122)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-04-25 19:12:35
UTC (rev 123)
@@ -32,4 +32,14 @@
<view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler>
-->
</application>
+ <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>
</faces-config>
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/portlet.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/portlet.xml 2007-04-25 00:24:54 UTC
(rev 122)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/portlet.xml 2007-04-25 19:12:35 UTC
(rev 123)
@@ -16,7 +16,7 @@
<name>default-help</name>
<value>/jsf/start-help.xhtml</value>
</init-param>
- <expiration-cache>-1</expiration-cache>
+ <expiration-cache>-0</expiration-cache>
<portlet-info>
<title>Ajax Portlet</title>
</portlet-info>
Modified: trunk/samples/ajaxPortlet/src/main/webapp/jsf/repeater.xhtml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/jsf/repeater.xhtml 2007-04-25 00:24:54 UTC
(rev 122)
+++ trunk/samples/ajaxPortlet/src/main/webapp/jsf/repeater.xhtml 2007-04-25 19:12:35 UTC
(rev 123)
@@ -1,4 +1,4 @@
-<div
+<a4j:portlet
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
@@ -17,5 +17,5 @@
<a4j:commandButton action="start" value="Ajax Switch to start
page" />
</h:panelGrid>
</h:form>
-
-</div>
+ <a4j:log hotkey="M" />
+</a4j:portlet>
\ No newline at end of file
Modified: trunk/samples/ajaxPortlet/src/main/webapp/jsf/start.xhtml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/jsf/start.xhtml 2007-04-25 00:24:54 UTC (rev
122)
+++ trunk/samples/ajaxPortlet/src/main/webapp/jsf/start.xhtml 2007-04-25 19:12:35 UTC (rev
123)
@@ -12,14 +12,16 @@
<a4j:support event="onkeyup" reRender="text"/>
</h:inputText>
<a4j:outputPanel ajaxRendered="true">
+ <h:outputText id="text" value="#{bean.text}"/>
<h:message for="repeaterText"/>
</a4j:outputPanel>
- <h:outputText id="text" value="#{bean.text}"/>
<a4j:commandLink value="Increment counter"
action="#{bean.click}" reRender="counter"/>
<h:outputText id="counter" value="#{bean.counter}"/>
+ <h:outputText value="Portlet namespace:"/>
+ <h:outputText value="#{bean.namespace}"/>
<h:commandButton action="repeater" value="Switch to repeater
page" />
<a4j:commandButton action="repeater" value="Ajax Switch to
repeater page" />
</h:panelGrid>
</h:form>
-
+ <a4j:log hotkey="M" />
</a4j:portlet>