JBoss Rich Faces SVN: r3662 - in trunk: samples/ajaxPortlet/src/main/webapp/WEB-INF and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-10-31 21:04:03 -0400 (Wed, 31 Oct 2007)
New Revision: 3662
Added:
trunk/sandbox/ui/calendar/
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/web.xml
trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPortlet.java
trunk/ui/paint2D/pom.xml
Log:
Continue to implement JSR-301 bridge. Finish requrements from PLT 6.
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-11-01 01:00:43 UTC (rev 3661)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-11-01 01:04:03 UTC (rev 3662)
@@ -100,7 +100,7 @@
// This method MUST BE OVERRIDEN in any subclasses - since Junit see for it in class for call
super.setUp();
- // Setup FacesContext with nessesary init parameters.
+ // Setup FacesContext with necessary init parameters.
this.servletContext.addInitParameter(SkinFactory.SKIN_PARAMETER, getSkinName());
// setup VCP renderKit, create renderers.
RenderKitFactory vcpRenderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-11-01 01:00:43 UTC (rev 3661)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2007-11-01 01:04:03 UTC (rev 3662)
@@ -81,17 +81,7 @@
<faces-context-factory>
org.ajax4jsf.portlet.context.FacesContextFactoryImpl
</faces-context-factory>
- <lifecycle-factory>
- org.ajax4jsf.portlet.lifecycle.PortletLifecycleFactory
- </lifecycle-factory>
</factory>
- <managed-bean>
- <managed-bean-name>ajaxContext</managed-bean-name>
- <managed-bean-class>
- org.ajax4jsf.portlet.PortletAjaxContext
- </managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
</faces-config>
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/web.xml 2007-11-01 01:00:43 UTC (rev 3661)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/web.xml 2007-11-01 01:04:03 UTC (rev 3662)
@@ -66,10 +66,6 @@
</context-param>
-->
<context-param>
- <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
- <param-value>.xhtml</param-value>
- </context-param>
- <context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPortlet.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPortlet.java 2007-11-01 01:00:43 UTC (rev 3661)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPortlet.java 2007-11-01 01:04:03 UTC (rev 3662)
@@ -40,25 +40,16 @@
private String portletId = null;
+ @Override
+ public void setId(String id) {
+ portletId = null;
+ super.setId(id);
+ }
+
// ----------------------------------------------------- UIComponent Methods
public String getClientId(FacesContext context) {
if (portletId == null) {
- Object response = context.getExternalContext().getResponse();
- Class portletResponseClass = response.getClass();
- // Class.forName is used instead of instanceof to account for the case
- // where the porletPage tag is used in a webapp and portlet.jar is not
- // in classpath. In that scenario it will prevent ClassNotFoundException.
- try {
- Method method = portletResponseClass.getMethod("getNamespace", new Class[]{});
- portletId = (String) method.invoke(response, new Object[]{});
- } catch (Exception e) {
- if(_log.isDebugEnabled()){
- _log.debug("Response is not a portlet RenderResponse");
- }
- }
- if(null == portletId){
- return super.getClientId(context);
- }
+ portletId = context.getExternalContext().encodeNamespace(super.getClientId(context));
}
return portletId;
}
Modified: trunk/ui/paint2D/pom.xml
===================================================================
--- trunk/ui/paint2D/pom.xml 2007-11-01 01:00:43 UTC (rev 3661)
+++ trunk/ui/paint2D/pom.xml 2007-11-01 01:04:03 UTC (rev 3662)
@@ -1,51 +1,55 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <artifactId>ui</artifactId>
- <groupId>org.richfaces</groupId>
- <version>3.2.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.richfaces.ui</groupId>
- <artifactId>paint2D</artifactId>
- <name>Paint java 2D</name>
- <build>
- <plugins>
- <plugin>
- <groupId>org.richfaces.cdk</groupId>
- <artifactId>maven-cdk-plugin</artifactId>
- <version>3.2.0-SNAPSHOT</version>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- <execution>
- <id>generate-test-sources</id>
- <phase>generate-test-sources</phase>
- <goals>
- <goal>generate-tests</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <library>
- <prefix>org.richfaces</prefix>
- <taglib>
- <shortName>paint2D</shortName>
- </taglib>
- </library>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.4</source>
- <target>1.4</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>ui</artifactId>
+ <groupId>org.richfaces</groupId>
+ <version>3.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>paint2D</artifactId>
+ <name>Paint java 2D</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>generate-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>generate-tests</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <library>
+ <prefix>org.richfaces</prefix>
+ <taglib>
+ <shortName>paint2D</shortName>
+ </taglib>
+ </library>
+ </configuration>
+ </plugin>
+ <!--
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
+ </plugin>
+ -->
+ </plugins>
+ </build>
</project>
\ No newline at end of file
17 years, 2 months
JBoss Rich Faces SVN: r3661 - in trunk/framework/impl/src/main/java/org/ajax4jsf: event and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-10-31 21:00:43 -0400 (Wed, 31 Oct 2007)
New Revision: 3661
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
Log:
Continue to implement JSR-301 bridge. Finish requrements from PLT 6.
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-11-01 01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-11-01 01:00:43 UTC (rev 3661)
@@ -56,8 +56,6 @@
import org.ajax4jsf.application.AjaxViewHandler;
import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.component.AjaxViewRoot;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.context.ViewIdHolder;
import org.ajax4jsf.renderkit.AjaxContainerRenderer;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HeaderResourceProducer;
@@ -794,8 +792,11 @@
"Illegal view Id for build AJAX Action URL: " + viewId);
}
ViewHandler viewHandler = context.getApplication().getViewHandler();
+ String actionURL = viewHandler.getActionURL(context, viewId);
+ // Mark Ajax action url as transparent with jsf-portlet bridge.
+ actionURL = actionURL + ((actionURL.lastIndexOf('?')>0)?"&":"?")+"javax.portlet.faces.DirectLink=true";
return context.getExternalContext().encodeActionURL(
- viewHandler.getActionURL(context, viewId));
+ actionURL);
}
/**
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java 2007-11-01 01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java 2007-11-01 01:00:43 UTC (rev 3661)
@@ -110,7 +110,7 @@
}
}
}
- if(context.getResponseComplete()){
+ if (context.getResponseComplete()) {
ajaxContext.release();
}
}
@@ -132,27 +132,28 @@
AjaxContext.getCurrentInstance(context).setViewIdHolder(null);
UIViewRoot root = context.getViewRoot();
-if (null != root) {
- log.debug(Messages.getMessage(
- Messages.ENTER_BEFORE_RENDER_VIEW_PHASE, root.getViewId(),
- root.getRenderKitId()));
+ if (null != root) {
+ log.debug(Messages.getMessage(
+ Messages.ENTER_BEFORE_RENDER_VIEW_PHASE, root
+ .getViewId(), root.getRenderKitId()));
- // TODO - create special skin-config.xml configuration.
- String renderKitId = null;
- try {
- renderKitId = SkinFactory.getInstance().getSkin(context)
- .getRenderKitId(context);
- } catch (Exception e) {
- log.error("Exception on get current Skin ", e);
+ // TODO - create special skin-config.xml configuration.
+ String renderKitId = null;
+ try {
+ renderKitId = SkinFactory.getInstance().getSkin(context)
+ .getRenderKitId(context);
+ } catch (Exception e) {
+ log.error("Exception on get current Skin ", e);
+ }
+ if (null != renderKitId) {
+ log.debug(Messages.getMessage(
+ Messages.SET_RENDER_KIT_ID_INFO, renderKitId));
+ root.setRenderKitId(renderKitId);
+ }
+
}
- if (null != renderKitId) {
- log.debug(Messages.getMessage(Messages.SET_RENDER_KIT_ID_INFO,
- renderKitId));
- root.setRenderKitId(renderKitId);
- }
+ } else if (phaseId == PhaseId.RESTORE_VIEW) {
- } } else if (phaseId == PhaseId.RESTORE_VIEW) {
-
}
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2007-11-01 01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2007-11-01 01:00:43 UTC (rev 3661)
@@ -46,8 +46,8 @@
*/
public class InitPhaseListener implements PhaseListener {
- private boolean removed= false;
- private boolean initialized = false;
+ private volatile boolean removed= false;
+ private volatile boolean initialized = false;
private static final Log log = LogFactory.getLog(InitPhaseListener.class);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java 2007-11-01 01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java 2007-11-01 01:00:43 UTC (rev 3661)
@@ -21,6 +21,7 @@
package org.ajax4jsf.webapp;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@@ -29,7 +30,7 @@
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:58 $
*
*/
-public class FilterBean {
+public class FilterBean implements Serializable {
private String _filterName;
private String _filterClass;
private String _displayName;
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java 2007-11-01 01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java 2007-11-01 01:00:43 UTC (rev 3661)
@@ -21,6 +21,7 @@
package org.ajax4jsf.webapp;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@@ -29,7 +30,7 @@
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:59 $
*
*/
-public class ServletBean {
+public class ServletBean implements Serializable {
private String _servletName;
private String _servletClass;
private String _displayName;
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2007-11-01 01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2007-11-01 01:00:43 UTC (rev 3661)
@@ -29,6 +29,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
@@ -58,16 +59,17 @@
public static final String CONTEXT_ATTRIBUTE = WebXml.class.getName();
/**
- *
- */
- private static final long serialVersionUID = -9042908418843695017L;
+ *
+ */
+ private static final long serialVersionUID = -9042908418843695017L;
private static final Log _log = LogFactory.getLog(WebXml.class);
static final String WEB_XML = "/WEB-INF/web.xml";
-
- public static final String RESOURCE_URI_PREFIX = "a4j_"+VersionBean.MAJOR_VERSION+"_"+VersionBean.MINOR_VERSION+"_"+VersionBean.REVISION;
+ public static final String RESOURCE_URI_PREFIX = "a4j_"
+ + VersionBean.MAJOR_VERSION + "_" + VersionBean.MINOR_VERSION + "_"
+ + VersionBean.REVISION;
static final String RESOURCE_URI_PREFIX_WITH_SLASH = "/"
+ RESOURCE_URI_PREFIX;
@@ -86,6 +88,10 @@
*/
private String _facesFilterSuffix = null;
+ private String _facesServletPrefix = null;
+
+ private String _facesServletSuffix = null;
+
private boolean _prefixMapping = false;
private String _filterName;
@@ -99,91 +105,109 @@
*/
private String _resourcePrefix = RESOURCE_URI_PREFIX_WITH_SLASH;
-
/**
* Parse application web.xml configuration and detect mapping for resources
* and logs.
+ *
* @param context
* @param filterName
* @throws ServletException
*/
- public void init(ServletContext context, String filterName) throws ServletException {
- InputStream webXml = context.getResourceAsStream(WEB_XML);
- if (null == webXml) {
- throw new ServletException(Messages.getMessage(
- Messages.GET_RESOURCE_AS_STREAM_ERROR, WEB_XML));
- }
- Digester dig = new Digester();
- dig.setDocumentLocator(new LocatorImpl());
- // Disable xml validations at all - web.xml already validated by
- // container
- dig.setValidating(false);
- dig.setEntityResolver(new EntityResolver() {
- // Dummi resolver - alvays do nothing
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
- return new InputSource(new StringReader(""));
- }
+ public void init(ServletContext context, String filterName)
+ throws ServletException {
+ InputStream webXml = context.getResourceAsStream(WEB_XML);
+ if (null == webXml) {
+ throw new ServletException(Messages.getMessage(
+ Messages.GET_RESOURCE_AS_STREAM_ERROR, WEB_XML));
+ }
+ Digester dig = new Digester();
+ dig.setDocumentLocator(new LocatorImpl());
+ // Disable xml validations at all - web.xml already validated by
+ // container
+ dig.setValidating(false);
+ dig.setEntityResolver(new EntityResolver() {
+ // Dummi resolver - alvays do nothing
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
+ return new InputSource(new StringReader(""));
+ }
- });
- dig.setNamespaceAware(false);
- // dig.setUseContextClassLoader(true);
- dig.setClassLoader(this.getClass().getClassLoader());
- // Parsing rules.
- // Servlets.
- String path = "web-app/servlet";
- dig.addObjectCreate(path, ServletBean.class);
- dig.addBeanPropertySetter(path + "/servlet-name", "servletName");
- dig.addBeanPropertySetter(path + "/servlet-class", "servletClass");
- dig.addBeanPropertySetter(path + "/display-name", "displayName");
- dig.addBeanPropertySetter(path + "/description");
- dig.addSetNext(path, "addServlet");
- // Filters
- path = "web-app/filter";
- dig.addObjectCreate(path, FilterBean.class);
- dig.addBeanPropertySetter(path + "/filter-name", "filterName");
- dig.addBeanPropertySetter(path + "/filter-class", "filterClass");
- dig.addBeanPropertySetter(path + "/display-name", "displayName");
- dig.addBeanPropertySetter(path + "/description");
- dig.addSetNext(path, "addFilter");
- // Servlet mappings
- path = "web-app/servlet-mapping";
- dig.addCallMethod(path, "addServletMapping", 2);
- dig.addCallParam(path + "/servlet-name", 0);
- dig.addCallParam(path + "/url-pattern", 1);
- // Filter mappings
- // TODO - parse dispatcher.
- path = "web-app/filter-mapping";
- dig.addCallMethod(path, "addFilterMapping", 3);
- dig.addCallParam(path + "/filter-name", 0);
- dig.addCallParam(path + "/url-pattern", 1);
- dig.addCallParam(path + "/servlet-name", 2);
- dig.push(this);
- try {
- dig.parse(webXml);
- this.setFilterName(filterName, context);
- // Store Instance to context attribute.
- context.setAttribute(CONTEXT_ATTRIBUTE,this);
- } catch (IOException e) {
- String message = Messages
- .getMessage(Messages.PARSING_WEB_XML_IO_ERROR);
- _log.error(message, e);
- throw new ServletException(message, e);
- } catch (SAXException e) {
- String message = Messages
- .getMessage(Messages.PARSING_WEB_XML_SAX_ERROR);
- _log.error(message, e);
- throw new ServletException(message, e);
- } finally {
- try {
- webXml.close();
- } catch (IOException e) {
- // this exception don't affect any aspects of work and can be
- // ignored.
- }
- }
+ });
+ dig.setNamespaceAware(false);
+ // dig.setUseContextClassLoader(true);
+ dig.setClassLoader(this.getClass().getClassLoader());
+ // Parsing rules.
+ // Servlets.
+ String path = "web-app/servlet";
+ dig.addObjectCreate(path, ServletBean.class);
+ dig.addBeanPropertySetter(path + "/servlet-name", "servletName");
+ dig.addBeanPropertySetter(path + "/servlet-class", "servletClass");
+ dig.addBeanPropertySetter(path + "/display-name", "displayName");
+ dig.addBeanPropertySetter(path + "/description");
+ dig.addSetNext(path, "addServlet");
+ // Filters
+ path = "web-app/filter";
+ dig.addObjectCreate(path, FilterBean.class);
+ dig.addBeanPropertySetter(path + "/filter-name", "filterName");
+ dig.addBeanPropertySetter(path + "/filter-class", "filterClass");
+ dig.addBeanPropertySetter(path + "/display-name", "displayName");
+ dig.addBeanPropertySetter(path + "/description");
+ dig.addSetNext(path, "addFilter");
+ // Servlet mappings
+ path = "web-app/servlet-mapping";
+ dig.addCallMethod(path, "addServletMapping", 2);
+ dig.addCallParam(path + "/servlet-name", 0);
+ dig.addCallParam(path + "/url-pattern", 1);
+ // Filter mappings
+ // TODO - parse dispatcher.
+ path = "web-app/filter-mapping";
+ dig.addCallMethod(path, "addFilterMapping", 3);
+ dig.addCallParam(path + "/filter-name", 0);
+ dig.addCallParam(path + "/url-pattern", 1);
+ dig.addCallParam(path + "/servlet-name", 2);
+ dig.push(this);
+ try {
+ dig.parse(webXml);
+ this.setFilterName(filterName, context);
+ this.findFacesServlet(context);
+ // Store Instance to context attribute.
+ context.setAttribute(CONTEXT_ATTRIBUTE, this);
+ } catch (IOException e) {
+ String message = Messages
+ .getMessage(Messages.PARSING_WEB_XML_IO_ERROR);
+ _log.error(message, e);
+ throw new ServletException(message, e);
+ } catch (SAXException e) {
+ String message = Messages
+ .getMessage(Messages.PARSING_WEB_XML_SAX_ERROR);
+ _log.error(message, e);
+ throw new ServletException(message, e);
+ } finally {
+ try {
+ webXml.close();
+ } catch (IOException e) {
+ // this exception don't affect any aspects of work and can be
+ // ignored.
+ }
+ }
}
+ private void findFacesServlet(ServletContext context) {
+ for (Iterator<Entry<String, ServletBean>> servletsIterator = _servlets
+ .entrySet().iterator(); servletsIterator.hasNext();) {
+ Entry<String, ServletBean> servletEntry = servletsIterator.next();
+ String servletClass = servletEntry.getValue().getServletClass();
+ if("javax.faces.webapp.FacesServlet".equals(servletClass)){
+ Mapping mapping = checkMapping(servletEntry.getValue().getMappings());
+ if(null != mapping){
+ this._facesServletPrefix = mapping.getPrefix();
+ this._facesServletSuffix = mapping.getSuffix();
+ }
+ }
+ }
+
+ }
+
public void addServlet(ServletBean bean) {
String name = bean.getServletName();
if (null != name) {
@@ -220,12 +244,11 @@
}
/**
- * Convert {@link org.ajax4jsf.resource.InternetResource } key to
- * real URL for handle by chameleon filter, depend of mapping in WEB.XML .
- * For prefix or * mapping, prepend servlet prefix and default Resource
- * prefix to key. For suffix mapping, prepend with resource prefix and
- * append default faces suffix to URL ( before request param ). After
- * conversion, call
+ * Convert {@link org.ajax4jsf.resource.InternetResource } key to real URL
+ * for handle by chameleon filter, depend of mapping in WEB.XML . For prefix
+ * or * mapping, prepend servlet prefix and default Resource prefix to key.
+ * For suffix mapping, prepend with resource prefix and append default faces
+ * suffix to URL ( before request param ). After conversion, call
* {@link javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext, java.lang.String)}
* and
* {@link javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)} .
@@ -360,7 +383,8 @@
*
* @param filterName
* The filterName to set.
- * @param context TODO
+ * @param context
+ * TODO
*/
void setFilterName(String filterName, ServletContext context) {
if (null == filterName) {
@@ -377,21 +401,30 @@
Messages.FILTER_NOT_FOUND_ERROR, filterName));
}
// find faces servlet
- checkMapping(filter.getMappings());
+ Mapping mapping = checkMapping(filter.getMappings());
// Filter mapped only to servlet.
- if (_facesFilterPrefix == null && _facesFilterSuffix == null) {
+ if (null == mapping) {
for (Iterator sevlets = filter.getServlets().iterator(); sevlets
.hasNext()
&& _facesFilterPrefix == null && _facesFilterSuffix == null;) {
String servletname = (String) sevlets.next();
ServletBean servlet = (ServletBean) _servlets.get(servletname);
if (null != servlet) {
- checkMapping(servlet.getMappings());
+ mapping = checkMapping(servlet.getMappings());
}
}
}
- String resourcePrefix = (String) context.getAttribute(RESOURCE_URI_PREFIX_PARAM);
- if(null == resourcePrefix){
+ if (null != mapping) {
+ setFacesFilterPrefix(mapping.getPrefix());
+ setFacesFilterSuffix(mapping.getSuffix());
+ } else {
+ throw new IllegalStateException(Messages.getMessage(
+ Messages.NO_PREFIX_OR_SUFFIX_IN_FILTER_MAPPING_ERROR,
+ filterName));
+ }
+ String resourcePrefix = (String) context
+ .getAttribute(RESOURCE_URI_PREFIX_PARAM);
+ if (null == resourcePrefix) {
resourcePrefix = RESOURCE_URI_PREFIX;
}
if (null != _facesFilterPrefix) {
@@ -399,37 +432,42 @@
if (_facesFilterPrefix.endsWith("/")) {
setResourcePrefix(resourcePrefix);
} else {
- setResourcePrefix("/"+resourcePrefix);
+ setResourcePrefix("/" + resourcePrefix);
}
} else if (null != _facesFilterSuffix) {
_prefixMapping = false;
- setResourcePrefix("/"+resourcePrefix);
- } else {
- throw new IllegalStateException(Messages.getMessage(
- Messages.NO_PREFIX_OR_SUFFIX_IN_FILTER_MAPPING_ERROR,
- filterName));
+ setResourcePrefix("/" + resourcePrefix);
}
}
- private void checkMapping(Set mappings) {
+ private Mapping checkMapping(Set mappings) {
+ Mapping mapping = null;
if (null != mappings) {
for (Iterator iter = mappings.iterator(); iter.hasNext();) {
- String mapping = (String) iter.next();
+ String mappingPattern = (String) iter.next();
// first test - for prefix, like /xxx/*
// TODO - select correct dispatcher.
- if (mapping.endsWith("*")) {
- setFacesFilterPrefix(mapping.substring(0,
- mapping.length() - 1));
+ if (mappingPattern.endsWith("*")) {
+ if (null == mapping) {
+ mapping = new Mapping();
+ }
+ int cut = mappingPattern.endsWith("/*")?2:1;
+ mapping.setPrefix(mappingPattern.substring(0,
+ mappingPattern.length() - cut));
break;
} else
// test for suffix mapping, eg *.xxx
- if (mapping.startsWith("*")) {
- setFacesFilterSuffix(mapping.substring(1));
+ if (mappingPattern.startsWith("*")) {
+ if (null == mapping) {
+ mapping = new Mapping();
+ }
+ mapping.setSuffix(mappingPattern.substring(1));
} else {
// Fixed mapping - do not use it.
}
}
}
+ return mapping;
}
/**
@@ -438,4 +476,53 @@
public boolean isPrefixMapping() {
return _prefixMapping;
}
+
+ private static class Mapping {
+ private String prefix;
+ private String suffix;
+
+ /**
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * @param prefix
+ * the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * @return the suffix
+ */
+ public String getSuffix() {
+ return suffix;
+ }
+
+ /**
+ * @param suffix
+ * the suffix to set
+ */
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+ }
+
+ /**
+ * @return the facesServletPrefix
+ */
+ public String getFacesServletPrefix() {
+ return _facesServletPrefix;
+ }
+
+ /**
+ * @return the facesServletSuffix
+ */
+ public String getFacesServletSuffix() {
+ return _facesServletSuffix;
+ }
}
17 years, 2 months
JBoss Rich Faces SVN: r3660 - in trunk/extensions/portlet/src: main/java/org/ajax4jsf/portlet/application and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-10-31 21:00:16 -0400 (Wed, 31 Oct 2007)
New Revision: 3660
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/context/AbstractExternalContext.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
Log:
Continue to implement JSR-301 bridge. Finish requrements from PLT 5.
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-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -4,6 +4,7 @@
package org.ajax4jsf.portlet;
import java.io.PrintWriter;
+import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.FacesException;
@@ -35,7 +36,7 @@
public class AjaxPortletBridge extends AbstractAjaxBridge implements Bridge {
private static final Log log = LogFactory.getLog(AjaxPortletBridge.class);
- private PortletConfig portletConfig;
+ private PortletConfig portletConfig;
/*
* (non-Javadoc)
@@ -76,14 +77,17 @@
throws BridgeException {
initRequest(request, response, Bridge.PortletPhase.ActionPhase);
FacesContext facesContext = getFacesContext(request, response);
- PortletViewState windowState = PortletStateHolder.getInstance(facesContext).getWindowState(facesContext);
- request.setAttribute(Bridge.IS_POSTBACK_ATTRIBUTE, Boolean.valueOf(null != windowState.getViewId()));
+ PortletViewState windowState = PortletStateHolder.getInstance(
+ facesContext).getWindowState(facesContext);
+ windowState.restoreRequest(facesContext, false);
+ // request.setAttribute(Bridge.IS_POSTBACK_ATTRIBUTE,
+ // Boolean.valueOf(null != windowState.getViewId()));
try {
execute(facesContext);
- facesContext.getApplication().getStateManager().saveSerializedView(facesContext);
- // save request scope variables and Faces Messages.
- windowState.saveMessages(facesContext);
- windowState.saveBeans(facesContext);
+ facesContext.getApplication().getStateManager().saveSerializedView(
+ facesContext);
+ // save request scope variables and Faces Messages.
+ windowState.saveRequest(facesContext);
// saveView(facesContext);
} catch (Exception e) {
log.error("Error processing execute lifecycle", e);
@@ -110,46 +114,46 @@
response.setContentType(contenttype);
}
- // 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();
+ // 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();
+ PortletViewState windowState = PortletStateHolder.getInstance(
+ facesContext).getWindowState(facesContext);
+ windowState.restoreRequest(facesContext, true);
+ if (null == facesContext.getViewRoot()) {
+ execute(facesContext);
+ }
+ //
AjaxContext ajaxContext = AjaxContext
.getCurrentInstance(facesContext);
- ajaxContext.getCommonAjaxParameters().put(
- AbstractExternalContext.ACTION__PARAMETER,
+ Map commonAjaxParameters = ajaxContext.getCommonAjaxParameters();
+ commonAjaxParameters.put(AbstractExternalContext.ACTION__PARAMETER,
response.createActionURL().toString());
- ajaxContext.getCommonAjaxParameters().put(
- AbstractExternalContext.PORTLET_MODE_PARAMETER,
- request.getPortletMode().toString());
- ajaxContext.getCommonAjaxParameters().put(
+ commonAjaxParameters.put(
+ AbstractExternalContext.PORTLET_MODE_PARAMETER, request
+ .getPortletMode().toString());
+ commonAjaxParameters.put(
AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
- ajaxContext.getCommonAjaxParameters().put(
- AbstractExternalContext.PORTLET_NAME_PARAMETER, getPortletConfig().getPortletName());
- PortletViewState windowState = PortletStateHolder.getInstance(facesContext).getWindowState(facesContext);
- request.setAttribute(Bridge.IS_POSTBACK_ATTRIBUTE, Boolean.valueOf(null != windowState.getViewId()));
- windowState.restoreMessages(facesContext);
- windowState.restoreBeans(facesContext);
- if(null == facesContext.getViewRoot()){
- execute(facesContext);
- }
-//
+ commonAjaxParameters.put(
+ AbstractExternalContext.PORTLET_NAME_PARAMETER,
+ getPortletConfig().getPortletName());
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,
@@ -182,11 +186,12 @@
protected void initRequest(PortletRequest request,
PortletResponse response, PortletPhase actionPhase)
throws BridgeException {
- if( null == request.getAttribute(Bridge.DEFAULT_VIEWID)){
- throw new BridgeDefaultViewNotSpecifiedException();
- }
- request.setAttribute(Bridge.PORTLET_LIFECYCLE_PHASE, actionPhase);
- request.setAttribute(AbstractExternalContext.PORTLET_CONFIG_ATTRIBUTE, getPortletConfig());
+ if (null == request.getAttribute(Bridge.DEFAULT_VIEWID)) {
+ throw new BridgeDefaultViewNotSpecifiedException();
+ }
+ request.setAttribute(Bridge.PORTLET_LIFECYCLE_PHASE, actionPhase);
+ request.setAttribute(AbstractExternalContext.PORTLET_CONFIG_ATTRIBUTE,
+ getPortletConfig());
}
/**
@@ -205,8 +210,9 @@
@Override
protected String getInitParameter(String name) {
String initParameter = portletConfig.getInitParameter(name);
- if(null == initParameter){
- initParameter = portletConfig.getPortletContext().getInitParameter(name);
+ if (null == initParameter) {
+ initParameter = portletConfig.getPortletContext().getInitParameter(
+ name);
}
return initParameter;
}
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-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewHandler.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -4,15 +4,21 @@
package org.ajax4jsf.portlet.application;
import java.io.IOException;
+import java.io.Writer;
import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.StateManager;
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.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
import javax.portlet.RenderResponse;
import javax.portlet.faces.Bridge;
+import javax.servlet.ServletContext;
import org.ajax4jsf.application.AjaxViewHandler;
import org.ajax4jsf.component.AjaxViewRoot;
@@ -50,17 +56,7 @@
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) {
String actionURL = super.getActionURL(context, url);
if( null != context.getExternalContext().getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE)){
@@ -72,4 +68,270 @@
protected synchronized void fillChain(FacesContext context) {
// Do nothing - chain must be filled in AjaxViewHandler
}
+
+ // TODO - create own implementation. Now, this code are copied from MyFaces implementation.
+ @Override
+ public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException,
+ FacesException
+ {
+ // Get the renderPolicy from the requestScope
+ Bridge.BridgeRenderPolicy renderPolicy = (Bridge.BridgeRenderPolicy) context
+ .getExternalContext()
+ .getRequestMap()
+ .get(
+ AbstractExternalContext.RENDER_POLICY_ATTRIBUTE);
+
+ if (renderPolicy == null)
+ {
+ renderPolicy = Bridge.BridgeRenderPolicy.valueOf("DEFAULT");
+ }
+
+ if (context.getExternalContext().getContext() instanceof ServletContext
+ || renderPolicy == Bridge.BridgeRenderPolicy.ALWAYS_DELEGATE)
+ {
+ super.renderView(context, viewToRender);
+ return;
+ }
+ else if (renderPolicy == Bridge.BridgeRenderPolicy.DEFAULT)
+ {
+ try
+ {
+ super.renderView(context, viewToRender);
+ return;
+ }
+ catch (Throwable t)
+ {
+ // catch all throws and swallow -- falling through to our own
+ // render
+ }
+ }
+
+ // suppress rendering if "rendered" property on the component is
+ // false
+ if (!viewToRender.isRendered())
+ {
+ return;
+ }
+
+ ExternalContext extContext = context.getExternalContext();
+ RenderResponse renderResponse = (RenderResponse) extContext.getResponse();
+
+ try
+ {
+
+ // set request attribute indicating we can deal with content
+ // that is supposed to be delayed until after JSF tree is ouput.
+ extContext.getRequestMap().put(Bridge.RENDER_CONTENT_AFTER_VIEW, Boolean.TRUE);
+ // TODO JSF 1.2 - executePageToBuildView() creates
+ // ViewHandlerResponseWrapper
+ // to handle error page and text that exists after the <f:view> tag
+ // among other things which have lots of servlet dependencies -
+ // we're skipping this for now for portlet
+ extContext.dispatch(viewToRender.getViewId());
+ /*
+ * if (executePageToBuildView(context, viewToRender)) { response.flushBuffer(); return; }
+ */
+ }
+ catch (IOException e)
+ {
+ throw new FacesException(e);
+ }
+
+ // set up the ResponseWriter
+ RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKit renderKit = renderFactory.getRenderKit(context, viewToRender.getRenderKitId());
+
+ ResponseWriter oldWriter = context.getResponseWriter();
+ StringBuilderWriter strWriter = new StringBuilderWriter(context, 4096);
+ ResponseWriter newWriter;
+ if (null != oldWriter)
+ {
+ newWriter = oldWriter.cloneWithWriter(strWriter);
+ }
+ else
+ {
+ newWriter = renderKit.createResponseWriter(strWriter, null,
+ renderResponse.getCharacterEncoding());
+ }
+ context.setResponseWriter(newWriter);
+
+ newWriter.startDocument();
+
+ doRenderView(context, viewToRender);
+
+ newWriter.endDocument();
+
+ // replace markers in the body content and write it to response.
+
+ ResponseWriter responseWriter;
+ if (null != oldWriter)
+ {
+ responseWriter = oldWriter.cloneWithWriter(renderResponse.getWriter());
+ }
+ else
+ {
+ responseWriter = newWriter.cloneWithWriter(renderResponse.getWriter());
+ }
+ context.setResponseWriter(responseWriter);
+
+ strWriter.write(responseWriter);
+
+ if (null != oldWriter)
+ {
+ context.setResponseWriter(oldWriter);
+ }
+
+ Object content = extContext.getRequestMap().get(Bridge.AFTER_VIEW_CONTENT);
+ if (content != null)
+ {
+ if (content instanceof char[])
+ {
+ renderResponse.getWriter().write(new String((byte[]) content));
+ }
+ else if (content instanceof byte[])
+ {
+ renderResponse.getWriter().write(new String((char[]) content));
+ }
+ else
+ {
+ throw new IOException("PortletViewHandlerImpl: invalid" + "AFTER_VIEW_CONTENT buffer type");
+ }
+ }
+ renderResponse.flushBuffer();
+ }
+
+ /**
+ * <p>
+ * This is a separate method to account for handling the content after the view tag.
+ * </p>
+ *
+ * <p>
+ * Create a new ResponseWriter around this response's Writer. Set it into the FacesContext, saving
+ * the old one aside.
+ * </p>
+ *
+ * <p>
+ * call encodeBegin(), encodeChildren(), encodeEnd() on the argument <code>UIViewRoot</code>.
+ * </p>
+ *
+ * <p>
+ * Restore the old ResponseWriter into the FacesContext.
+ * </p>
+ *
+ * <p>
+ * Write out the after view content to the response's writer.
+ * </p>
+ *
+ * <p>
+ * Flush the response buffer, and remove the after view content from the request scope.
+ * </p>
+ *
+ * @param context
+ * the <code>FacesContext</code> for the current request
+ * @param viewToRender
+ * the view to render
+ * @throws IOException
+ * if an error occurs rendering the view to the client
+ */
+ private void doRenderView(FacesContext context, UIViewRoot viewToRender) throws IOException,
+ FacesException
+ {
+ ExternalContext extContext = context.getExternalContext();
+ viewToRender.encodeAll(context);
+ }
+
+ private static final class StringBuilderWriter extends Writer
+ {
+ private StringBuilder mBuilder;
+ private FacesContext mContext;
+
+ // TODO: These bridge needs to use it's own constants here. This will
+ // confine
+ // us to only work with the R.I.
+ private static final String SAVESTATE_FIELD_MARKER = "~com.sun.faces.saveStateFieldMarker~";
+
+ public StringBuilderWriter(FacesContext context, int initialCapacity)
+ {
+ if (initialCapacity < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ mBuilder = new StringBuilder(initialCapacity);
+ mContext = context;
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException
+ {
+ if (off < 0 || off > cbuf.length || len < 0 || off + len > cbuf.length || off + len < 0)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ else if (len == 0)
+ {
+ return;
+ }
+ mBuilder.append(cbuf, off, len);
+ }
+
+ @Override
+ public void flush() throws IOException
+ {
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ }
+
+ /**
+ * Write a string.
+ *
+ * @param str
+ * String to be written
+ */
+ @Override
+ public void write(String str)
+ {
+ mBuilder.append(str);
+ }
+
+ @Override
+ public void write(String str, int off, int len)
+ {
+ write(str.substring(off, off + len));
+ }
+
+ public StringBuilder getBuffer()
+ {
+ return mBuilder;
+ }
+
+ @Override
+ public String toString()
+ {
+ return mBuilder.toString();
+ }
+
+ public void write(Writer writer) throws IOException
+ {
+ // TODO: Buffer?
+ StateManager stateManager = mContext.getApplication().getStateManager();
+ Object stateToWrite = stateManager.saveView(mContext);
+ int markLen = SAVESTATE_FIELD_MARKER.length();
+ int pos = 0;
+ int tildeIdx = mBuilder.indexOf(SAVESTATE_FIELD_MARKER);
+ while (tildeIdx > 0)
+ {
+ writer.write(mBuilder.substring(pos, (tildeIdx - pos)));
+ stateManager.writeState(mContext, stateToWrite);
+ pos += tildeIdx + markLen;
+ tildeIdx = mBuilder.indexOf(SAVESTATE_FIELD_MARKER, pos);
+ }
+ writer.write(mBuilder.substring(pos));
+ }
+ }
+
+
}
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-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -14,9 +14,15 @@
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.render.ResponseStateManager;
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeDefaultViewNotSpecifiedException;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.portlet.context.AbstractExternalContext;
+
/**
* @author asmirnov
*
@@ -45,7 +51,8 @@
javax.servlet.ServletContext.class,
javax.servlet.ServletRequest.class,
javax.servlet.ServletResponse.class,
- javax.servlet.http.HttpSession.class };
+ javax.servlet.http.HttpSession.class,
+ AjaxContext.class};
private static final String[] excludedRequestAttributes = {
"javax.servlet.include", ResponseStateManager.VIEW_STATE_PARAM };
@@ -246,8 +253,8 @@
beans.put(entry.getKey(), entry.getValue());
}
}
- _requestParameters = facesContext.getExternalContext()
- .getRequestParameterValuesMap();
+ _requestParameters = new HashMap<String, String[]>(facesContext
+ .getExternalContext().getRequestParameterValuesMap());
}
public void restoreBeans(FacesContext facesContext) {
@@ -259,4 +266,37 @@
requestMap.put(REQUEST_PARAMETERS_ATTRIBUTE, _requestParameters);
}
+ public void restoreRequest(FacesContext facesContext, boolean b) {
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+ if (b) {
+ restoreMessages(facesContext);
+ restoreBeans(facesContext);
+ }
+ String viewId = getViewId();
+ if(null == viewId && Bridge.PortletPhase.ActionPhase.equals(requestMap.get(Bridge.PORTLET_LIFECYCLE_PHASE))){
+ viewId = (String) externalContext.getRequestParameterMap().get(AbstractExternalContext.VIEW_ID_PARAMETER);
+ }
+ if (null == viewId) {
+ viewId = (String) requestMap.get(Bridge.DEFAULT_VIEWID);
+ if (null == viewId) {
+ throw new BridgeDefaultViewNotSpecifiedException("could'n determine portlet view id");
+ }
+ } else {
+ requestMap.put(Bridge.IS_POSTBACK_ATTRIBUTE, Boolean.TRUE);
+ }
+ setViewId(viewId);
+ requestMap.put(AbstractExternalContext.VIEW_ID_PARAMETER, viewId);
+
+ }
+
+ public void saveRequest(FacesContext facesContext) {
+ UIViewRoot root = facesContext.getViewRoot();
+ if (null != root) {
+ setViewId(root.getViewId());
+ }
+ saveBeans(facesContext);
+ saveMessages(facesContext);
+ }
+
}
Modified: trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
--- trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-10-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -53,12 +53,16 @@
*/
package org.ajax4jsf.portlet.context;
+import java.net.MalformedURLException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
+import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.portlet.faces.Bridge;
/**
*
@@ -82,395 +86,423 @@
*
*/
public abstract class AbstractExternalContext extends ExternalContext {
-
- /**
- * Request parameter to store current View Id.
- */
- public static final String VIEW_ID_PARAMETER ="org.ajax4jsf.portlet.VIEWID";
- /**
- * 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";
- public static final Object PORTLET_MODE_PARAMETER = "org.ajax4jsf.portlet.MODE";
- public static final Object PORTLET_NAME_PARAMETER = "org.ajax4jsf.portlet.NAME";
-
- protected static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ /**
+ * Request parameter to store current View Id.
+ */
+ public static final String VIEW_ID_PARAMETER = "org.ajax4jsf.portlet.VIEWID";
+ /**
+ * 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";
+ public static final Object PORTLET_MODE_PARAMETER = "org.ajax4jsf.portlet.MODE";
+ public static final Object PORTLET_NAME_PARAMETER = "org.ajax4jsf.portlet.NAME";
+
+ protected static final String[] EMPTY_STRING_ARRAY = new String[0];
public static final String PORTLET_CONFIG_ATTRIBUTE = "org.ajax4jsf.portlet.CONFIG";
- // TODO - optimization.
- private Map applicationMap;
+ public static final Object RENDER_POLICY_ATTRIBUTE = "org.ajax4jsf.portlet.RENDER_POLICY";
+ // TODO - optimization.
+ private Map applicationMap;
- private Map initParameterMap;
+ private Map initParameterMap;
- private Map requestHeaderMap = null;
+ private Map requestHeaderMap = null;
- private Map requestHeaderValues;
+ private Map requestHeaderValues;
- private Map requestMap;
+ private Map requestMap;
- private Map requestParameterMap;
+ private Map requestParameterMap;
- private Map requestParameterValuesMap;
+ private Map requestParameterValuesMap;
- private Map sessionMap;
+ private Map sessionMap;
- private Object request;
+ private Object request;
- private Object response;
+ private Object response;
- private boolean http;
+ private boolean http;
- private Map actionSettings;
+ private Map actionSettings;
- private Object context;
-
+ private Object context;
- /**
- *
- * @param response
- *
- * @param request
- *
- * @param context
- *
- * @param defaultContext -
- *
- * default implementation of <code>ExternalFacesContext</code>.
- *
- */
- public AbstractExternalContext(Object context, Object request,
- Object response) {
- super();
- this.context = context;
- this.request = request;
- this.response = response;
- }
+ /**
+ *
+ * @param context
+ * @param request
+ * @param response
+ * @param defaultContext -
+ *
+ * default implementation of <code>ExternalFacesContext</code>.
+ *
+ */
+ public AbstractExternalContext(Object context, Object request,
+ Object response) {
+ super();
+ this.context = context;
+ this.request = request;
+ this.response = response;
+ }
- protected abstract String getNamespace();
-
-
- public String encodeNamespace(String name) {
-
- return getNamespace()+name;
- }
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
- *
- */
- public Map getApplicationMap() {
- if (this.applicationMap == null) {
- this.applicationMap = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return getContextAttributeNames();
- }
+ protected abstract String getNamespace();
- protected Object getAttribute(String name) {
- return getContextAttribute(name);
- }
+ public String encodeNamespace(String name) {
- protected void setAttribute(String name, Object value) {
- setContextAttribute(name, value);
- }
+ return getNamespace() + name;
+ }
- protected void removeAttribute(String name) {
- removeContextAttribute(name);
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
+ *
+ */
+ public Map getApplicationMap() {
+ if (this.applicationMap == null) {
+ this.applicationMap = new ContextAttributesMap() {
+ protected Enumeration getEnumeration() {
+ return getContextAttributeNames();
+ }
+
+ protected Object getAttribute(String name) {
+ return getContextAttribute(name);
+ }
+
+ protected void setAttribute(String name, Object value) {
+ setContextAttribute(name, value);
+ }
+
+ protected void removeAttribute(String name) {
+ removeContextAttribute(name);
+ }
+ };
}
- };
+ return this.applicationMap;
}
- return this.applicationMap;
- }
- protected abstract void removeContextAttribute(String name);
+ protected abstract void removeContextAttribute(String name);
- protected abstract void setContextAttribute(String name, Object value);
+ protected abstract void setContextAttribute(String name, Object value);
- protected abstract Object getContextAttribute(String name);
+ protected abstract Object getContextAttribute(String name);
- protected abstract Enumeration getContextAttributeNames();
+ protected abstract Enumeration getContextAttributeNames();
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getAuthType()
- */
- public Object getContext() {
- return this.context;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getAuthType()
+ */
+ public Object getContext() {
+ return this.context;
+ }
- /**
- * @param context
- */
- public void setContext(Object context) {
- this.context = context;
- }
+ /**
+ * @param context
+ */
+ public void setContext(Object context) {
+ this.context = context;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
- */
- public Map getInitParameterMap() {
- if (this.initParameterMap == null) {
- this.initParameterMap = new ContextAttributesMap() {
- protected Object getAttribute(String name) {
- return getInitParameter(name);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ */
+ public Map getInitParameterMap() {
+ if (this.initParameterMap == null) {
+ this.initParameterMap = new ContextAttributesMap() {
+ protected Object getAttribute(String name) {
+ return getInitParameter(name);
+ }
- protected void setAttribute(String name, Object value) {
- throw new UnsupportedOperationException();
- }
+ protected void setAttribute(String name, Object value) {
+ throw new UnsupportedOperationException();
+ }
- protected Enumeration getEnumeration() {
- return getInitParametersNames();
+ protected Enumeration getEnumeration() {
+ return getInitParametersNames();
+ }
+ };
}
- };
+ return this.initParameterMap;
}
- return this.initParameterMap;
- }
- /**
- * Hoock method for initialization parameters.
- *
- * @return
- */
- protected abstract Enumeration getInitParametersNames();
+ /**
+ * Hoock method for initialization parameters.
+ *
+ * @return
+ */
+ protected abstract Enumeration getInitParametersNames();
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getRequest()
- */
- public Object getRequest() {
- return this.request;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getRequest()
+ */
+ public Object getRequest() {
+ return this.request;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#setRequest(java.lang.Object)
- */
- public void setRequest(Object request) {
- this.request = request;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#setRequest(java.lang.Object)
+ */
+ public void setRequest(Object request) {
+ this.request = request;
+ }
- public Map getRequestCookieMap() {
- // Portlet environment don't have methods to use cookies.
- return Collections.EMPTY_MAP;
- }
+ public Map getRequestCookieMap() {
+ // Portlet environment don't have methods to use cookies.
+ return Collections.EMPTY_MAP;
+ }
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
- *
- */
- public Map getRequestHeaderMap() {
- if (this.requestHeaderMap == null) {
- this.requestHeaderMap = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return getRequestHeaderNames();
- }
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
+ *
+ */
+ public Map getRequestHeaderMap() {
+ if (this.requestHeaderMap == null) {
+ this.requestHeaderMap = new ContextAttributesMap() {
+ protected Enumeration getEnumeration() {
+ return getRequestHeaderNames();
+ }
- protected Object getAttribute(String name) {
- return getRequestHeader(name);
- }
+ protected Object getAttribute(String name) {
+ return getRequestHeader(name);
+ }
- protected void setAttribute(String name, Object value) {
- throw new UnsupportedOperationException();
+ protected void setAttribute(String name, Object value) {
+ throw new UnsupportedOperationException();
+ }
+ };
}
- };
+ return this.requestHeaderMap;
}
- return this.requestHeaderMap;
- }
- protected abstract Object getRequestHeader(String name);
+ protected abstract Object getRequestHeader(String name);
- protected abstract Enumeration getRequestHeaderNames();
+ protected abstract Enumeration getRequestHeaderNames();
- public Map getRequestHeaderValuesMap() {
- //
- if (this.requestHeaderValues == null) {
- this.requestHeaderValues = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return getRequestHeaderNames();
- }
+ public Map getRequestHeaderValuesMap() {
+ //
+ if (this.requestHeaderValues == null) {
+ this.requestHeaderValues = new ContextAttributesMap() {
+ protected Enumeration getEnumeration() {
+ return getRequestHeaderNames();
+ }
- protected Object getAttribute(String name) {
- return getRequestHeaderValues(name);
- }
+ protected Object getAttribute(String name) {
+ return getRequestHeaderValues(name);
+ }
- protected void setAttribute(String name, Object value) {
- throw new UnsupportedOperationException();
+ protected void setAttribute(String name, Object value) {
+ throw new UnsupportedOperationException();
+ }
+ };
}
- };
+ return this.requestHeaderValues;
}
- return this.requestHeaderValues;
- }
- protected abstract String[] getRequestHeaderValues(String name);
+ protected abstract String[] getRequestHeaderValues(String name);
- public Map getRequestMap() {
- if (this.requestMap == null) {
- this.requestMap = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return getRequestAttributeNames();
- }
+ public Map getRequestMap() {
+ if (this.requestMap == null) {
+ this.requestMap = new ContextAttributesMap() {
+ protected Enumeration getEnumeration() {
+ return getRequestAttributeNames();
+ }
- protected Object getAttribute(String name) {
- return getRequestAttribute(name);
- }
+ protected Object getAttribute(String name) {
+ return getRequestAttribute(name);
+ }
- protected void setAttribute(String name, Object value) {
- setRequestAttribute(name, value);
- }
+ protected void setAttribute(String name, Object value) {
+ setRequestAttribute(name, value);
+ }
- protected void removeAttribute(String name) {
- removeRequestAttribute(name);
+ protected void removeAttribute(String name) {
+ removeRequestAttribute(name);
+ }
+ };
}
- };
+ return this.requestMap;
}
- return this.requestMap;
- }
- protected abstract void removeRequestAttribute(String name);
+ protected abstract void removeRequestAttribute(String name);
- protected abstract void setRequestAttribute(String name, Object value);
+ protected abstract void setRequestAttribute(String name, Object value);
- protected abstract Object getRequestAttribute(String name);
+ protected abstract Object getRequestAttribute(String name);
- protected abstract Enumeration getRequestAttributeNames();
+ protected abstract Enumeration getRequestAttributeNames();
- public Map getRequestParameterMap() {
- //
- if (this.requestParameterMap == null) {
- this.requestParameterMap = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return enumerateRequestParameterNames();
- }
+ public Map getRequestParameterMap() {
+ //
+ if (this.requestParameterMap == null) {
+ this.requestParameterMap = new ContextAttributesMap() {
+ protected Enumeration getEnumeration() {
+ return enumerateRequestParameterNames();
+ }
- protected Object getAttribute(String name) {
- return getRequestParameter(name);
- }
+ protected Object getAttribute(String name) {
+ return getRequestParameter(name);
+ }
- protected void setAttribute(String name, Object value) {
- throw new UnsupportedOperationException();
+ protected void setAttribute(String name, Object value) {
+ throw new UnsupportedOperationException();
+ }
+ };
}
- };
+ return this.requestParameterMap;
}
- return this.requestParameterMap;
- }
- protected abstract Object getRequestParameter(String name);
+ protected abstract Object getRequestParameter(String name);
- protected abstract Enumeration enumerateRequestParameterNames();
+ protected abstract Enumeration enumerateRequestParameterNames();
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getRequestParameterNames()
- *
- */
- public Iterator getRequestParameterNames() {
- return new EnumerationIterator(enumerateRequestParameterNames());
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterNames()
+ *
+ */
+ public Iterator getRequestParameterNames() {
+ return new EnumerationIterator(enumerateRequestParameterNames());
+ }
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
- *
- */
- public Map getRequestParameterValuesMap() {
- if (this.requestParameterValuesMap == null) {
- this.requestParameterValuesMap = new ContextAttributesMap() {
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
+ *
+ */
+ public Map getRequestParameterValuesMap() {
+ if (this.requestParameterValuesMap == null) {
+ this.requestParameterValuesMap = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return enumerateRequestParameterNames();
- }
+ protected Enumeration getEnumeration() {
+ return enumerateRequestParameterNames();
+ }
- protected Object getAttribute(String name) {
- return getRequestParameterValues(name);
- }
+ protected Object getAttribute(String name) {
+ return getRequestParameterValues(name);
+ }
- protected void setAttribute(String name, Object value) {
- throw new UnsupportedOperationException();
+ protected void setAttribute(String name, Object value) {
+ throw new UnsupportedOperationException();
+ }
+ };
}
- };
+ return this.requestParameterValuesMap;
}
- return this.requestParameterValuesMap;
- }
- protected abstract Object getRequestParameterValues(String name);
+ protected abstract Object getRequestParameterValues(String name);
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getResponse()
- *
- */
- public void setResponse(Object response) {
- this.response = response;
- }
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getResponse()
+ *
+ */
+ public void setResponse(Object response) {
+ this.response = response;
+ }
- public Object getResponse() {
- return this.response;
- }
+ public Object getResponse() {
+ return this.response;
+ }
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getSessionMap()
- *
- */
- public Map getSessionMap() {
- if (this.sessionMap == null) {
- this.sessionMap = new ContextAttributesMap() {
+ /*
+ *
+ * (non-Javadoc)
+ *
+ *
+ *
+ * @see javax.faces.context.ExternalContext#getSessionMap()
+ *
+ */
+ public Map getSessionMap() {
+ if (this.sessionMap == null) {
+ this.sessionMap = new ContextAttributesMap() {
- protected Enumeration getEnumeration() {
- return getSessionAttributeNames();
- }
+ protected Enumeration getEnumeration() {
+ return getSessionAttributeNames();
+ }
- protected Object getAttribute(String name) {
- return getSessionAttribute(name);
- }
+ protected Object getAttribute(String name) {
+ return getSessionAttribute(name);
+ }
- protected void setAttribute(String name, Object value) {
- setSessionAttribute(name, value);
+ protected void setAttribute(String name, Object value) {
+ setSessionAttribute(name, value);
+ }
+
+ protected void removeAttribute(String name) {
+ removeSessionAttribute(name);
+ }
+
+ };
}
-
- protected void removeAttribute(String name) {
- removeSessionAttribute(name);
- }
-
-
- };
+ return this.sessionMap;
}
- return this.sessionMap;
- }
+ protected abstract void removeSessionAttribute(String name);
- protected abstract void removeSessionAttribute(String name);
+ protected abstract void setSessionAttribute(String name, Object value);
- protected abstract void setSessionAttribute(String name, Object value);
+ protected abstract Object getSessionAttribute(String name);
- protected abstract Object getSessionAttribute(String name);
+ protected abstract Enumeration getSessionAttributeNames();
- protected abstract Enumeration getSessionAttributeNames();
+ protected abstract String createActionUrl(Map parameters);
+
+ public String encodeActionURL(String url) {
+ if (null == url) {
+ throw new NullPointerException();
+ }
+ String actionUrl = url;
+ if (!actionUrl.startsWith("#")) {
+ try {
+ PortalActionURL portalUrl = new PortalActionURL(url);
+ String directLink = portalUrl.getParameter(Bridge.DIRECT_LINK);
+ boolean inContext = portalUrl
+ .isInContext(getRequestContextPath());
+ if (inContext
+ && (null == directLink || false == Boolean
+ .parseBoolean(directLink))) {
+ if (null != directLink) {
+ portalUrl.removeParameter(Bridge.DIRECT_LINK);
+
+ }
+ String viewId = portalUrl.getParameter(VIEW_ID_PARAMETER);
+ actionUrl = createActionUrl(portalUrl.getParameters());
+ }
+ } catch (MalformedURLException e) {
+ throw new FacesException(e);
+ }
+ }
+ return encodeURL(actionUrl);
+ }
+
+ protected abstract String encodeURL(String actionUrl);
}
\ No newline at end of file
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-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -18,7 +18,6 @@
import java.util.Set;
import java.util.regex.Pattern;
-import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContextFactory;
import javax.portlet.ActionRequest;
@@ -31,8 +30,9 @@
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
-import javax.portlet.faces.Bridge;
+import org.ajax4jsf.webapp.WebXml;
+
/**
* Version of the {@link ExternalContext} for a Portlet request. {@link FacesContextFactory} will create instance of this class
* for a portal <code>action</code> phase.
@@ -46,6 +46,10 @@
public PortletContextImpl(PortletContext context, PortletRequest request,
PortletResponse response) {
super(context, request, response);
+ WebXml webXml = (WebXml) context.getAttribute(WebXml.CONTEXT_ATTRIBUTE);
+ if(null != webXml){
+ _servletPath = webXml.getFacesServletPrefix();
+ }
}
public void setResponseCharacterEncoding(String encoding) {
@@ -221,56 +225,24 @@
private static final Pattern directLink = Pattern.compile("");
private static final Pattern viewIdParam = Pattern.compile("");
- /* (non-Javadoc)
- * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
- * JSR-301 requirements, PLT 6.1.3.1 :
- * Return the inputURL, after performing any rewriting needed to ensure that it will correctly identify an addressable URL in the current application. The inputURL is expected to conform to standard URI syntax or more specifically not be the result of calling PortletURL.toString(). When called during the RenderPhase, the inputURL is transformed, encoded, and returned so it can be used as markup into the response. When called during the ActionPhase, the inputURL is transformed and encoded into the ActionResponse as the Faces navigation which resulted from processing the action. To process such an inputURL correctly, this method must:
- o If the inputURL starts with the # character or the inputURL is an absolute path external to this portlet application return the inputURL unchanged.
- o If the inputURL contains the parameter javax.portlet.faces.DirectLink and its value is true then return it without removing this parameter. If the inputURL contains the parameter javax.portlet.faces.DirectLink and its value is false then remove the javax.portlet.faces.DirectLink parameter and value from the queryString and continue processing.
- o Otherwise:
- + Identify the viewId within the inputURL.
- # If the inputURL contains a bridge encoded viewId then extract it from the URL and use this as the viewId.
- # Otherwise if the inputURL is a full path within the portlet application, use the servlet definitions from the web application's web.xml to determine both how the Faces servlet is mapped and whether this URL resolves to the Faces servlet. Derive the view identifier that corresponds to this URL, as follows:
- Note: all resulting viewIds start with a "/".
- * If prefix mapping (such as “/faces/*”) is used for FacesServlet, the viewId is set from the extra path information of the request URI. This corresponds to the path that follows the prefix mapping.
- * If suffix mapping (such as “*.faces”) is used for FacesServlet, the viewId is set from the servlet path information of the request URI, after replacing the suffix with the value of the context initialization parameter named by the symbolic constant ViewHandler.DEFAULT_SUFFIX_PARAM_NAME (if no such context initialization parameter is present, use the value of the symbolic constant ViewHandler.DEFAULT_SUFFIX as the replacement suffix). This corresponds to the path that follows the context path.
- * If the URL doesn't reference a FacesServlet mapping then the viewId is the path that follows the context path.
- + Process the viewId based URL
- # If executed during the ActionPhase, encode the viewId and any additional querystring parameters in the ActionResponse in a way that not only ensures that the appropriate subsequent render will be based on these but also that inappropriate subsequent renders will not. (See section 5.1 concerning request scopes). Return a non-null URL string whose value isn't equal to the inputURL.
- # If executed during the RenderPhase, construct an actionURL by calling getResponse().createActionURL(). Encode the viewId and any additional querystring parameters in this actionURL in a way that not only ensures that the appropriate subsequent render will be based on these parameters but also that inappropriate subsequent renders will not. (See section 5.1 concerning request scopes).. And return actionURL.toString().
-
- Note: the result must not contain doubly encoded querystring parameter values and hence additional processing is required to detect and undo such double encoding when the inputURL is already encoded and the actionURL.toString() does reencoding.
-
- */
- public String encodeActionURL(String url) {
- if (null == url) {
- throw new NullPointerException();
- }
- String actionUrl = url;
- if(!actionUrl.startsWith("#") ){
- try {
- PortalActionURL portalUrl = new PortalActionURL(url);
- if(portalUrl.isInContext(getRequestContextPath()) || !(Boolean.parseBoolean(portalUrl.getParameter(Bridge.DIRECT_LINK)))){
- portalUrl.removeParameter(Bridge.DIRECT_LINK);
- String viewId = portalUrl.getParameter(VIEW_ID_PARAMETER);
- actionUrl = createActionUrl(portalUrl.getParameters());
- }
- } catch (MalformedURLException e) {
- throw new FacesException(e);
- }
- }
- return getPortletResponse().encodeURL(actionUrl);
- }
-
/**
* @param parameters
* @return
*/
+ @Override
protected String createActionUrl(Map parameters){
return "/ajax4jsfPortletBridge/actionUrl/do/nothitg";
}
public String encodeResourceURL(String url) {
+ return encodeURL(url);
+ }
+
+ /**
+ * @param url
+ * @return
+ */
+ protected String encodeURL(String url) {
return getPortletResponse().encodeURL(url);
}
@@ -294,6 +266,8 @@
return new EnumerationIterator(getPortletRequest().getLocales());
}
+ private String _pathInfo = null;
+
public String getRequestPathInfo() {
String pathInfo = (String) getRequestParameter(VIEW_ID_PARAMETER);
if (null == pathInfo) {
@@ -302,8 +276,10 @@
return pathInfo;
}
+ private String _servletPath = null;
+
public String getRequestServletPath() {
- return null;
+ return _servletPath;
}
public Object getSession(boolean create) {
Modified: trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
--- trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-10-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -13,6 +13,7 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import java.util.Set;
import javax.faces.FacesException;
@@ -26,6 +27,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import org.ajax4jsf.context.AjaxContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -34,301 +36,322 @@
*
*/
public class ServletContextImpl extends AbstractExternalContext {
-
- private static final Log _log = LogFactory.getLog(ServletContextImpl.class);
-
- private String namespace;
- /**
- * @param context
- * @param request
- * @param response
- */
- public ServletContextImpl(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
- super(context, request, response);
- }
-
- public void setResponseCharacterEncoding(String encoding) {
-
- getHttpResponse().setCharacterEncoding(encoding);
- }
-
- public String getResponseCharacterEncoding() {
- return getHttpResponse().getCharacterEncoding();
- }
-
-
- public String getResponseContentType() {
- return getHttpResponse().getContentType();
- }
+ private static final Log _log = LogFactory.getLog(ServletContextImpl.class);
- public void setRequestCharacterEncoding(String encoding)
- throws UnsupportedEncodingException {
- getHttpRequest().setCharacterEncoding(encoding);
- }
-
- public String getRequestCharacterEncoding() {
- return getHttpRequest().getCharacterEncoding();
- }
-
-
- public String getRequestContentType() {
- return getHttpRequest().getContentType();
- }
+ private String namespace;
- private HttpServletRequest getHttpRequest() {
- return (HttpServletRequest) getRequest();
- }
+ /**
+ * @param context
+ * @param request
+ * @param response
+ */
+ public ServletContextImpl(ServletContext context,
+ HttpServletRequest request, HttpServletResponse response) {
+ super(context, request, response);
+ }
- private ServletContext getServletContext() {
- return (ServletContext) getContext();
- }
+ public void setResponseCharacterEncoding(String encoding) {
- private HttpServletResponse getHttpResponse() {
- return (HttpServletResponse) getResponse();
- }
+ getHttpResponse().setCharacterEncoding(encoding);
+ }
- protected String getNamespace() {
- if (null == namespace) {
- Object requestParameter = getRequestParameter(NAMESPACE_PARAMETER);
- if (null != requestParameter) {
- namespace = (String) requestParameter;
- if (_log.isDebugEnabled()) {
- _log.debug("Namespace for a portlet instance is "+namespace);
+ public String getResponseCharacterEncoding() {
+ return getHttpResponse().getCharacterEncoding();
+ }
+
+ public String getResponseContentType() {
+ return getHttpResponse().getContentType();
+ }
+
+ public void setRequestCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException {
+ getHttpRequest().setCharacterEncoding(encoding);
+ }
+
+ public String getRequestCharacterEncoding() {
+ return getHttpRequest().getCharacterEncoding();
+ }
+
+ public String getRequestContentType() {
+ return getHttpRequest().getContentType();
+ }
+
+ private HttpServletRequest getHttpRequest() {
+ return (HttpServletRequest) getRequest();
+ }
+
+ private ServletContext getServletContext() {
+ return (ServletContext) getContext();
+ }
+
+ private HttpServletResponse getHttpResponse() {
+ return (HttpServletResponse) getResponse();
+ }
+
+ protected String getNamespace() {
+ if (null == namespace) {
+ 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");
+ }
}
- } else {
- throw new FacesException("AJAX call to portlet without namespace parameter");
- }
+ return namespace;
}
- return namespace;
- }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
- */
- public String getInitParameter(String name) {
- return getServletContext().getInitParameter(name);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String name) {
+ return getServletContext().getInitParameter(name);
+ }
- protected Enumeration getInitParametersNames() {
- return getServletContext().getInitParameterNames();
- }
+ protected Enumeration getInitParametersNames() {
+ return getServletContext().getInitParameterNames();
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
- */
- public URL getResource(String path) throws MalformedURLException {
- return getServletContext().getResource(path);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+ */
+ public URL getResource(String path) throws MalformedURLException {
+ return getServletContext().getResource(path);
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
- */
- public InputStream getResourceAsStream(String path) {
- return getServletContext().getResourceAsStream(path);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+ */
+ public InputStream getResourceAsStream(String path) {
+ return getServletContext().getResourceAsStream(path);
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
- */
- public Set getResourcePaths(String path) {
- return getServletContext().getResourcePaths(path);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+ */
+ public Set getResourcePaths(String path) {
+ return getServletContext().getResourcePaths(path);
+ }
- protected Object getContextAttribute(String name) {
- return getServletContext().getAttribute(name);
- }
+ protected Object getContextAttribute(String name) {
+ return getServletContext().getAttribute(name);
+ }
- protected Enumeration getContextAttributeNames() {
- return getServletContext().getAttributeNames();
- }
+ protected Enumeration getContextAttributeNames() {
+ return getServletContext().getAttributeNames();
+ }
- protected void setContextAttribute(String name, Object value) {
- getServletContext().setAttribute(name, value);
- }
+ protected void setContextAttribute(String name, Object value) {
+ getServletContext().setAttribute(name, value);
+ }
- public String getAuthType() {
- return getHttpRequest().getAuthType();
- }
+ public String getAuthType() {
+ return getHttpRequest().getAuthType();
+ }
- public String getRemoteUser() {
- return getHttpRequest().getRemoteUser();
- }
+ public String getRemoteUser() {
+ return getHttpRequest().getRemoteUser();
+ }
- public String getRequestContextPath() {
- return getHttpRequest().getContextPath();
- }
+ public String getRequestContextPath() {
+ return getHttpRequest().getContextPath();
+ }
- public String getRequestPathInfo() {
- return getHttpRequest().getPathInfo();
- }
+ public String getRequestPathInfo() {
+ return getHttpRequest().getPathInfo();
+ }
- public String getRequestServletPath() {
- return getHttpRequest().getServletPath();
- }
+ public String getRequestServletPath() {
+ return getHttpRequest().getServletPath();
+ }
- protected Enumeration enumerateRequestParameterNames() {
- return getHttpRequest().getParameterNames();
- }
+ protected Enumeration enumerateRequestParameterNames() {
+ return getHttpRequest().getParameterNames();
+ }
- protected Object getRequestAttribute(String name) {
- return getHttpRequest().getAttribute(name);
- }
+ protected Object getRequestAttribute(String name) {
+ return getHttpRequest().getAttribute(name);
+ }
- protected Enumeration getRequestAttributeNames() {
- return getHttpRequest().getAttributeNames();
- }
+ protected Enumeration getRequestAttributeNames() {
+ return getHttpRequest().getAttributeNames();
+ }
- protected Object getRequestParameterValues(String name) {
- return getHttpRequest().getParameterValues(name);
- }
+ protected Object getRequestParameterValues(String name) {
+ return getHttpRequest().getParameterValues(name);
+ }
- protected Object getRequestHeader(String name) {
- return getHttpRequest().getHeader(name);
- }
+ protected Object getRequestHeader(String name) {
+ return getHttpRequest().getHeader(name);
+ }
- protected Enumeration getRequestHeaderNames() {
- return getHttpRequest().getHeaderNames();
- }
+ protected Enumeration getRequestHeaderNames() {
+ return getHttpRequest().getHeaderNames();
+ }
- protected String[] getRequestHeaderValues(String name) {
- Enumeration values = getHttpRequest().getHeaders(name);
- ArrayList valuesList = new ArrayList();
- while (values.hasMoreElements()) {
- valuesList.add(values.nextElement());
+ protected String[] getRequestHeaderValues(String name) {
+ Enumeration values = getHttpRequest().getHeaders(name);
+ ArrayList valuesList = new ArrayList();
+ while (values.hasMoreElements()) {
+ valuesList.add(values.nextElement());
+ }
+ return (String[]) valuesList.toArray(EMPTY_STRING_ARRAY);
}
- return (String[]) valuesList.toArray(EMPTY_STRING_ARRAY);
- }
- protected Object getRequestParameter(String name) {
- return getHttpRequest().getParameter(name);
- }
-
- private String sessionPrefix;
-
- private String getSessionPrefix(){
- if (sessionPrefix == null) {
- HttpSession session = getHttpRequest().getSession(false);
- String namespase = getNamespace();
- if(null == namespase || null == session){
- throw new FacesException("JSF request called without portlet namespace parameter");
- }
- 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(attribute)) {
- sessionPrefix = name.substring(0, name.length()-NAMESPACE_PARAMETER.length());
- if (_log.isDebugEnabled()) {
- _log.debug("Prefix for a PORTLET_SCOPE session attributes: "+sessionPrefix);
- }
+ protected Object getRequestParameter(String name) {
+ return getHttpRequest().getParameter(name);
+ }
+
+ private String sessionPrefix;
+
+ private String getSessionPrefix() {
+ if (sessionPrefix == null) {
+ HttpSession session = getHttpRequest().getSession(false);
+ String namespase = getNamespace();
+ if (null == namespase || null == session) {
+ throw new FacesException(
+ "JSF request called without portlet namespace parameter");
+ }
+ 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(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) {
+ throw new FacesException(
+ "Prefix for attributes in portlet session scope not found");
+ }
}
- }
- if(null == sessionPrefix){
- throw new FacesException("Prefix for attributes in portlet session scope not found");
- }
+ return sessionPrefix;
}
- return sessionPrefix;
- }
- protected Object getSessionAttribute(String name) {
- return getHttpRequest().getSession(true).getAttribute(getSessionPrefix()+name);
- }
+ protected Object getSessionAttribute(String name) {
+ return getHttpRequest().getSession(true).getAttribute(
+ getSessionPrefix() + name);
+ }
- protected Enumeration getSessionAttributeNames() {
- return new SessionAttributesNames(getHttpRequest().getSession(true).getAttributeNames(),getSessionPrefix());
- }
+ protected Enumeration getSessionAttributeNames() {
+ return new SessionAttributesNames(getHttpRequest().getSession(true)
+ .getAttributeNames(), getSessionPrefix());
+ }
- protected void removeSessionAttribute(String name) {
- getHttpRequest().getSession(true).removeAttribute(getSessionPrefix()+name);
- }
+ protected void removeSessionAttribute(String name) {
+ getHttpRequest().getSession(true).removeAttribute(
+ getSessionPrefix() + name);
+ }
- protected void setSessionAttribute(String name, Object value) {
- getHttpRequest().getSession(true).setAttribute(getSessionPrefix()+name, value);
- }
+ protected void setSessionAttribute(String name, Object value) {
+ getHttpRequest().getSession(true).setAttribute(
+ getSessionPrefix() + name, value);
+ }
- protected void removeContextAttribute(String name) {
- getHttpRequest().getSession(true).removeAttribute(name);
- }
+ protected void removeContextAttribute(String name) {
+ getHttpRequest().getSession(true).removeAttribute(name);
+ }
- protected void removeRequestAttribute(String name) {
- getHttpRequest().removeAttribute(name);
- }
+ protected void removeRequestAttribute(String name) {
+ getHttpRequest().removeAttribute(name);
+ }
- protected void setRequestAttribute(String name, Object value) {
- getHttpRequest().setAttribute(name, value);
- }
+ protected void setRequestAttribute(String name, Object value) {
+ getHttpRequest().setAttribute(name, value);
+ }
- public void dispatch(String path) throws IOException {
- RequestDispatcher requestDispatcher = getHttpRequest().getRequestDispatcher(path);
- if (requestDispatcher == null) {
- (getHttpResponse()).
- sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
- try {
- requestDispatcher.forward(getHttpRequest(), getHttpResponse());
- } catch (IOException ioe) {
- throw ioe;
- } catch (ServletException se) {
- throw new FacesException(se);
- }
+ public void dispatch(String path) throws IOException {
+ RequestDispatcher requestDispatcher = getHttpRequest()
+ .getRequestDispatcher(path);
+ if (requestDispatcher == null) {
+ (getHttpResponse()).sendError(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+ try {
+ requestDispatcher.forward(getHttpRequest(), getHttpResponse());
+ } catch (IOException ioe) {
+ throw ioe;
+ } catch (ServletException se) {
+ throw new FacesException(se);
+ }
- }
+ }
- public String encodeActionURL(String url) {
- return getHttpResponse().encodeURL(url);
- }
+ @Override
+ protected String createActionUrl(Map parameters) {
+ String actionURL = getHttpRequest().getParameter(ACTION__PARAMETER);
+ return actionURL;
+ }
- public String encodeResourceURL(String url) {
- return getHttpResponse().encodeURL(url);
- }
+ public String encodeResourceURL(String url) {
+ return encodeURL(url);
+ }
- public Locale getRequestLocale() {
- return getHttpRequest().getLocale();
- }
+ /**
+ * @param url
+ * @return
+ */
+ protected String encodeURL(String url) {
+ return getHttpResponse().encodeURL(url);
+ }
- public Iterator getRequestLocales() {
- return new EnumerationIterator(getHttpRequest().getLocales());
- }
+ public Locale getRequestLocale() {
+ return getHttpRequest().getLocale();
+ }
- public Object getSession(boolean create) {
- HttpSession session = getHttpRequest().getSession(create);
- if(null != session){
- session = new ServletSessionWrapper(session,getSessionPrefix());
+ public Iterator getRequestLocales() {
+ return new EnumerationIterator(getHttpRequest().getLocales());
}
- return session;
- }
- public Principal getUserPrincipal() {
- return getHttpRequest().getUserPrincipal();
- }
+ public Object getSession(boolean create) {
+ HttpSession session = getHttpRequest().getSession(create);
+ if (null != session) {
+ session = new ServletSessionWrapper(session, getSessionPrefix());
+ }
+ return session;
+ }
- public boolean isUserInRole(String role) {
- return getHttpRequest().isUserInRole(role);
- }
+ public Principal getUserPrincipal() {
+ return getHttpRequest().getUserPrincipal();
+ }
- public void log(String message) {
- getServletContext().log(message);
- }
+ public boolean isUserInRole(String role) {
+ return getHttpRequest().isUserInRole(role);
+ }
- public void log(String message, Throwable exception) {
- getServletContext().log(message, exception);
- }
+ public void log(String message) {
+ getServletContext().log(message);
+ }
- public void redirect(String url) throws IOException {
- getHttpResponse().sendRedirect(url);
- FacesContext.getCurrentInstance().responseComplete();
- }
+ public void log(String message, Throwable exception) {
+ getServletContext().log(message, exception);
+ }
+
+ public void redirect(String url) throws IOException {
+ getHttpResponse().sendRedirect(url);
+ FacesContext.getCurrentInstance().responseComplete();
+ }
+
}
Modified: trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
===================================================================
--- trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java 2007-10-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -3,18 +3,22 @@
*/
package org.ajax4jsf.portlet.lifecycle;
+import java.util.Map;
+
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.portlet.faces.Bridge;
+import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.portlet.application.PortletStateHolder;
import org.ajax4jsf.portlet.application.PortletViewState;
+import org.ajax4jsf.portlet.context.AbstractExternalContext;
/**
* @author asmirnov
- *
+ *
*/
public class PortalPhaseListener implements PhaseListener {
@@ -23,39 +27,79 @@
*/
private static final long serialVersionUID = -4023885603543145666L;
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
*/
public void afterPhase(PhaseEvent event) {
PhaseId phaseId = event.getPhaseId();
FacesContext context = event.getFacesContext();
- if(phaseId.equals(PhaseId.RESTORE_VIEW)){
- Object portletPhase = context.getExternalContext().getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
- if(Bridge.PortletPhase.RenderPhase.equals(portletPhase)){
+ if (phaseId.equals(PhaseId.RESTORE_VIEW)) {
+ Object portletPhase = context.getExternalContext().getRequestMap()
+ .get(Bridge.PORTLET_LIFECYCLE_PHASE);
+ if (null == portletPhase) {
+ // For a servlet phase, put all portlet-related parameters back to ajaxContext.
+ Map<String, String> requestParameters = context
+ .getExternalContext().getRequestParameterMap();
+
+ AjaxContext ajaxContext = AjaxContext
+ .getCurrentInstance(context);
+ Map commonAjaxParameters = ajaxContext
+ .getCommonAjaxParameters();
+ commonAjaxParameters
+ .put(
+ AbstractExternalContext.ACTION__PARAMETER,
+ requestParameters
+ .get(AbstractExternalContext.ACTION__PARAMETER));
+ commonAjaxParameters
+ .put(
+ AbstractExternalContext.PORTLET_MODE_PARAMETER,
+ requestParameters
+ .get(AbstractExternalContext.PORTLET_MODE_PARAMETER));
+
+ commonAjaxParameters
+ .put(
+ AbstractExternalContext.NAMESPACE_PARAMETER,
+ requestParameters
+ .get(AbstractExternalContext.NAMESPACE_PARAMETER));
+
+ commonAjaxParameters
+ .put(
+ AbstractExternalContext.PORTLET_NAME_PARAMETER,
+ requestParameters
+ .get(AbstractExternalContext.PORTLET_NAME_PARAMETER));
+
+ } else if (Bridge.PortletPhase.RenderPhase.equals(portletPhase)) {
context.renderResponse();
}
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
*/
public void beforePhase(PhaseEvent event) {
PhaseId phaseId = event.getPhaseId();
FacesContext context = event.getFacesContext();
- if(phaseId.equals(PhaseId.RENDER_RESPONSE)){
- Object portletPhase = context.getExternalContext().getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
- if(null == portletPhase){
- // save request scope variables and Faces Messages.
- PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
- windowState.saveMessages(context);
- windowState.saveBeans(context);
+ if (phaseId.equals(PhaseId.RENDER_RESPONSE)) {
+ Object portletPhase = context.getExternalContext().getRequestMap()
+ .get(Bridge.PORTLET_LIFECYCLE_PHASE);
+ if (null == portletPhase) {
+ // save request scope variables and Faces Messages.
+ PortletViewState windowState = PortletStateHolder.getInstance(
+ context).getWindowState(context);
+ windowState.saveRequest(context);
}
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.faces.event.PhaseListener#getPhaseId()
*/
public PhaseId getPhaseId() {
Modified: trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
===================================================================
--- trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java 2007-10-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -66,7 +66,7 @@
FacesContext context = factory.getFacesContext(portletContext,
portletRequest, portletResponse, lifecycle);
assertTrue((context instanceof FacesContextImpl));
- assertTrue((context.getExternalContext() instanceof PortletContextImpl));
+ assertTrue((context.getExternalContext() instanceof AbstractExternalContext));
assertSame(FacesContext.getCurrentInstance(),context);
}
Modified: trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
===================================================================
--- trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java 2007-10-31 21:57:40 UTC (rev 3659)
+++ trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java 2007-11-01 01:00:16 UTC (rev 3660)
@@ -16,7 +16,7 @@
*
*/
public class PortletExternalContextTest extends AbstractAjax4JsfTestCase {
- private PortletContextImpl portletContextImpl;
+ private AbstractExternalContext portletContextImpl;
private FacesContextImpl portalFacesContext;
private MockPortletContext portletContext;
private MockActionRequest portletRequest;
17 years, 2 months