[Jsf4portlets-devel] SF.net SVN: jsf4portlets: [35] trunk
Status: Alpha
Brought to you by:
alonsoft
From: <alo...@us...> - 2007-10-21 11:32:17
|
Revision: 35 http://jsf4portlets.svn.sourceforge.net/jsf4portlets/?rev=35&view=rev Author: alonsoft Date: 2007-10-21 04:31:56 -0700 (Sun, 21 Oct 2007) Log Message: ----------- Modified for future version Modified Paths: -------------- trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/context/ExternalContextImpl.java trunk/jsf4portlets-ext/pom.xml trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventFacesPortlet.java trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventPhaseListener.java trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEvent.java trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/facelets/FaceletPortletViewHandler.java trunk/jsf4portlets-ext/src/site/site.xml trunk/pom.xml Added Paths: ----------- trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoder.java trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoderFactory.java trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/util/DefaultPortletURLEncoder.java trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventHelper.java trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletListener.java trunk/jsf4portlets-ext/src/site/apt/portlet_events.apt Removed Paths: ------------- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventListener.java Modified: trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/context/ExternalContextImpl.java =================================================================== --- trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/context/ExternalContextImpl.java 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/context/ExternalContextImpl.java 2007-10-21 11:31:56 UTC (rev 35) @@ -26,7 +26,13 @@ import java.net.MalformedURLException; import java.net.URL; import java.security.Principal; -import java.util.*; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -41,11 +47,11 @@ import javax.portlet.PortletRequest; import javax.portlet.PortletRequestDispatcher; import javax.portlet.PortletResponse; -import javax.portlet.PortletURL; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import javax.portlet.faces.*; -import javax.portlet.faces.Bridge.*; +import javax.portlet.faces.Bridge; +import javax.portlet.faces.BridgeDefaultViewNotSpecifiedException; +import javax.portlet.faces.Bridge.PortletPhase; import net.sf.jsf4portlets.BridgeConstants; import net.sf.jsf4portlets.RequestScope; @@ -55,6 +61,8 @@ import net.sf.jsf4portlets.spi.InjectionProvider; import net.sf.jsf4portlets.spi.InjectionProviderException; import net.sf.jsf4portlets.spi.InjectionProviderFactory; +import net.sf.jsf4portlets.spi.PortletURLEncoder; +import net.sf.jsf4portlets.spi.PortletURLEncoderFactory; import net.sf.jsf4portlets.util.PathString; import net.sf.jsf4portlets.util.Util; @@ -153,67 +161,8 @@ @Override public String encodeActionURL(String url) { - logger.entering(ExternalContextImpl.class.getName(), "encodeActionURL", url); - if (url == null) { - throw new NullPointerException(); - } - if(!url.startsWith("#") && (url.startsWith("/") - && !url.startsWith(getRequestContextPath()))) { - logger.exiting(ExternalContext.class.getName(), "encodeActionURL", url); - return url; - } - - PathString qs = PathString.parse(this, url); - String directLink = qs.getParameter(Bridge.DIRECT_LINK); - if(directLink != null) { - if("true".equals(directLink)) { - logger.exiting(ExternalContext.class.getName(), "encodeActionURL", qs); - return qs.toString(); - } else { - qs.removeParameter(Bridge.DIRECT_LINK); - } - } - - String viewId = null; - if(qs.getContextPath().equals(getRequestContextPath())) { - ApplicationConfiguration config = - ApplicationConfiguration.getInstance(this); - String mapping = config.getFacesMapping(); - if(Util.isPrefixMapped(mapping)) { - int slash = mapping.lastIndexOf("/"); - String prefix = mapping.substring(0, slash); - if(qs.getPath().startsWith(prefix)) { - viewId = qs.getPath().substring(slash); - } - } - } - if(viewId == null) { - viewId = qs.getPath(); - } - if(!viewId.startsWith("/")) { - viewId = "/" + viewId; - } - if(logger.isLoggable(Level.FINER)) { - logger.log(Level.FINER, "J4P_000023", viewId); - } - - String result = null; - PortletPhase phase = Util.getPortletLifecyclePhase(this); - if(PortletPhase.RenderPhase.equals(phase)) { - RenderResponse response = (RenderResponse) getResponse(); - PortletURL portletURL = response.createActionURL(); - portletURL.setParameters(qs.getParameterMap()); - portletURL.setParameter(BridgeConstants.VIEW_ID_PARAMETER, viewId); - result = portletURL.toString(); - } else if(PortletPhase.ActionPhase.equals(phase)) { - RequestScope requestScope = Util.getRequestScope(this); - requestScope.setParameters(qs.getParameterMap()); - result = viewId; - } else { - throw new IllegalStateException(); - } - logger.exiting(ExternalContext.class.getName(), "encodeActionURL", result); - return result; + PortletURLEncoder encoder = PortletURLEncoderFactory.getEncoder(this); + return encoder.encodeActionURL(this, url); } @Override @@ -226,16 +175,8 @@ @Override public String encodeResourceURL(String url) { - if(url == null) { - throw new NullPointerException(); - } - - if(!url.startsWith("http") && !url.startsWith("https") - && !(url.startsWith("/"))) { - url = getRequestContextPath() + "/" + url; - } - - return (response.encodeURL(url)); + PortletURLEncoder encoder = PortletURLEncoderFactory.getEncoder(this); + return encoder.encodeResourceURL(this, url); } @Override Added: trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoder.java =================================================================== --- trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoder.java (rev 0) +++ trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoder.java 2007-10-21 11:31:56 UTC (rev 35) @@ -0,0 +1,31 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ +package net.sf.jsf4portlets.spi; + +import javax.faces.context.ExternalContext; + +public interface PortletURLEncoder { + + public String encodeActionURL(ExternalContext context, String url); + + public String encodeResourceURL(ExternalContext context, String url); + +} Added: trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoderFactory.java =================================================================== --- trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoderFactory.java (rev 0) +++ trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/spi/PortletURLEncoderFactory.java 2007-10-21 11:31:56 UTC (rev 35) @@ -0,0 +1,49 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ +package net.sf.jsf4portlets.spi; + +import javax.faces.context.ExternalContext; +import javax.portlet.PortletConfig; + +import net.sf.jsf4portlets.util.DefaultPortletURLEncoder; +import net.sf.jsf4portlets.util.Util; + +public final class PortletURLEncoderFactory { + + private static final PortletURLEncoder DEFAULT_ENCODER = + new DefaultPortletURLEncoder(); + + public static final String ENCODER_ATTR_PREFIX = + "javax.portlet.faces.extension.encoder."; + + public static PortletURLEncoder getEncoder(ExternalContext context) { + PortletConfig portletConfig = Util.getPortletConfig(context); + PortletURLEncoder instance = (PortletURLEncoder) context.getApplicationMap().get( + ENCODER_ATTR_PREFIX + portletConfig.getPortletName()); + if(instance == null) { + instance = DEFAULT_ENCODER; + } + return instance; + } + + private PortletURLEncoderFactory() { } + +} Added: trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/util/DefaultPortletURLEncoder.java =================================================================== --- trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/util/DefaultPortletURLEncoder.java (rev 0) +++ trunk/jsf4portlets/src/main/java/net/sf/jsf4portlets/util/DefaultPortletURLEncoder.java 2007-10-21 11:31:56 UTC (rev 35) @@ -0,0 +1,118 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ +package net.sf.jsf4portlets.util; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.faces.context.ExternalContext; +import javax.portlet.PortletResponse; +import javax.portlet.PortletURL; +import javax.portlet.RenderResponse; +import javax.portlet.faces.Bridge; +import javax.portlet.faces.Bridge.PortletPhase; + +import net.sf.jsf4portlets.BridgeConstants; +import net.sf.jsf4portlets.RequestScope; +import net.sf.jsf4portlets.config.ApplicationConfiguration; +import net.sf.jsf4portlets.spi.PortletURLEncoder; + +public class DefaultPortletURLEncoder implements PortletURLEncoder { + + private final Logger logger = Logger.getLogger( + DefaultPortletURLEncoder.class.getPackage().getName(), + "net.sf.jsf4portlets.LogMessages"); + + public String encodeActionURL(ExternalContext context, String url) { + if (url == null) { + throw new NullPointerException(); + } + if(!url.startsWith("#") && (url.startsWith("/") + && !url.startsWith(context.getRequestContextPath()))) { + return url; + } + + PathString qs = PathString.parse(context, url); + String directLink = qs.getParameter(Bridge.DIRECT_LINK); + if(directLink != null) { + if("true".equals(directLink)) { + return qs.toString(); + } else { + qs.removeParameter(Bridge.DIRECT_LINK); + } + } + + String viewId = null; + if(qs.getContextPath().equals(context.getRequestContextPath())) { + ApplicationConfiguration config = + ApplicationConfiguration.getInstance(context); + String mapping = config.getFacesMapping(); + if(Util.isPrefixMapped(mapping)) { + int slash = mapping.lastIndexOf("/"); + String prefix = mapping.substring(0, slash); + if(qs.getPath().startsWith(prefix)) { + viewId = qs.getPath().substring(slash); + } + } + } + if(viewId == null) { + viewId = qs.getPath(); + } + if(!viewId.startsWith("/")) { + viewId = "/" + viewId; + } + if(logger.isLoggable(Level.FINER)) { + logger.log(Level.FINER, "J4P_000023", viewId); + } + + String result = null; + PortletPhase phase = Util.getPortletLifecyclePhase(context); + if(PortletPhase.RenderPhase.equals(phase)) { + RenderResponse response = (RenderResponse) context.getResponse(); + PortletURL portletURL = response.createActionURL(); + portletURL.setParameters(qs.getParameterMap()); + portletURL.setParameter(BridgeConstants.VIEW_ID_PARAMETER, viewId); + result = portletURL.toString(); + } else if(PortletPhase.ActionPhase.equals(phase)) { + RequestScope requestScope = Util.getRequestScope(context); + requestScope.setParameters(qs.getParameterMap()); + result = viewId; + } else { + throw new IllegalStateException(); + } + return result; + } + + public String encodeResourceURL(ExternalContext context, String url) { + if(url == null) { + throw new NullPointerException(); + } + + if(!url.startsWith("http") && !url.startsWith("https") + && !(url.startsWith("/"))) { + url = context.getRequestContextPath() + "/" + url; + } + + PortletResponse response = (PortletResponse) context.getResponse(); + return (response.encodeURL(url)); + } + +} Modified: trunk/jsf4portlets-ext/pom.xml =================================================================== --- trunk/jsf4portlets-ext/pom.xml 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/pom.xml 2007-10-21 11:31:56 UTC (rev 35) @@ -70,6 +70,11 @@ <artifactId>portletappengine</artifactId> <groupId>com.sun.portal.portletcontainer</groupId> </dependency> + + <dependency> + <groupId>jsf-extensions</groupId> + <artifactId>jsf-extensions-run-time</artifactId> + </dependency> <dependency> <groupId>junit</groupId> Modified: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventFacesPortlet.java =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventFacesPortlet.java 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventFacesPortlet.java 2007-10-21 11:31:56 UTC (rev 35) @@ -1,3 +1,23 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ package net.sf.jsf4portlets.event; import java.util.LinkedList; Modified: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventPhaseListener.java =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventPhaseListener.java 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/EventPhaseListener.java 2007-10-21 11:31:56 UTC (rev 35) @@ -1,3 +1,23 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ package net.sf.jsf4portlets.event; import java.util.Enumeration; @@ -75,7 +95,7 @@ throw new FacesException(e); } - if(PortletEventListener.class.isAssignableFrom(beanClass)) { + if(PortletListener.class.isAssignableFrom(beanClass)) { Object bean = resolveManagedBean(context, beanName, beanClass); assert bean != null; @@ -84,7 +104,7 @@ event.getEventName(), beanName }); } - ((PortletEventListener) bean).handleEvent(event); + ((PortletListener) bean).processPortlet(event); } } } Modified: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEvent.java =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEvent.java 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEvent.java 2007-10-21 11:31:56 UTC (rev 35) @@ -1,3 +1,23 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ package net.sf.jsf4portlets.event; import java.util.EventObject; @@ -4,6 +24,14 @@ import javax.portlet.Portlet; +/** + * Representation of the event information received + * by the portlet and broadcasted to the application + * managed beans + * + * @author A. Alonso Domínguez + * + */ public class PortletEvent extends EventObject { private String eventName; @@ -15,14 +43,30 @@ this.eventData = eventData; } + /** + * Obtains the portlet which received the event + * + * @return the portlet which received the event + */ public Portlet getPortlet() { return (Portlet) super.getSource(); } + /** + * Obtains the event name + * + * @return the event name + */ public String getEventName() { return eventName; } + /** + * Obtains the object which represents the + * event data + * + * @return the event data + */ public Object getEventData() { return eventData; } Added: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventHelper.java =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventHelper.java (rev 0) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventHelper.java 2007-10-21 11:31:56 UTC (rev 35) @@ -0,0 +1,59 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ +package net.sf.jsf4portlets.event; + +import java.io.Serializable; + +import javax.faces.FacesException; +import javax.faces.context.FacesContext; +import javax.portlet.PortletRequest; + +import com.sun.portal.portletappengine.ipc.EventNotRegisteredException; +import com.sun.portal.portletappengine.ipc.PortletEventBroker; + +public final class PortletEventHelper { + + private FacesContext context; + + public PortletEventHelper(FacesContext context) { + this.context = context; + } + + public void fireEvent(String name, Object data) + throws FacesException { + if(!(data instanceof Serializable)) { + throw new IllegalArgumentException(); + } + + PortletRequest request = (PortletRequest) context + .getExternalContext().getRequest(); + PortletEventBroker broker = new PortletEventBroker(request); + com.sun.portal.portletappengine.ipc.PortletEvent event; + try { + event = broker.createEvent(name); + } catch(EventNotRegisteredException e) { + throw new FacesException(e); + } + event.setEventData((Serializable) data); + event.fire(); + } + +} Deleted: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventListener.java =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventListener.java 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventListener.java 2007-10-21 11:31:56 UTC (rev 35) @@ -1,9 +0,0 @@ -package net.sf.jsf4portlets.event; - -import java.util.EventListener; - -public interface PortletEventListener extends EventListener { - - public void handleEvent(PortletEvent event); - -} Copied: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletListener.java (from rev 34, trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletEventListener.java) =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletListener.java (rev 0) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/event/PortletListener.java 2007-10-21 11:31:56 UTC (rev 35) @@ -0,0 +1,29 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ +package net.sf.jsf4portlets.event; + +import java.util.EventListener; + +public interface PortletListener extends EventListener { + + public void processPortlet(PortletEvent event); + +} Modified: trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/facelets/FaceletPortletViewHandler.java =================================================================== --- trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/facelets/FaceletPortletViewHandler.java 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/src/main/java/net/sf/jsf4portlets/facelets/FaceletPortletViewHandler.java 2007-10-21 11:31:56 UTC (rev 35) @@ -1,3 +1,23 @@ +/* JSF 4 Portlets - JSF Portlet Bridge (JSR-301) + * Copyright (C) 2007 A. Alonso Dominguez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A. Alonso Dominguez + * alo...@us... + */ package net.sf.jsf4portlets.facelets; import java.io.IOException; Added: trunk/jsf4portlets-ext/src/site/apt/portlet_events.apt =================================================================== --- trunk/jsf4portlets-ext/src/site/apt/portlet_events.apt (rev 0) +++ trunk/jsf4portlets-ext/src/site/apt/portlet_events.apt 2007-10-21 11:31:56 UTC (rev 35) @@ -0,0 +1,133 @@ +~~ +~~ JSF 4 Portlets - JSF Portlet Bridge (JSR-301) +~~ Copyright (C) 2007 A. Alonso Dominguez +~~ +~~ This library is free software; you can redistribute it and/or +~~ modify it under the terms of the GNU Lesser General Public +~~ License as published by the Free Software Foundation; either +~~ version 2.1 of the License, or (at your option) any later version. +~~ +~~ This library is distributed in the hope that it will be useful, +~~ but WITHOUT ANY WARRANTY; without even the implied warranty of +~~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +~~ Lesser General Public License for more details. +~~ +~~ You should have received a copy of the GNU Lesser General Public +~~ License along with this library; if not, write to the Free Software +~~ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +~~ +~~ A. Alonso Dominguez +~~ alo...@us... +~~ + + --- + JSF 4 Portlets Extensions - Portlet Events + --- + A. Alonso Dominguez + --- + +Inter-Portlet Communication + +* Before Starting + + This is an especial feature on JSR-168 portlets and support for portlet events must be implemented on the portlet container. Currently, JSF 4 Portlets gives support for portlet events if those portlets are deployed with the {{{http://portlet-container.dev.java.net}Open Source Portlet Container}}. + +Event Support + +* Configuring Container + + Firts of all, you must add a file called <<<sun-portlet.xml>>> to the <<<WEB-INF>>> folder inside your portlet application. In that file you must specify which portlets will generate/consume events. Following is an example: + ++--- +<sun-portlet-app> +... + + <portlet> + <portlet-name>Faces Portlet</portlet-name> + ... + + <events> + <generates-event>EventName</generates-event> + + <consume-event>PayOrder</consume-event> + ... + </events> + + </portlet> + +... +</sun-portlet-app> ++--- + + If you need more information you take a look at the following link: {{https://portlet-container.dev.java.net/docs/ipc/IPC.html}}. + +* Configure the EventFacesPortlet + + Once you have configured which events will generate/consume your portlet, you must use a portlet implementation able to listen to portlet events. JSF 4 Portlets gives you one at: <<<net.sf.jsf4portlets.event.EventFacesPortlet>>>. + + Notice that <<<net.sf.jsf4portlets.event.EventFacesPortlet>>> is an extension of <<<javax.portlet.faces.GenericFacesPortlet>>> so it must be configured the same way the faces portlet is configured. You may take a look at the {{{http://jsf4portlets.sf.net/web/user_docs.html}User Documentation}}. Following is an example of how to configure the <<<EventFacesPortlet>>>: + ++--- +<portlet-app> +... + + <portlet> + <portlet-name>Faces Portlet</portlet-name> + <portlet-class> + net.sf.jsf4portlets.event.EventFacesPortlet + </portlet-class> + + ... + </portlet> + +... +</portlet-app> ++--- + +Working with events + +* Generating Events + + Events are generated using a helper class called <<<net.sf.jsf4portlets.event.PortletEventHelper>>>: + ++--- +import ... +import net.sf.jsf4portlets.event.PortletEventHelper + +... + +public class EventGeneratorBean { + + public void actionPerformed(ActionEvent event) { + FacesContext context = FacesContext.getCurrentInstance(); + + // Do action processing + + PortletEventHelper helper = new PortletEventHelper(context); + helper.fireEvent("EventName", eventData); + } + +} ++--- + +* Consuming Events + + Portlet events are received by managed beans just before the <<<RENDER_RESPONSE>>> phase. A managed bean which needs to be aware of portlet events must implement the <<<net.sf.jsf4portlets.event.PortletListener>>> interface. This interface has just a method which is the entry point of the event processing. Following is an example of a managed bean which is aware of portlet events: + ++--- +import ... +import net.sf.jsf4portlets.event.PortletEvent +import net.sf.jsf4portlets.event.PortletListener + +... + +public class EventAwareBean implements PortletListener { + + public void processPortlet(PortletEvent event) { + if("PayOrder".equals(event.getEventName()) { + // Process "PayOrder" bean. + } + } + +} ++--- \ No newline at end of file Modified: trunk/jsf4portlets-ext/src/site/site.xml =================================================================== --- trunk/jsf4portlets-ext/src/site/site.xml 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/jsf4portlets-ext/src/site/site.xml 2007-10-21 11:31:56 UTC (rev 35) @@ -46,7 +46,8 @@ </menu> <menu name="Feature Documentation"> - <item name="Facelets" href="facelets.html" /> + <item name="Facelets" href="facelets.html" /> + <item name="Portlet Events" href="portlet_events.html" /> </menu> <menu ref="reports" /> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2007-09-28 18:08:20 UTC (rev 34) +++ trunk/pom.xml 2007-10-21 11:31:56 UTC (rev 35) @@ -72,7 +72,15 @@ <layout>default</layout> </snapshotRepository> </distributionManagement> - + + <repositories> + <repository> + <id>java.net</id> + <url>http://download.java.net/maven/1</url> + <layout>legacy</layout> + </repository> + </repositories> + <modules> <module>jsf4portlets</module> <module>jsf4portlets-ext</module> @@ -250,8 +258,16 @@ <scope>provided</scope> <optional>true</optional> </dependency> - + <dependency> + <groupId>jsf-extensions</groupId> + <artifactId>jsf-extensions-run-time</artifactId> + <version>0.1alpha4</version> + <scope>compile</scope> + <optional>true</optional> + </dependency> + + <dependency> <groupId>net.sf.jsf4portlets</groupId> <artifactId>jsf4portlets</artifactId> <version>${pom.version}</version> @@ -267,4 +283,4 @@ </dependencies> </dependencyManagement> -</project> \ No newline at end of file +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |