[seam-commits] Seam SVN: r12726 - in modules/faces/trunk/impl/src: main/java/org/jboss/seam/faces/component and 5 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu May 13 14:19:21 EDT 2010
Author: lincolnthree
Date: 2010-05-13 14:19:20 -0400 (Thu, 13 May 2010)
New Revision: 12726
Added:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamResourceResolver.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/SeamResourceResolverTest.java
modules/faces/trunk/impl/src/test/resources/org/jboss/seam/faces/environment/
modules/faces/trunk/impl/src/test/resources/org/jboss/seam/faces/environment/mock.resource
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/SeamFacesException.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java
modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
modules/faces/trunk/impl/src/main/resources/META-INF/web-fragment.xml
Log:
Added support for loading Facelets template files from classpath.
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/SeamFacesException.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/SeamFacesException.java 2010-05-13 13:58:50 UTC (rev 12725)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/SeamFacesException.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -29,12 +29,18 @@
{
private static final long serialVersionUID = -610838646516706170L;
- public SeamFacesException(final String string)
+ public SeamFacesException()
{
}
- public SeamFacesException()
+ public SeamFacesException(final String message)
{
+ super(message);
}
+ public SeamFacesException(final String message, final Exception e)
+ {
+ super(message, e);
+ }
+
}
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java 2010-05-13 13:58:50 UTC (rev 12725)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -66,6 +66,7 @@
validator = event;
form = validator.locateForm();
locateAliasedComponents(event);
+ event.setComponents(components);
}
public void cleanupComponentTree(@Observes @After final UIValidateForm event)
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java 2010-05-13 13:58:50 UTC (rev 12725)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -23,6 +23,8 @@
package org.jboss.seam.faces.component;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.AnnotationLiteral;
@@ -62,6 +64,7 @@
private String validatorId = "";
private String fields = "";
+ private Map<String, UIInput> components = new HashMap<String, UIInput>();
@Override
public String getFamily()
@@ -85,11 +88,17 @@
try
{
UIComponent parent = this.getParent();
- validator.validate(context, parent, null);
+ validator.validate(context, parent, components);
}
catch (ValidatorException e)
{
setValid(false);
+ for (UIInput comp : components.values())
+ {
+ comp.setValid(false);
+ // TODO Put this back when attributes can control it
+ // context.addMessage(comp.getClientId(), e.getFacesMessage());
+ }
context.addMessage(null, e.getFacesMessage());
}
@@ -163,4 +172,12 @@
{
this.validatorId = validatorId;
}
+
+ /**
+ * @param components
+ */
+ public void setComponents(final Map<String, UIInput> components)
+ {
+ this.components = components;
+ }
}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -0,0 +1,36 @@
+package org.jboss.seam.faces.environment;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextWrapper;
+import javax.faces.view.facelets.ResourceResolver;
+
+public class SeamExternalContext extends ExternalContextWrapper
+{
+ private final ExternalContext wrapped;
+ private final ResourceResolver resolver = new SeamResourceResolver();
+
+ public SeamExternalContext(final ExternalContext wrapped)
+ {
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public URL getResource(final String path) throws MalformedURLException
+ {
+ URL url = resolver.resolveUrl(path);
+ if (url == null)
+ {
+ url = getWrapped().getResource(path);
+ }
+ return url;
+ }
+
+ @Override
+ public ExternalContext getWrapped()
+ {
+ return wrapped;
+ }
+}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -0,0 +1,28 @@
+package org.jboss.seam.faces.environment;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextFactory;
+
+public class SeamExternalContextFactory extends ExternalContextFactory
+{
+ private final ExternalContextFactory parent;
+
+ public SeamExternalContextFactory(final ExternalContextFactory parent)
+ {
+ super();
+ this.parent = parent;
+ }
+
+ @Override
+ public ExternalContext getExternalContext(final Object context, final Object request, final Object response) throws FacesException
+ {
+ return new SeamExternalContext(getWrapped().getExternalContext(context, request, response));
+ }
+
+ @Override
+ public ExternalContextFactory getWrapped()
+ {
+ return parent;
+ }
+}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamResourceResolver.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamResourceResolver.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamResourceResolver.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.environment;
+
+import java.net.URL;
+
+import javax.faces.view.facelets.ResourceResolver;
+
+/**
+ * Allow resolution of classpath resources.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ *
+ */
+public class SeamResourceResolver extends ResourceResolver
+{
+ private final ResourceResolver parent;
+
+ public SeamResourceResolver()
+ {
+ this.parent = null;
+ }
+
+ public SeamResourceResolver(final ResourceResolver parent)
+ {
+ this.parent = parent;
+ }
+
+ @Override
+ public URL resolveUrl(final String path)
+ {
+ URL result = null;
+ if (path != null)
+ {
+ String canonicalPath = path;
+ if (path.startsWith("/"))
+ {
+ canonicalPath = path.substring(1);
+ }
+
+ result = Thread.currentThread().getContextClassLoader().getResource(canonicalPath);
+ if ((result == null) && (parent != null))
+ {
+ result = parent.resolveUrl(path);
+ }
+ }
+ return result;
+ }
+}
Modified: modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml 2010-05-13 13:58:50 UTC (rev 12725)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml 2010-05-13 18:19:20 UTC (rev 12726)
@@ -16,6 +16,10 @@
<phase-listener>org.jboss.seam.faces.context.FlashScopedContext</phase-listener>
<phase-listener>org.jboss.seam.faces.event.DelegatingPhaseListener</phase-listener>
</lifecycle>
+
+ <factory>
+ <external-context-factory>org.jboss.seam.faces.environment.SeamExternalContextFactory</external-context-factory>
+ </factory>
<application>
<system-event-listener>
Modified: modules/faces/trunk/impl/src/main/resources/META-INF/web-fragment.xml
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/web-fragment.xml 2010-05-13 13:58:50 UTC (rev 12725)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/web-fragment.xml 2010-05-13 18:19:20 UTC (rev 12726)
@@ -3,9 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
<name>seamfaces</name>
-
+
<listener>
<listener-class>org.jboss.seam.faces.beanManager.BeanManagerServletContextListener</listener-class>
</listener>
+ <context-param>
+ <param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
+ <param-value>org.jboss.seam.faces.environment.SeamResourceResolver</param-value>
+ </context-param>
+
</web-fragment>
\ No newline at end of file
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/SeamResourceResolverTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/SeamResourceResolverTest.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/SeamResourceResolverTest.java 2010-05-13 18:19:20 UTC (rev 12726)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.environment;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import javax.faces.view.facelets.ResourceResolver;
+
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ *
+ */
+public class SeamResourceResolverTest
+{
+ SeamResourceResolver resolver = new SeamResourceResolver(new ResourceResolver()
+ {
+ @Override
+ public URL resolveUrl(final String path)
+ {
+ return null;
+ }
+ });
+
+ @Test
+ public void testResolveClasspathUrl()
+ {
+ String validPath = "/org/jboss/seam/faces/environment/mock.resource";
+ URL url = resolver.resolveUrl(validPath);
+ assertTrue(url instanceof URL);
+ }
+
+ @Test
+ public void testResolveUnprefixedClasspathUrl()
+ {
+ String validPath = "org/jboss/seam/faces/environment/mock.resource";
+ URL url = resolver.resolveUrl(validPath);
+ assertTrue(url instanceof URL);
+ }
+
+ @Test
+ public void testNullInputYieldsNullOutput() throws Exception
+ {
+ URL url = resolver.resolveUrl(null);
+ assertNull(url);
+ }
+
+ @Test
+ public void testResolveUrlReturnsNullIfNotFound()
+ {
+ String invalidPath = "some/nonexistent/mock.resource";
+ URL url = resolver.resolveUrl(invalidPath);
+ assertNull(url);
+ }
+
+}
Added: modules/faces/trunk/impl/src/test/resources/org/jboss/seam/faces/environment/mock.resource
===================================================================
--- modules/faces/trunk/impl/src/test/resources/org/jboss/seam/faces/environment/mock.resource (rev 0)
+++ modules/faces/trunk/impl/src/test/resources/org/jboss/seam/faces/environment/mock.resource 2010-05-13 18:19:20 UTC (rev 12726)
@@ -0,0 +1 @@
+SomeMockResourceDataHere
\ No newline at end of file
More information about the seam-commits
mailing list