Author: alexsmirnov
Date: 2010-12-02 19:26:26 -0500 (Thu, 02 Dec 2010)
New Revision: 20322
Added:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Resource.java
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/csv.xml
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/CustomValidator.java
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Component.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/validator/ValidatorWithFacesResource.java
branches/RF-8742-1/ui/validator/ui/src/test/resources/badcsv.xml
branches/RF-8742-1/ui/validator/ui/src/test/resources/csv.xml
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
Log:
CODING IN PROGRESS - issue RF-9799: CSV code review
https://jira.jboss.org/browse/RF-9799
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -3,14 +3,19 @@
*/
package org.richfaces.javascript;
+import java.util.List;
import java.util.Map;
import javax.faces.application.Resource;
+import javax.faces.application.ResourceDependency;
import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
import org.richfaces.component.util.Strings;
+import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.Lists;
+
/**
* @author asmirnov
*
@@ -52,7 +57,11 @@
private LibraryFunction getScriptFromAnnotation(Class<?> javaClass) throws
ScriptNotFoundException {
if (javaClass.isAnnotationPresent(ClientSideScript.class)) {
ClientSideScript clientSideScript =
javaClass.getAnnotation(ClientSideScript.class);
- return new LibraryFunctionImplementation(clientSideScript.function(),
clientSideScript.resource(), clientSideScript.library());
+ List<ResourceKey> resources = Lists.newArrayList();
+ for(ResourceDependency dependency: clientSideScript.resources()){
+
resources.add(ResourceKey.create(dependency.name(),dependency.library()));
+ }
+ return new LibraryFunctionImplementation(clientSideScript.function(),
resources);
} else {
throw new ScriptNotFoundException();
}
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -12,11 +12,15 @@
import javax.faces.FacesException;
import javax.xml.bind.JAXB;
+import org.richfaces.resource.ResourceKey;
import org.richfaces.validator.model.ClientSideScripts;
import org.richfaces.validator.model.Component;
+import org.richfaces.validator.model.Resource;
+import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
/**
@@ -52,8 +56,15 @@
ClientSideScripts clientSideScripts = JAXB.unmarshal(url,
ClientSideScripts.class);
for (Component component : clientSideScripts.getComponent()) {
Class<?> componentClass = loader.loadClass(component.getType());
+ Iterable<ResourceKey> resources =
Iterables.transform(component.getResource(), new Function<Resource,ResourceKey>(){
+
+ public ResourceKey apply(Resource from) {
+ return ResourceKey.create(from.getName(),from.getLibrary());
+ }
+
+ });
LibraryFunctionImplementation function = new
LibraryFunctionImplementation(component.getFunction(),
- component.getResource(), component.getLibrary());
+ resources);
result.put(componentClass, function);
}
} catch (ClassNotFoundException e) {
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -4,13 +4,15 @@
import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.ImmutableList;
+
final class LibraryFunctionImplementation implements LibraryFunction {
private final Iterable<ResourceKey> library;
private final String functionName;
- LibraryFunctionImplementation(String functionName, ResourceKey library) {
- this.library = Collections.singleton(library);
+ LibraryFunctionImplementation(String functionName, Iterable<ResourceKey>
dependencies) {
+ this.library = ImmutableList.copyOf(dependencies);
this.functionName = functionName;
}
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Component.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Component.java 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Component.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -1,17 +1,18 @@
package org.richfaces.validator.model;
+import java.util.List;
+
import javax.xml.bind.annotation.XmlElement;
+import com.google.common.collect.Lists;
+
public class Component {
private String type;
private String function;
- private String library;
-
- private String resource;
-
+ private List<Resource> resource = Lists.newArrayList();
/**
* @return the type
*/
@@ -43,32 +44,19 @@
}
/**
- * @return the library
- */
- @XmlElement
- public String getLibrary() {
- return library;
- }
-
- /**
- * @param library the library to set
- */
- public void setLibrary(String library) {
- this.library = library;
- }
-
- /**
+ * <p class="changed_added_4_0"></p>
* @return the resource
*/
- @XmlElement
- public String getResource() {
- return resource;
+ public List<Resource> getResource() {
+ return this.resource;
}
/**
+ * <p class="changed_added_4_0"></p>
* @param resource the resource to set
*/
- public void setResource(String resource) {
+ @XmlElement
+ public void setResource(List<Resource> resource) {
this.resource = resource;
}
Added:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Resource.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Resource.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Resource.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -0,0 +1,45 @@
+package org.richfaces.validator.model;
+
+import javax.xml.bind.annotation.XmlElement;
+
+public class Resource {
+
+ private String name;
+
+ private String library;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the name
+ */
+ @XmlElement
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the library
+ */
+ @XmlElement
+ public String getLibrary() {
+ return this.library;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param library the library to set
+ */
+ public void setLibrary(String library) {
+ this.library = library;
+ }
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/validator/model/Resource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/csv.xml
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/csv.xml
(rev 0)
+++ branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/csv.xml 2010-12-03
00:26:26 UTC (rev 20322)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scripts>
+ <component>
+ <type>javax.faces.convert.NumberConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <resource>
+ <name>number-converter.js</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertNumber</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.LengthValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <resource>
+ <name>length-validator.js</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateLength</function>
+ </component>
+</scripts>
\ No newline at end of file
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/csv.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties 2010-12-03
00:26:26 UTC (rev 20322)
@@ -0,0 +1 @@
+resources=jquery.js, richfaces.js, richfaces-event.js, org.richfaces:richfaces-csv.js
\ No newline at end of file
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -0,0 +1,90 @@
+package org.richfaces.component;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.hamcrest.Matcher;
+import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+
+/**
+ * Test for dynamic add/remove {@link UIScripts} as view resource.
+ * @author asmirnov
+ *
+ */
+public class ClientValidationTest {
+
+ private HtmlUnitEnvironment environment;
+
+
+ @Before
+ public void setUp() {
+ this.environment = new HtmlUnitEnvironment();
+
this.environment.withWebRoot("org/richfaces/component/client-test.xhtml").start();
+ }
+
+ @After
+ public void thearDown() throws Exception{
+ environment.release();
+ environment = null;
+ }
+
+ @Test
+ public void testRequest() throws Exception {
+ HtmlPage page = requestPage();
+ HtmlInput input = hetInput(page);
+ assertNotNull(input);
+
+ }
+
+ @Test
+ public void testSubmitTooShortValue() throws Exception {
+ submitValueAndCheckMesage("",containsString("Error"));
+ }
+
+ @Test
+ public void testSubmitTooLongValue() throws Exception {
+ submitValueAndCheckMesage("123456",containsString("Error"));
+ }
+
+ @Test
+ public void testSubmitProperValue() throws Exception {
+ submitValueAndCheckMesage("ab",equalTo(""));
+ }
+
+ private void submitValueAndCheckMesage(String value, Matcher<String> matcher)
throws Exception {
+ HtmlPage page = requestPage();
+ HtmlInput input = hetInput(page);
+ input.setValueAttribute(value);
+ input.fireEvent("keyup");
+ HtmlElement message = page.getElementById("form:message");
+ assertThat(message.getTextContent(), matcher);
+// System.out.println(page.asXml());
+ }
+ private HtmlInput hetInput(HtmlPage page) {
+ HtmlForm htmlForm = page.getFormByName("form");
+ assertNotNull(htmlForm);
+ HtmlInput input = htmlForm.getInputByName("form:text");
+ return input;
+ }
+
+ private HtmlPage requestPage() throws MalformedURLException, IOException {
+ HtmlPage page = environment.getPage("/client-test.jsf");
+ System.out.println(page.asXml());
+ return page;
+ }
+
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/CustomValidator.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/CustomValidator.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/CustomValidator.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ * 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.richfaces.component;
+
+import javax.faces.validator.LengthValidator;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class CustomValidator extends LengthValidator {
+
+ public CustomValidator() {
+ setMinimum(1);
+ setMaximum(3);
+ }
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/CustomValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/validator/ValidatorWithFacesResource.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/validator/ValidatorWithFacesResource.java 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/validator/ValidatorWithFacesResource.java 2010-12-03
00:26:26 UTC (rev 20322)
@@ -1,8 +1,10 @@
package org.richfaces.validator;
+import javax.faces.application.ResourceDependency;
+
import org.richfaces.javascript.ClientSideScript;
-@ClientSideScript(function="foo",library="bar",resource="baz.js")
+@ClientSideScript(function="foo",resources=(a)ResourceDependency(name="baz.js",library="bar"))
public class ValidatorWithFacesResource {
}
Modified: branches/RF-8742-1/ui/validator/ui/src/test/resources/badcsv.xml
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/resources/badcsv.xml 2010-12-02 23:10:02
UTC (rev 20321)
+++ branches/RF-8742-1/ui/validator/ui/src/test/resources/badcsv.xml 2010-12-03 00:26:26
UTC (rev 20322)
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<scripts>
- <component>
- <type>non.existed.Class</type>
- <library>org.richfaces</library>
- <resource>csv.js</resource>
- <function>stringConverter</function>
- </component>
+ <component>
+ <type>non.existed.Class</type>
+ <resource>
+ <name>csv.js</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>stringConverter</function>
+ </component>
</scripts>
\ No newline at end of file
Modified: branches/RF-8742-1/ui/validator/ui/src/test/resources/csv.xml
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/resources/csv.xml 2010-12-02 23:10:02 UTC
(rev 20321)
+++ branches/RF-8742-1/ui/validator/ui/src/test/resources/csv.xml 2010-12-03 00:26:26 UTC
(rev 20322)
@@ -2,14 +2,18 @@
<scripts>
<component>
<type>java.lang.String</type>
- <library>org.richfaces</library>
- <resource>csv.js</resource>
+ <resource>
+ <name>csv.js</name>
+ <library>org.richfaces</library>
+ </resource>
<function>stringConverter</function>
</component>
<component>
<type>java.lang.Integer</type>
- <library>org.richfaces</library>
- <resource>csv.js</resource>
+ <resource>
+ <name>csv.js</name>
+ <library>org.richfaces</library>
+ </resource>
<function>intConverter</function>
</component>
</scripts>
\ No newline at end of file
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/WEB-INF/faces-config.xml 2010-12-03
00:26:26 UTC (rev 20322)
@@ -5,4 +5,8 @@
<managed-bean-class>org.richfaces.component.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
+<validator>
+ <validator-id>custom</validator-id>
+ <validator-class>org.richfaces.component.CustomValidator</validator-class>
+</validator>
</faces-config>
\ No newline at end of file
Added:
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml 2010-12-03
00:26:26 UTC (rev 20322)
@@ -0,0 +1,16 @@
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:csv="http://richfaces.org/csv">
+ <h:head><title>Ajax validator</title></h:head>
+ <h:body>
+ <h:form id="form">
+ <h:inputText id="text" value="#{test.value}">
+ <f:validateLength minimum="1" maximum="3"/>
+ <csv:validator event="keyup" />
+ </h:inputText>
+ <h:outputText id="out"
value="#{test.value}"></h:outputText>
+ <h:message id="message" for="text" />
+ </h:form>
+ </h:body>
+</html>
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml 2010-12-02
23:10:02 UTC (rev 20321)
+++
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml 2010-12-03
00:26:26 UTC (rev 20322)
@@ -6,7 +6,7 @@
<h:body>
<h:form id="form">
<h:inputText id="text" value="#{test.value}">
- <f:validateLength minimum="1" maximum="3"/>
+ <f:validator validatorId="custom" />
<csv:validator event="keyup" />
</h:inputText>
<h:outputText id="out"
value="#{test.value}"></h:outputText>