Author: alexsmirnov
Date: 2011-01-20 19:29:53 -0500 (Thu, 20 Jan 2011)
New Revision: 21136
Added:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
Modified:
trunk/
trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java
trunk/examples/validator-demo/pom.xml
trunk/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
Log:
Merged revisions 20994,21013,21036,21041,21067,21102,21134 via svnmerge from
https://svn.jboss.org/repos/richfaces/branches/RF-9797
.......
r20994 | pyaschenko | 2011-01-13 07:49:52 -0800 (Thu, 13 Jan 2011) | 1 line
RF-9797
.......
r21013 | alexsmirnov | 2011-01-13 17:03:54 -0800 (Thu, 13 Jan 2011) | 2 lines
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current
wiki document
https://issues.jboss.org/browse/RF-9797
.......
r21036 | pyaschenko | 2011-01-14 09:23:26 -0800 (Fri, 14 Jan 2011) | 5 lines
RF-9797
validators and converter hash script rendering were added
validators and converters were moved to RichFaces.csv container
bugfix
.......
r21041 | alexsmirnov | 2011-01-14 16:56:14 -0800 (Fri, 14 Jan 2011) | 2 lines
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current
wiki document
https://issues.jboss.org/browse/RF-9797
.......
r21067 | alexsmirnov | 2011-01-18 23:55:42 -0800 (Tue, 18 Jan 2011) | 3 lines
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current
wiki document
https://issues.jboss.org/browse/RF-9797
Length validator working.
.......
r21102 | alexsmirnov | 2011-01-19 15:20:06 -0800 (Wed, 19 Jan 2011) | 2 lines
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current
wiki document
https://issues.jboss.org/browse/RF-9797
.......
r21134 | alexsmirnov | 2011-01-20 15:41:01 -0800 (Thu, 20 Jan 2011) | 2 lines
RESOLVED - issue RF-9797: CSV: make client code compatible with the current wiki
document
https://issues.jboss.org/browse/RF-9797
.......
Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
- /branches/RF-7817:1-19154 /branches/RF-8742:1-19867 /branches/RF-9309:1-19112,19378
/branches/RF-9323:1-20621 /branches/RF-9797:1-20979
+ /branches/RF-7817:1-19154 /branches/RF-8742:1-19867 /branches/RF-9309:1-19112,19378
/branches/RF-9323:1-20621 /branches/RF-9797:1-21135
Modified: trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java
===================================================================
---
trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -79,9 +79,14 @@
first = false;
}
- target.append("){").append(body).append("}");
+ target.append("){");appendBody(target);
+ target.append("}");
}
+ protected void appendBody(Appendable target) throws IOException {
+ target.append(body);
+ }
+
/**
* @return the name
*/
Modified: trunk/examples/validator-demo/pom.xml
===================================================================
--- trunk/examples/validator-demo/pom.xml 2011-01-20 23:59:35 UTC (rev 21135)
+++ trunk/examples/validator-demo/pom.xml 2011-01-21 00:29:53 UTC (rev 21136)
@@ -60,5 +60,20 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.11</version>
+ </dependency>
</dependencies>
</project>
Modified: trunk/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java
===================================================================
--- trunk/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java 2011-01-20
23:59:35 UTC (rev 21135)
+++ trunk/ui/validator/api/src/main/java/org/richfaces/javascript/Message.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -43,5 +43,51 @@
public String getSummary() {
return summary;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((this.detail == null) ? 0 : this.detail.hashCode());
+ result = prime * result + this.severity;
+ result = prime * result + ((this.summary == null) ? 0 :
this.summary.hashCode());
+ return result;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Message other = (Message) obj;
+ if (this.detail == null) {
+ if (other.detail != null) {
+ return false;
+ }
+ } else if (!this.detail.equals(other.detail)) {
+ return false;
+ }
+ if (this.severity != other.severity) {
+ return false;
+ }
+ if (this.summary == null) {
+ if (other.summary != null) {
+ return false;
+ }
+ } else if (!this.summary.equals(other.summary)) {
+ return false;
+ }
+ return true;
+ }
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1,32 +1,30 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
import java.util.Collections;
import org.richfaces.resource.ResourceKey;
public class AjaxOnlyScript extends ValidatorScriptBase {
+ public static final Iterable<ResourceKey> AJAX_LIBRARIES =
Collections.singleton(ResourceKey.create("ajax.reslib",
+ "org.richfaces"));
- public static final Iterable<ResourceKey>
AJAX_LIBRARIES=Collections.singleton(ResourceKey.create("ajax.reslib",
"org.richfaces"));
-
private final String ajaxScript;
public AjaxOnlyScript(String ajaxScript) {
super();
this.ajaxScript = ajaxScript;
-
+
}
public Iterable<ResourceKey> getResources() {
return AJAX_LIBRARIES;
}
- @Override
- protected Object buildBody() {
- return ajaxScript;
- }
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -37,7 +35,9 @@
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -61,5 +61,12 @@
}
return true;
}
-
+
+ @Override
+ protected void appendBody(Appendable target) throws IOException {
+ target.append("if(!").append(DISABLE_AJAX).append("){(");
+ appendAjaxFunction(target, ajaxScript);
+
target.append(").call(").append(ELEMENT).append(",").append(EVENT).append(",").append(CLIENT_ID).append(");");
+ target.append(("}"));
+ }
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1,8 +1,8 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
import java.util.Collection;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
import com.google.common.collect.Iterables;
@@ -12,26 +12,27 @@
- final String ajaxScript;
+ private final String ajaxScript;
+ private final Iterable<ResourceKey> resources;
- public ClientAndAjaxScript(ScriptWithDependencies clientSideConverterScript,
- Collection<? extends ScriptWithDependencies> validatorScripts, String
ajaxScript) {
+ public ClientAndAjaxScript(LibraryScriptFunction clientSideConverterScript,
+ Collection<? extends LibraryScriptFunction> validatorScripts, String
ajaxScript) {
super(clientSideConverterScript,validatorScripts);
this.ajaxScript = ajaxScript;
+ resources =
Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
}
@Override
public Iterable<ResourceKey> getResources() {
- return Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
+ return resources;
}
- protected void finishValidation(StringBuilder body) {
- // AJAX callback
- body.append("if(!").append(DISABLE_AJAX).append("){\n");
- body.append(ajaxScript).append(EOL).append("}\n");
+
+ @Override
+ protected void appendAjaxParameter(Appendable target) throws IOException {
+ appendAjaxParameter(target, ajaxScript);
}
-
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1,76 +1,85 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashSet;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
+import com.google.common.collect.UnmodifiableIterator;
public class ClientOnlyScript extends ValidatorScriptBase {
- protected final ScriptWithDependencies converter;
- protected final Collection<? extends ScriptWithDependencies> validators;
+ private static final ResourceKey CSV_RESOURCE =
ResourceKey.create("csv.reslib", "org.richfaces");
+ protected final LibraryScriptFunction converter;
+ protected final ImmutableList<? extends LibraryScriptFunction> validators;
+ private final ImmutableSet<ResourceKey> resources;
- public ClientOnlyScript(ScriptWithDependencies clientSideConverterScript,
- Collection<? extends ScriptWithDependencies> validatorScripts) {
+ public ClientOnlyScript(LibraryScriptFunction clientSideConverterScript,
+ Collection<? extends LibraryScriptFunction> validatorScripts) {
super();
- if(null==clientSideConverterScript){
- this.converter = NULL_CONVERTER_SCRIPT;
- } else {
- this.converter = clientSideConverterScript;
+ this.converter = clientSideConverterScript;
+ this.validators = ImmutableList.copyOf(validatorScripts);
+ LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
+ if (null != converter) {
+ Iterables.addAll(resources, converter.getResources());
}
- this.validators = validatorScripts;
-
+ for (LibraryScriptFunction scriptString : validators) {
+ Iterables.addAll(resources, scriptString.getResources());
+ }
+ resources.add(CSV_RESOURCE);
+ this.resources = ImmutableSet.copyOf(resources);
}
public Iterable<ResourceKey> getResources() {
- // TODO - make immutable.
- LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
- Iterables.addAll(resources,converter.getResources());
- for (ScriptWithDependencies scriptString : validators) {
- Iterables.addAll(resources,scriptString.getResources());
- }
return resources;
}
@Override
- protected Object buildBody() {
- StringBuilder body = new StringBuilder();
- // Get component value by clientId.
- body.append("var
").append(ClientValidatorRenderer.VALUE_VAR).append("=");
- GET_VALUE_FUNCTION.appendScriptToStringBuilder(body);
- body.append(EOL);
- // Try client-side validation
- body.append("try {\n");
- // convert value
- body.append("var
").append(ClientValidatorRenderer.CONVERTED_VALUE_VAR).append("=");
- converter.appendScriptToStringBuilder(body);
- body.append(EOL);
- // call validators
- for (ScriptWithDependencies validatorScript : validators) {
- validatorScript.appendScriptToStringBuilder(body);
- body.append(EOL);
+ protected void appendParameters(Appendable target) throws IOException {
+ if (null != converter) {
+ target.append(CONVERTER).append(":");
+ appendConverter(target, converter);
+ target.append(",");
}
- finishValidation(body);
- body.append("return true;\n");
- // Catch errors
- body.append("} catch(e) {\n");
- SEND_ERROR_FUNCTION.appendScriptToStringBuilder(body);body.append(EOL);
- body.append("return false;\n}");
- return body;
+ target.append(VALIDATORS).append(":[");
+
+ UnmodifiableIterator<? extends LibraryScriptFunction> iterator =
validators.iterator();
+ while (iterator.hasNext()) {
+ LibraryScriptFunction validatorScript = (LibraryScriptFunction)
iterator.next();
+ appendValidator(target, validatorScript);
+ if (iterator.hasNext()) {
+ target.append(",");
+ }
+ }
+ target.append("]");
+ appendAjaxParameter(target);
}
- protected void finishValidation(StringBuilder body) {
- // clear messages after successful validation
- body.append("if(!").append(DISABLE_AJAX).append("){\n");
- CLEAR_ERROR_FUNCTION.appendScriptToStringBuilder(body);
- body.append(EOL).append("}\n");
+ protected void appendValidator(Appendable target, LibraryScriptFunction
validatorScript) throws IOException {
+ appendConverter(target, validatorScript);
}
- /* (non-Javadoc)
+ protected void appendConverter(Appendable target, LibraryScriptFunction converter)
throws IOException {
+
target.append('{').append("f").append(':').append(converter.getName()).append(',');
+ target.append(PARAMS).append(':');ScriptUtils.appendScript(target,
converter.getParameters());
+ target.append(',');
+ target.append(MESSAGE).append(':');ScriptUtils.appendScript(target,
converter.getMessage());
+ target.append('}');
+ }
+
+ protected void appendAjaxParameter(Appendable target) throws IOException {
+ // This is client-only validation script.
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -82,7 +91,9 @@
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -114,5 +125,4 @@
return true;
}
-
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -19,7 +19,6 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
import org.richfaces.application.ServiceTracker;
import org.richfaces.component.behavior.ClientValidatorBehavior;
import org.richfaces.component.behavior.ConverterNotFoundException;
@@ -38,7 +37,6 @@
*/
public class ClientValidatorRenderer extends ClientBehaviorRenderer {
-
public static final String RENDERER_TYPE =
"org.richfaces.ClientValidatorRenderer";
public static final String VALUE_VAR = "value";
@@ -80,48 +78,46 @@
throw new IllegalArgumentException(
"Instance of
org.ruchvaces.component.behaviot.ClientValidatorBehavior required: " + behavior);
}
- ClientValidatorBehavior ajaxBehavior = (ClientValidatorBehavior)behavior;
+ ClientValidatorBehavior ajaxBehavior = (ClientValidatorBehavior) behavior;
// First things first - if AjaxBehavior is disabled, we are done.
if (!ajaxBehavior.isDisabled()) {
component.queueEvent(createEvent(component, ajaxBehavior));
- }
+ }
}
// Creates an AjaxBehaviorEvent for the specified component/behavior
- private static AjaxBehaviorEvent createEvent(UIComponent component,
- ClientValidatorBehavior ajaxBehavior) {
+ private static AjaxBehaviorEvent createEvent(UIComponent component,
ClientValidatorBehavior ajaxBehavior) {
AjaxBehaviorEvent event = new AjaxBehaviorEvent(component, ajaxBehavior);
- PhaseId phaseId = isImmediate(component, ajaxBehavior) ?
- PhaseId.APPLY_REQUEST_VALUES :
- PhaseId.PROCESS_VALIDATIONS;
+ PhaseId phaseId =
+ isImmediate(component, ajaxBehavior) ? PhaseId.APPLY_REQUEST_VALUES :
PhaseId.PROCESS_VALIDATIONS;
event.setPhaseId(phaseId);
return event;
}
-
- // Tests whether we should perform immediate processing. Note
+ // Tests whether we should perform immediate processing. Note
// that we "inherit" immediate from the parent if not specified
// on the behavior.
- private static boolean isImmediate(UIComponent component,
- ClientValidatorBehavior ajaxBehavior) {
+ private static boolean isImmediate(UIComponent component, ClientValidatorBehavior
ajaxBehavior) {
boolean immediate = false;
if (ajaxBehavior.isImmediateSet()) {
immediate = ajaxBehavior.isImmediate();
} else if (component instanceof EditableValueHolder) {
- immediate = ((EditableValueHolder)component).isImmediate();
+ immediate = ((EditableValueHolder) component).isImmediate();
} else if (component instanceof ActionSource) {
- immediate = ((ActionSource)component).isImmediate();
+ immediate = ((ActionSource) component).isImmediate();
}
return immediate;
- } /**
+ }
+
+ /**
* <p class="changed_added_4_0">
* This method builds client-side validation script and stores it in View resource
component
* </p>
@@ -136,14 +132,13 @@
FacesContext facesContext = behaviorContext.getFacesContext();
JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
validatorScript = javaScriptService.addScript(facesContext,
validatorScript);
- return
validatorScript.createCallScript(behaviorContext.getComponent().getClientId(facesContext),behaviorContext.getSourceId());
+ return
validatorScript.createCallScript(behaviorContext.getComponent().getClientId(facesContext),
+ behaviorContext.getSourceId());
} else {
return null;
}
}
-
-
ComponentValidatorScript createValidatorScript(ClientBehaviorContext
behaviorContext,
ClientValidatorBehavior behavior) {
ValidatorScriptBase validatorScript;
@@ -153,9 +148,10 @@
ConverterDescriptor converter = behavior.getConverter(behaviorContext);
if (null != converter) {
try {
- ScriptWithDependencies clientSideConverterScript =
+ LibraryScriptFunction clientSideConverterScript =
getClientSideConverterScript(behaviorContext.getFacesContext(), converter);
- validatorScript = createValidatorScript(behaviorContext,
behavior, validators, clientSideConverterScript);
+ validatorScript =
+ createValidatorScript(behaviorContext, behavior, validators,
clientSideConverterScript);
} catch (ScriptNotFoundException e) {
// ajax-only validation
validatorScript = new
AjaxOnlyScript(createAjaxScript(behaviorContext, behavior));
@@ -167,7 +163,7 @@
throw new FacesException(e);
}
String clientId = getComponentClientId(behaviorContext);
- String name = ScriptUtils.getValidJavascriptName(clientId+":v");
+ String name = ScriptUtils.getValidJavascriptName(clientId + ":v");
validatorScript.setName(name);
return validatorScript;
} else {
@@ -182,13 +178,14 @@
private ValidatorScriptBase createValidatorScript(ClientBehaviorContext
behaviorContext,
ClientValidatorBehavior behavior, Collection<ValidatorDescriptor>
validators,
- ScriptWithDependencies clientSideConverterScript) {
- Collection<? extends ScriptWithDependencies> validatorScripts =
getClientSideValidatorScript(behaviorContext.getFacesContext(), validators);
+ LibraryScriptFunction clientSideConverterScript) {
+ Collection<? extends LibraryScriptFunction> validatorScripts =
+ getClientSideValidatorScript(behaviorContext.getFacesContext(), validators);
if (validatorScripts.isEmpty()) {
return new AjaxOnlyScript(createAjaxScript(behaviorContext, behavior));
} else if (validatorScripts.size() < validators.size()) {
- return new ClientAndAjaxScript(clientSideConverterScript, validatorScripts,
- createAjaxScript(behaviorContext, behavior));
+ return new ClientAndAjaxScript(clientSideConverterScript, validatorScripts,
createAjaxScript(
+ behaviorContext, behavior));
} else {
return new ClientOnlyScript(clientSideConverterScript, validatorScripts);
}
@@ -196,19 +193,19 @@
private String createAjaxScript(ClientBehaviorContext behaviorContext,
ClientValidatorBehavior behavior) {
String ajaxScript = behavior.getAjaxScript(behaviorContext);
- ajaxScript=ajaxScript.replace("this", ValidatorScriptBase.ELEMENT);
String clientId = getComponentClientId(behaviorContext);
ajaxScript = replaceTextToVariable(ajaxScript, clientId,
ValidatorScriptBase.CLIENT_ID);
String sourceId = behaviorContext.getSourceId();
- if(null != sourceId){
+ if (null != sourceId) {
+ // TODO - send sourceId as separate parameter.
ajaxScript = replaceTextToVariable(ajaxScript, sourceId,
ValidatorScriptBase.ELEMENT);
}
return ajaxScript;
}
private String replaceTextToVariable(String ajaxScript, String clientId, String
variableName) {
-
ajaxScript=ajaxScript.replace("'"+clientId+"'",variableName);
-
ajaxScript=ajaxScript.replace("\""+clientId+"\"",variableName);
+ ajaxScript = ajaxScript.replace("'" + clientId + "'",
variableName);
+ ajaxScript = ajaxScript.replace("\"" + clientId +
"\"", variableName);
return ajaxScript;
}
@@ -231,17 +228,16 @@
* @return
* @throws ScriptNotFoundException
*/
- ScriptWithDependencies getClientSideConverterScript(FacesContext facesContext,
- ConverterDescriptor converter) throws ScriptNotFoundException {
- ClientScriptService clientScriptService =
- ServiceTracker.getService(facesContext, ClientScriptService.class);
- return createClientFunction(facesContext, converter, VALUE_LITERAL,
clientScriptService);
+ LibraryScriptFunction getClientSideConverterScript(FacesContext facesContext,
ConverterDescriptor converter)
+ throws ScriptNotFoundException {
+ ClientScriptService clientScriptService = ServiceTracker.getService(facesContext,
ClientScriptService.class);
+ return createClientFunction(facesContext, converter, clientScriptService);
}
- private ScriptWithDependencies createClientFunction(FacesContext facesContext,
FacesObjectDescriptor descriptor,
- JSReference variable, ClientScriptService clientScriptService) throws
ScriptNotFoundException {
+ private LibraryScriptFunction createClientFunction(FacesContext facesContext,
FacesObjectDescriptor descriptor,
+ ClientScriptService clientScriptService) throws ScriptNotFoundException {
LibraryFunction script = clientScriptService.getScript(facesContext,
descriptor.getImplementationClass());
- return new LibraryScriptFunction(script, variable, descriptor.getMessage(),
descriptor.getAdditionalParameters());
+ return new LibraryScriptFunction(script, descriptor.getMessage(),
descriptor.getAdditionalParameters());
}
/**
@@ -254,14 +250,14 @@
* @return
* @throws ScriptNotFoundException
*/
- Collection<? extends ScriptWithDependencies>
getClientSideValidatorScript(FacesContext facesContext,
+ Collection<? extends LibraryScriptFunction>
getClientSideValidatorScript(FacesContext facesContext,
Collection<ValidatorDescriptor> validators) {
- ClientScriptService clientScriptService =
- ServiceTracker.getService(facesContext, ClientScriptService.class);
- List<ScriptWithDependencies> scripts = Lists.newArrayList();
+ ClientScriptService clientScriptService = ServiceTracker.getService(facesContext,
ClientScriptService.class);
+ List<LibraryScriptFunction> scripts = Lists.newArrayList();
for (FacesObjectDescriptor validator : validators) {
try {
- scripts.add(createClientFunction(facesContext, validator,
CONVERTED_VALUE_LITERAL, clientScriptService));
+ scripts
+ .add(createClientFunction(facesContext, validator,
clientScriptService));
} catch (ScriptNotFoundException e) {
// Skip this validator for AJAX call.
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -23,11 +23,15 @@
package org.richfaces.renderkit.html;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
+import java.util.Map;
+
import org.richfaces.javascript.LibraryFunction;
+import org.richfaces.javascript.Message;
import org.richfaces.resource.ResourceKey;
+import org.richfaces.resource.ResourceLibrary;
+import com.google.common.collect.ImmutableSet;
+
/**
* <p class="changed_added_4_0">
* This class represents call to function in external library.
@@ -36,14 +40,17 @@
* @author asmirnov(a)exadel.com
*
*/
-public class LibraryScriptFunction extends JSFunction implements ScriptWithDependencies
{
+public class LibraryScriptFunction implements ResourceLibrary {
- private final Iterable<ResourceKey> resources;
+ private final ImmutableSet<ResourceKey> resources;
private final String name;
+ private final Message message;
+ private final Map<String, ? extends Object> parameters;
- public LibraryScriptFunction(LibraryFunction libraryScript, Object... parameters) {
- super(libraryScript.getName(), parameters);
- this.resources = libraryScript.getResources();
+ public LibraryScriptFunction(LibraryFunction libraryScript, Message message,
Map<String, ? extends Object> parameters) {
+ this.message = message;
+ this.parameters = parameters;
+ this.resources = ImmutableSet.copyOf(libraryScript.getResources());
this.name = libraryScript.getName();
}
@@ -60,6 +67,26 @@
return resources;
}
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the message
+ */
+ public Message getMessage() {
+ return this.message;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the parameters
+ */
+ public Map<String, ? extends Object> getParameters() {
+ return this.parameters;
+ }
+
/*
* (non-Javadoc)
*
@@ -69,9 +96,10 @@
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((resources == null) ? 0 : resources.hashCode());
- result = prime * result + getParameters().hashCode();
+ result = prime * result + ((this.message == null) ? 0 :
this.message.hashCode());
+ result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
+ result = prime * result + ((this.parameters == null) ? 0 :
this.parameters.hashCode());
+ result = prime * result + ((this.resources == null) ? 0 :
this.resources.hashCode());
return result;
}
@@ -92,29 +120,35 @@
return false;
}
LibraryScriptFunction other = (LibraryScriptFunction) obj;
- if (name == null) {
+ if (this.message == null) {
+ if (other.message != null) {
+ return false;
+ }
+ } else if (!this.message.equals(other.message)) {
+ return false;
+ }
+ if (this.name == null) {
if (other.name != null) {
return false;
}
- } else if (!name.equals(other.name)) {
+ } else if (!this.name.equals(other.name)) {
return false;
}
- if (resources == null) {
+ if (this.parameters == null) {
+ if (other.parameters != null) {
+ return false;
+ }
+ } else if (!this.parameters.equals(other.parameters)) {
+ return false;
+ }
+ if (this.resources == null) {
if (other.resources != null) {
return false;
}
- } else if (!resources.equals(other.resources)) {
+ } else if (!this.resources.equals(other.resources)) {
return false;
- } else if (!getParameters().equals(other.getParameters())) {
- return false;
}
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
-
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -6,46 +6,80 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
-public abstract class ValidatorScriptBase extends JSFunctionDefinition implements
ComponentValidatorScript {
+public abstract class ValidatorScriptBase extends JSFunctionDefinition implements
ComponentValidatorScript {
- public static final String ELEMENT = "element";
- public static final JSReference ELEMENT_LITERAL = new JSReference(ELEMENT);
+ public static final String ELEMENT = "e";
+ public static final JSReference ELEMENT_REF = new JSReference(ELEMENT);
public static final String EVENT = "event";
- public static final JSReference EVENT_LITERAL = new JSReference(EVENT);
- public static final String DISABLE_AJAX = "disableAjax";
+ public static final JSReference EVENT_REF = new JSReference(EVENT);
+ public static final String DISABLE_AJAX = "da";
+ public static final JSReference DISABLE_AJAX_REF = new JSReference(DISABLE_AJAX);
public static final String EOL = ";\n";
- public static final String CLIENT_ID = "clientId";
- public static final JSReference CLIENT_ID_LITERAL = new JSReference(CLIENT_ID);
- public static final String SOURCE_ID = "sourceId";
- public static final JSReference SOURCE_ID_LITERAL = new JSReference(SOURCE_ID);
+ public static final String CLIENT_ID = "id";
+ public static final JSReference CLIENT_ID_REF = new JSReference(CLIENT_ID);
+ public static final String SOURCE_ID = "sid";
+ public static final JSReference SOURCE_ID_REF = new JSReference(SOURCE_ID);
+ public static final String CONVERTER = "c";
+ public static final JSReference CONVERTER_REF = new JSReference(CONVERTER);
+ public static final String VALIDATORS = "v";
+ public static final JSReference VALIDATORS_REF = new JSReference(VALIDATORS);
+ public static final String AJAX = "a";
+ public static final JSReference AJAX_REF = new JSReference(AJAX);
+ public static final String PARAMS = "p";
+ public static final JSReference PARAMS_REF = new JSReference(PARAMS);
+ public static final String MESSAGE = "m";
+ public static final JSReference MESSAGE_REF = new JSReference(MESSAGE);
+
public static final NullConverterScript NULL_CONVERTER_SCRIPT = new
NullConverterScript();
public static final String CSV_NAMESPACE = "RichFaces.csv.";
- public static final String VALUE_FUNCTION_NAME = CSV_NAMESPACE+"getValue";
- public static final JSFunction GET_VALUE_FUNCTION = new
JSFunction(VALUE_FUNCTION_NAME,CLIENT_ID_LITERAL,ELEMENT_LITERAL);
- public static final JSFunction SEND_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"sendMessage",CLIENT_ID_LITERAL,new
JSReference("e"));
- public static final JSFunction CLEAR_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"clearMessage",CLIENT_ID_LITERAL);
-
- private boolean bodyProcessed = false;
+ public static final String VALUE_FUNCTION_NAME = CSV_NAMESPACE +
"getValue";
+ public static final JSFunction GET_VALUE_FUNCTION = new
JSFunction(VALUE_FUNCTION_NAME, CLIENT_ID_REF, ELEMENT_REF);
+ public static final String VALIDATE_FUNCTION_NAME = CSV_NAMESPACE +
"validate";
+ public static final JSFunction VALIDATE_FUNCTION = new
JSFunction(VALIDATE_FUNCTION_NAME, CLIENT_ID_REF,
+ ELEMENT_REF);
public ValidatorScriptBase() {
- super(CLIENT_ID,ELEMENT,EVENT,DISABLE_AJAX);
+ super(EVENT, CLIENT_ID, ELEMENT, DISABLE_AJAX);
}
- public void appendScript(Appendable target) throws IOException {
- if(!bodyProcessed){
- // pending RF-9565
- addToBody(buildBody());
- bodyProcessed = true;
- }
- super.appendScript(target);
+ public String createCallScript(String clientId, String sourceId) {
+ JSFunction callFunction =
+ new JSFunction(getName(), EVENT_REF, clientId, null != sourceId ? sourceId :
JSReference.THIS);
+ return callFunction.toScript();
}
- protected abstract Object buildBody();
+ protected void appendParameters(Appendable target) throws IOException {
+ }
- public String createCallScript(String clientId,String sourceId) {
- JSFunction callFunction = new
JSFunction(getName(),clientId,null!=sourceId?sourceId:JSReference.THIS,EVENT_LITERAL);
- return callFunction.toScript();
+ @Override
+ protected void appendBody(Appendable target) throws IOException {
+ appendParametersDefinition(target);
+ appendValidatorCall(target);
}
+ private void appendParametersDefinition(Appendable target) throws IOException {
+ target.append("var ").append(PARAMS).append("={");
+
target.append(DISABLE_AJAX).append(':').append(DISABLE_AJAX).append(',');
+ appendParameters(target);
+ target.append("}").append(EOL);
+ }
+ protected void appendValidatorCall(Appendable target) throws IOException {
+ JSFunction callValidator =
+ new JSFunction(VALIDATE_FUNCTION_NAME, EVENT_REF, CLIENT_ID_REF, ELEMENT_REF,
PARAMS_REF);
+ callValidator.appendScript(target);
+ target.append(EOL);
+ }
+
+ protected void appendAjaxParameter(Appendable target, String ajaxScript) throws
IOException {
+ target.append(AJAX).append(':');
+ appendAjaxFunction(target, ajaxScript);
+ }
+
+ protected void appendAjaxFunction(Appendable target, String ajaxScript) throws
IOException {
+ JSFunctionDefinition ajaxFunction = new JSFunctionDefinition(EVENT, CLIENT_ID);
+ ajaxFunction.addToBody(ajaxScript);
+ ajaxFunction.appendScript(target);
+ }
+
}
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -52,7 +52,7 @@
* @param component
* @return
*/
- protected FacesMessage getMessage(FacesContext context, T component) {
+ public FacesMessage getMessage(FacesContext context, T component) {
String messageId = getMessageId(component);
return MessageFactory.createMessage(context, messageId);
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -35,13 +35,47 @@
@Override
protected String getMessageId(Validator component) {
+ // TODO: all messages should be passed to client side using js function
RichFaces.csv.addMessage
String messageId;
if (component instanceof DoubleRangeValidator) {
- messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ DoubleRangeValidator validator = (DoubleRangeValidator) component;
+ if(validator.getMaximum() > Double.MIN_VALUE){
+ if(validator.getMinimum()> Double.MIN_VALUE){
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.MAXIMUM_MESSAGE_ID;
+ }
+ } else if( validator.getMinimum()>Double.MIN_VALUE){
+ messageId = DoubleRangeValidator.MINIMUM_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
+ }
} else if (component instanceof LengthValidator) {
- messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ LengthValidator validator = (LengthValidator) component;
+ if(validator.getMaximum() >0){
+ if(validator.getMinimum()>0){
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ } else {
+ messageId = LengthValidator.MAXIMUM_MESSAGE_ID;
+ }
+ } else if( validator.getMinimum()>0){
+ messageId = LengthValidator.MINIMUM_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
+ }
} else if (component instanceof LongRangeValidator) {
- messageId = LongRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ LongRangeValidator validator = (LongRangeValidator) component;
+ if(validator.getMaximum() >0){
+ if(validator.getMinimum()>0){
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ } else {
+ messageId = LongRangeValidator.MAXIMUM_MESSAGE_ID;
+ }
+ } else if( validator.getMinimum()>0){
+ messageId = LongRangeValidator.MINIMUM_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
+ }
} else if (component instanceof RegexValidator) {
messageId = RegexValidator.NOT_MATCHED_MESSAGE_ID;
} else if (component instanceof RequiredValidator) {
Modified: trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml
===================================================================
--- trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-01-20 23:59:35 UTC (rev
21135)
+++ trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-01-21 00:29:53 UTC (rev
21136)
@@ -9,6 +9,30 @@
<function>RichFaces.csv.convertNumber</function>
</component>
<component>
+ <type>javax.faces.convert.BooleanConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertBoolean</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.ByteConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertByte</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.ShortConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertShort</function>
+ </component>
+ <component>
<type>javax.faces.validator.LengthValidator</type>
<resource>
<name>csv.reslib</name>
@@ -16,4 +40,76 @@
</resource>
<function>RichFaces.csv.validateLength</function>
</component>
+ <component>
+ <type>javax.faces.validator.LongRangeValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateLongRange</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.DoubleRangeValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateDoubleRange</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.RegexValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateRegex</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.RequiredValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateRequired</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.NotNull</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateRequired</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Size</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateSize</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Pattern</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validatePattern</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Min</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateMin</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Max</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateMax</function>
+ </component>
</scripts>
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-21
00:29:53 UTC (rev 21136)
@@ -6,8 +6,45 @@
var _validators = {};
var _converters = {};
- var RE_MESSAGE_PATTERN = /\{(\d+)\}/g;
+ var RE_MESSAGE_PATTERN = /\'?\{(\d+)\}\'?/g;
+ var __interpolateMessage = function (message, values) {
+ if (message) {
+ var msgObject =
message.replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
+ var value;
+ for (var i=1; i<msgObject.length; i+=2) {
+ value = values[msgObject[i]];
+ msgObject[i] = typeof value == "undefined" ? "" : value;
+ }
+ return msgObject.join('');
+ } else {
+ return "";
+ }
+ }
+
+ var _interpolateFacesMessage = function(msg,id,value){
+ var d = msg.detail?_substitute(msg.detail,id,value):"";
+ var s = msg.summary?_substitute(msg.summary,id,value):"";
+ return {detail:d,summary:s};
+ }
+
+ var _substitute = function(msg,id,value){
+ return msg.replace("{id}",id).replace("{value}",value);
+ }
+
+ var __getValue = function(id) {
+ var value;
+ var element = rf.getDomElement(id);
+ if (element.value) {
+ value = element.value;
+ } else {
+ var component = rf.$(element);
+ // TODO: add getValue to baseComponent and change jsdocs
+ value = component && typeof component["getValue"] ==
"function" ? component.getValue() : "";
+ }
+ return value;
+ }
+
$.extend(rf.csv, {
RE_DIGITS: /^-?\d+$/,
RE_FLOAT: /^(-?\d+)?(\.(\d+)?(e[+-]?\d+)?)?$/,
@@ -16,73 +53,200 @@
$.extend(_messages, messagesObject);
},
getMessage: function(customMessage, messageId, values) {
- var message = customMessage || _messages[messageId] || "";
- if (message) {
- var msgObject =
message.replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
- var value;
- for (var i=1; i<msgObject.length; i+=2) {
- value = values[msgObject[i]];
- msgObject[i] = typeof value == "undefined" ? "" : value;
- }
- message = msgObject.join('');
- }
- return {message:message};
+ var message = customMessage ? customMessage : _messages[messageId] ||
{detail:"",summary:""};
+ return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values)};
},
+ interpolateMessage: function(message,values){
+ return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values)};
+ },
sendMessage: function (componentId, message) {
rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId, 'message':message});
},
- // Converters API
- addConverter: function (converterFunctions) {
- $.extend(_converters, converterFunctions);
- },
- getConverter: function (name) {
- return _converters[name];
- },
- // Validators API
- addValidator: function (validatorFunctions) {
- $.extend(_validators, validatorFunctions);
- },
- getValidator: function (name) {
- return _validators[name];
- },
- validate: function (event, id, converter, validators) {
- var value;
- var element = rf.getDomElement(id);
- if (element.value) {
- value = element.value;
- } else {
- var component = rf.$(element);
- // TODO: add getValue to baseComponent and change jsdocs
- value = component && typeof component["getValue"] ==
"function" ? component.getValue() : "";
- }
+ validate: function (event, id, element, params) {
+ var value = __getValue(element || id);
+ var convertedValue;
+ var converter = params.c;
if (converter) {
try {
- converter.options.componentId = id;
- value = getConverter([converter.name])(value, converter.options);
+ if (converter.f)
+ convertedValue = converter.f(value,id,converter.p,converter.m);
} catch (e){
- sendMessage(id, e.message);
+ rf.csv.sendMessage(id, e);
return false;
}
+ } else {
+ convertedValue = value;
}
+ var validators = params.v;
if (validators) {
var validatorFunction;
try {
for (i=0;i<validators.length;i++) {
- validatorFunction = getValidator(validators[i].type);
+ validatorFunction = validators[i].f;
if (validatorFunction) {
- validatorFunction(id, value, validators[i]);
+ validatorFunction(convertedValue,id, validators[i].p,validators[i].m);
}
}
} catch (e) {
- sendMessage(id, result);
+ rf.csv.sendMessage(id, e);
return false;
}
}
+ if(!params.da && params.a){
+ params.a.call(element,event,id);
+ } else {
+ rf.csv.sendMessage(id, "");
+ }
return true;
},
- addFormValidators: function (formId, callValidatorFunctions) {
+ /*
+ function form_3Atext_3Av(clientId,element,event,disableAjax){var
value=RichFaces.csv.getValue(clientId,element);
+ try {
+ var convertedValue=value;
+ RichFaces.csv.validateLength(convertedValue,{"detail":"{2}: Validation
Error: Specified attribute is not between the expected values of {0} and
{1}.","severity":0,"summary":"{2}: Validation Error:
Specified attribute is not between the expected values of {0} and {1}."}
,{"minimum":1,"maximum":3} );
+ if(!disableAjax){
+ RichFaces.csv.clearMessage(clientId);
+ }
+ return true;
+ } catch(e) {
+ RichFaces.csv.sendMessage(clientId,e);
+ return false;
+ }}
+ */
+ /*
+ * c: {name:, params:}
+ v: [{f:, customMessage:, [validator params]}]
+ function form_3Atext_3Av(id, el, e, c, v, p) {
+ RichFaces.csv.validate(e, id, el, c, v, p);
+ }
+ */
+ });
+
+ /*
+ * Converters implementation
+ */
+ $.extend(rf.csv, {
+ "convertBoolean": function (value,label,params,msg) {
+ var result; value = $.trim(value).toLowerCase();
+ result = value=='true' ? true : value.length<1 ? null : false;
+ return result;
+ },
+ "convertByte": function (value,label,params,msg) {
+ var result; value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-128 ||
result>127) {
+ throw rf.csv.interpolateMessage(msg, [value, 254, label]);
+ }
+ return result;
+ },
+ "convertNumber": function (value,label,params,msg) {
+ var result; value=$.trim(value);
+ result = parseFloat(value);
+ if (isNaN(result)) {
+ throw rf.csv.interpolateMessage(msg, [value, 99, label]);
+ }
+ return result;
+ },
+ "convertShort": function (value,label,params,msg) {
+ var result; value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-32768 ||
result>32767) {
+ throw rf.csv.interpolateMessage(msg, [value, 32456, label]);
+ }
+ return result;
}
});
+ var validateRange = function(value,label,params,msg) {
+ var isMinSet = typeof params.minimum == "number" ;//&& params.minimum
>0;
+ var isMaxSet = typeof params.maximum == "number" ;//&& params.maximum
>0;
+
+ if (isMaxSet && value > params.maximum) {
+ throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
+ }
+ if (isMinSet && value < params.minimum) {
+ throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.minimum,params.maximum,label]:[params.minimum,label]);
+ }
+ };
+
+ var validateRegex = function(value,label,pattern,msg) {
+ if (typeof pattern != "string" || pattern.length == 0) {
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
+ }
+
+ var re;
+ try {
+ re = new RegExp(pattern);
+ } catch (e) {
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
+ }
+ if (!re.test(value)){
+ throw rf.csv.interpolateMessage(msg, [pattern,label]);
+ }
+
+ }
+ /*
+ * Validators implementation
+ */
+ $.extend(rf.csv, {
+ "validateLongRange": function (value,label,params,msg) {
+ var type = typeof value;
+ if (type != "number") {
+ if (type != "string") {
+ throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_TYPE', [componentId,
""]);
+ } else {
+ value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (value = parseInt(value, 10))==NaN) {
+ throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_TYPE', [componentId,
""]);
+ }
+ }
+ }
+
+ validateRange(value,label,params,msg);
+ },
+ "validateDoubleRange": function (value,label,params,msg) {
+ var type = typeof value;
+ if (type != "number") {
+ if (type != "string") {
+ throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_TYPE', [componentId,
""]);
+ } else {
+ value = $.trim(value);
+ if (!rf.csv.RE_FLOAT.test(value) || (value = parseFloat(value))==NaN) {
+ throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_TYPE', [componentId,
""]);
+ }
+ }
+ }
+
+ validateRange(value,label,params,msg);
+ },
+ "validateLength": function (value,label,params,msg) {
+ var length = value?value.length:0;
+ validateRange(length,label,params,msg);
+ },
+ "validateSize": function (value,label,params,msg) {
+ var length = value?value.length:0;
+ validateRange(length,label,{maximum:params.max,minimum:params.min},msg);
+ },
+ "validateRegex": function (value,label,params,msg) {
+ validateRegex(value,label,params.pattern,msg);
+ },
+ "validatePattern": function (value,label,params,msg) {
+ validateRegex(value,label,params.regexp,msg);
+ },
+ "validateRequired": function (value,label,params,msg) {
+ if (!value ) {
+ throw rf.csv.interpolateMessage(msg, [label]);
+ }
+ },
+ "validateMax": function (value,label,params,msg) {
+ if (value > params.value ) {
+ throw msg;
+ }
+ },
+ "validateMin": function (value,label,params,msg) {
+ if (value < params.value ) {
+ throw msg;
+ }
+ }
+ });
+
})(jQuery, window.RichFaces || (window.RichFaces={}));
\ No newline at end of file
Copied:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js
(from rev 20994,
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js)
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js
(rev 0)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,77 @@
+(function($, rf) {
+
+ rf.ui = rf.ui || {};
+
+ // Constructor definition
+ rf.ui.Base = function(componentId, options, defaultOptions) {
+ this.namespace = "."+rf.Event.createNamespace(this.name, componentId);
+ // call constructor of parent class
+ $super.constructor.call(this, componentId);
+ this.options = $.extend(this.options, defaultOptions, options);
+ this.attachToDom();
+ this.__bindEventHandlers();
+ };
+
+ // Extend component class and add protected methods from parent class to our container
+ rf.BaseComponent.extend(rf.ui.Base);
+
+ // define super class link
+ var $super = rf.ui.Base.$super;
+
+ $.extend(rf.ui.Base.prototype, {
+ __bindEventHandlers: function () {
+ },
+ destroy: function () {
+ rf.Event.unbindById(this.id, this.namespace);
+ $super.destroy.call(this);
+ }
+ });
+
+})(jQuery, window.RichFaces || (window.RichFaces={}));
+
+(function($, rf) {
+
+ // Constructor definition
+ rf.ui.Message = function(componentId, options) {
+ // call constructor of parent class
+ $super.constructor.call(this, componentId, options, defaultOptions);
+ };
+
+ // Extend component class and add protected methods from parent class to our container
+ rf.ui.Base.extend(rf.ui.Message);
+
+ // define super class link
+ var $super = rf.ui.Message.$super;
+
+ var defaultOptions = {
+
+ };
+
+ var componentHash = {};
+ var componentIndex = 0;
+
+ var onMessage = function (event, element, data) {
+ if (!this.options.forComponentId) {
+ var index = componentHash[data.sourceId];
+ if (typeof index != undefined) {
+ $(rf.getDomElement(this.id+index)).remove();
+ }
+ var content = content = $(rf.getDomElement(this.id));
+
+ componentIndex ++;
+ if (data.message) content.append('<li
id="'+this.id+componentIndex+'">'+data.message.summary+'</li>');
+ componentHash[data.sourceId] = componentIndex;
+
+ } else if (this.options.forComponentId==data.sourceId) {
+ rf.getDomElement(this.id).innerHTML = data.message ?
'<li>'+data.message.summary+'</li>' : '';
+ }
+ }
+
+ $.extend(rf.ui.Message.prototype, {
+ name: "Message",
+ __bindEventHandlers: function () {
+ rf.Event.bind(window.document, rf.Event.MESSAGE_EVENT_TYPE+this.namespace, onMessage,
this);
+ }
+ });
+
+})(jQuery, window.RichFaces || (window.RichFaces={}));
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/csv.library.properties 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1 +1 @@
-resources=jquery.js, richfaces.js, richfaces-event.js, org.richfaces:csv.js
\ No newline at end of file
+resources=jquery.js, richfaces.js, richfaces-event.js, org.richfaces:richfaces-csv.js
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1 +1 @@
-resources=jquery.js, richfaces.js, richfaces-event.js, richfaces-base-component.js,
org.richfaces:message.js
\ No newline at end of file
+resources=jquery.js, richfaces.js, richfaces-event.js, richfaces-base-component.js,
org.richfaces:richfaces-message.js
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1,9 +1,14 @@
package org.richfaces.javascript.client;
+import static org.easymock.EasyMock.*;
+
+import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import org.jboss.test.faces.mock.MockFacesEnvironment;
import org.jboss.test.qunit.Qunit;
@@ -20,6 +25,8 @@
@RunWith(Parameterized.class)
public abstract class MockTestBase {
+ protected static final String TEST_COMPONENT_ID = "testComponent";
+
@Rule
public final Qunit qunit;
@@ -41,8 +48,11 @@
}
protected void recordMocks() {
- // template method to record mock objects
-
+ UIViewRoot viewRoot = facesEnvironment.createMock(UIViewRoot.class);
+ expect(viewRoot.getLocale()).andStubReturn(Locale.ENGLISH);
+
expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(viewRoot);
+ expect(component.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
+
expect(component.getClientId(facesEnvironment.getFacesContext())).andStubReturn(TEST_COMPONENT_ID);
}
@After
@@ -62,11 +72,16 @@
protected org.jboss.test.qunit.Qunit.Builder createQunitPage() {
return
Qunit.builder().loadJsfResource("jquery.js").loadJsfResource("richfaces.js")
-
.loadJsfResource("richfaces-event.js").loadJsfResource("csv.js",
"org.richfaces");
+
.loadJsfResource("richfaces-event.js").loadJsfResource("richfaces-csv.js",
"org.richfaces");
}
protected abstract String getJavaScriptFunctionName();
+ protected Map<String, Object> getOptions() {
+ Map<String, Object> options = criteria.getOptions();
+ return options;
+ }
+
protected static List<RunParameters[]> options(RunParameters ...criterias){
Builder<RunParameters[]> builder = ImmutableList.builder();
for (RunParameters testCriteria : criterias) {
@@ -87,12 +102,17 @@
}
protected static RunParameters pass(Object value, String option1, Object value1,
String option2, Object value2) {
- RunParameters testCriteria = pass(value);
+ RunParameters testCriteria = pass(value,option1, value1);
Map<String, Object> options = testCriteria.getOptions();
- options.put(option1, value1);
options.put(option2, value2);
return testCriteria;
}
+ protected static RunParameters pass(Object value, String option1, Object value1,
String option2, Object value2,String option3, Object value3) {
+ RunParameters testCriteria = pass(value,option1, value1,option2, value2);
+ Map<String, Object> options = testCriteria.getOptions();
+ options.put(option3, value3);
+ return testCriteria;
+ }
private static RunParameters[] optionsArray(RunParameters testCriteria) {
return new RunParameters[] { testCriteria };
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,45 @@
+package org.richfaces.javascript.client.converter;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.faces.convert.BooleanConverter;
+import javax.faces.convert.ByteConverter;
+import javax.faces.convert.Converter;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+public class ByteConverterTest extends ConverterTestBase {
+
+ public ByteConverterTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Override
+ protected Converter createConverter() {
+ ByteConverter byteConverter = new ByteConverter();
+ return byteConverter;
+ }
+
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "convertByte";
+ }
+
+ @Override
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ assertTrue(jsConvertedValue instanceof Double);
+ assertTrue(convertedValue instanceof Byte);
+ Double jsDouble = (Double) jsConvertedValue;
+ Double jsfDouble = new Double((Byte)convertedValue);
+ assertEquals(jsfDouble, jsDouble,0.0000001);
+ }
+
+ @Parameters
+ public static List<RunParameters[]> getRunParameterss() {
+ return options(pass("true"), pass("ok"),
pass("123"),pass("0"),pass("1"),pass("255"),pass("-128"),pass("-129"),pass("256"),pass("-0"),pass("0.05"));
+ }
+}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -1,16 +1,27 @@
package org.richfaces.javascript.client.converter;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.*;
+import javax.faces.application.FacesMessage;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
+import javax.faces.validator.Validator;
+import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
+import net.sourceforge.htmlunit.corejs.javascript.NativeObject;
+
import org.ajax4jsf.javascript.JSFunction;
import org.junit.Test;
+import org.richfaces.javascript.Message;
import org.richfaces.javascript.client.MockTestBase;
import org.richfaces.javascript.client.RunParameters;
+import org.richfaces.validator.ConverterServiceImpl;
+import com.gargoylesoftware.htmlunit.ScriptException;
+
public abstract class ConverterTestBase extends MockTestBase {
public ConverterTestBase(RunParameters criteria) {
@@ -24,24 +35,49 @@
Object convertedValue =
converter.getAsObject(facesEnvironment.getFacesContext(), component,
criteria.getValue().toString());
Object jsConvertedValue =
- convertOnClient();
- assertEquals(convertedValue, jsConvertedValue);
+ convertOnClient(converter);
+ if(null != convertedValue || null != jsConvertedValue){
+ compareResult(convertedValue, jsConvertedValue);
+ }
} catch (ConverterException e) {
// JSF conversion error - JavaScript should throw exception too.
try {
- convertOnClient();
+ convertOnClient(converter);
assertFalse("Client-side converted didn't throw exception for
value:"+criteria.getValue(), true);
- } catch (Exception jsException){
+ } catch (ScriptException jsException){
// Test passed
+ Throwable cause = jsException.getCause();
+ assertTrue(cause instanceof JavaScriptException);
+ NativeObject value = (NativeObject) ((JavaScriptException)
cause).getValue();
+ assertEquals(e.getFacesMessage().getDetail(),
value.get("detail"));
+ assertEquals(e.getFacesMessage().getSummary(),
value.get("summary"));
}
}
}
- protected Object convertOnClient() throws ConverterException {
- JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),criteria.getValue(),getErrorMessage(),getJavaScriptOptions());
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ assertEquals(convertedValue, jsConvertedValue);
+ }
+
+ protected Object convertOnClient(Converter converter) throws ConverterException {
+ JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),criteria.getValue(),TEST_COMPONENT_ID,getJavaScriptOptions(),
getErrorMessage(converter));
return qunit.runScript(clientSideFunction.toScript());
}
+ private Object getErrorMessage(Converter converter) {
+ ConverterServiceImpl converterService = new ConverterServiceImpl();
+ FacesMessage message =
converterService.getMessage(facesEnvironment.getFacesContext(), converter);
+ return new Message(message);
+ }
+
protected abstract Converter createConverter();
+ protected void compareNumbers(Object convertedValue, Object jsConvertedValue) {
+ assertTrue(jsConvertedValue instanceof Double);
+ assertTrue(convertedValue instanceof Number);
+ Double jsDouble = (Double) jsConvertedValue;
+ Double jsfDouble = Double.valueOf(((Number)convertedValue).doubleValue());
+ assertEquals(jsfDouble, jsDouble,0.0000001);
+ }
+
}
\ No newline at end of file
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,46 @@
+package org.richfaces.javascript.client.converter;
+
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.convert.BooleanConverter;
+import javax.faces.convert.NumberConverter;
+import javax.faces.convert.Converter;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+public class NumberConverterTest extends ConverterTestBase {
+
+ private static final String TYPE = "type";
+
+ public NumberConverterTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Override
+ protected Converter createConverter() {
+ NumberConverter converter = new NumberConverter();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(TYPE)){
+ converter.setType((String) options.get(TYPE));
+ }
+ return converter;
+ }
+
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "convertNumber";
+ }
+
+ @Override
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ compareNumbers(convertedValue, jsConvertedValue);
+ }
+
+ @Parameters
+ public static List<RunParameters[]> getRunParameterss() {
+ return options(pass("true"),
pass("123"),pass("0"),pass("1"),pass("255"),pass("-128"),pass("-129"),pass("256"),pass("-0"),pass("0.05"));
+ }
+}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,41 @@
+package org.richfaces.javascript.client.converter;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.faces.convert.BooleanConverter;
+import javax.faces.convert.ShortConverter;
+import javax.faces.convert.Converter;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+public class ShortConverterTest extends ConverterTestBase {
+
+ public ShortConverterTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Override
+ protected Converter createConverter() {
+ ShortConverter byteConverter = new ShortConverter();
+ return byteConverter;
+ }
+
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "convertShort";
+ }
+
+ @Override
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ compareNumbers(convertedValue, jsConvertedValue);
+ }
+
+ @Parameters
+ public static List<RunParameters[]> getRunParameterss() {
+ return options(pass("true"),
pass("123"),pass("0"),pass("1"),pass(Long.toString(Long.MAX_VALUE)),pass(Short.toString(Short.MIN_VALUE)),pass(Short.toString(Short.MAX_VALUE)),pass("-129"),pass("256"),pass("-0"),pass("0.05"));
+ }
+}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,56 @@
+package org.richfaces.javascript.client.validator;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.junit.Test;
+import org.richfaces.javascript.client.MockTestBase;
+import org.richfaces.javascript.client.RunParameters;
+
+import com.gargoylesoftware.htmlunit.ScriptException;
+
+public abstract class BeanValidatorTestBase extends MockTestBase {
+
+ protected static final String PROP = "property";
+
+ public BeanValidatorTestBase(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Test
+ public void testValidator() throws Exception {
+ Validator validator = createValidator();
+ Set<?> constrains = validator.validateValue(getBeanType(), (String)
getOptions()
+ .get(PROP), criteria.getValue());
+ try {
+ validateOnClient(validator);
+ assertTrue("Bean validator found error for value: " +
criteria.getValue() + ", validator options: "
+ + getOptions(), constrains.isEmpty());
+ } catch (ScriptException e2) {
+ // both methods throws exceptions - it's ok.
+ Throwable cause = e2.getCause();
+ assertTrue(cause instanceof JavaScriptException);
+ }
+ }
+
+ protected abstract Class<?> getBeanType();
+
+ protected Object validateOnClient(Validator validator) throws ValidationException {
+ JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),
+ criteria.getValue(), TEST_COMPONENT_ID, getJavaScriptOptions(),
getErrorMessage());
+ return qunit.runScript(clientSideFunction.toScript());
+ }
+
+ protected Validator createValidator() {
+ return Validation.buildDefaultValidatorFactory().usingContext().getValidator();
+ }
+
+}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.DoubleRangeValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class DoubleRangeValidatorTest extends ValidatorTestBase {
+
+ private static final String MINIMUM = "minimum";
+ private static final String MAXIMUM = "maximum";
+ /**
+ * @param criteria
+ */
+ public DoubleRangeValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ DoubleRangeValidator validator = new DoubleRangeValidator();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(MINIMUM)){
+ validator.setMinimum((Double) options.get(MINIMUM));
+ }
+ if(options.containsKey(MAXIMUM)){
+ validator.setMaximum((Double) options.get(MAXIMUM));
+ }
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateDoubleRange";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(0L),pass(3L),pass(Double.MAX_VALUE),
+
pass(0.0D,MINIMUM,2.0D,IGNORE_MESSAGE,true),pass(2.0D,MINIMUM,2.0D),pass(3.0D,MINIMUM,2.0D),pass(-3.0D,MINIMUM,2.0D,IGNORE_MESSAGE,true),
+
pass(0.0D,MAXIMUM,2.0D),pass(2.0D,MAXIMUM,2.0D),pass(3.0D,MAXIMUM,2.0D,IGNORE_MESSAGE,true),pass(-3.0D,MAXIMUM,2.0D),
+
pass(0.0D,MINIMUM,3.0D,MAXIMUM,5.0D,IGNORE_MESSAGE,true),pass(3.0D,MINIMUM,3.0D,MAXIMUM,5.0D),pass(4.0D,MINIMUM,3.0D,MAXIMUM,5.0D),pass(7.0D,MINIMUM,3.0D,MAXIMUM,5.0D,IGNORE_MESSAGE,true));
+ }
+}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -33,7 +33,7 @@
@Override
protected Validator createValidator() {
LengthValidator validator = new LengthValidator();
- Map<String, Object> options = criteria.getOptions();
+ Map<String, Object> options = getOptions();
if(options.containsKey(MINIMUM)){
validator.setMinimum((Integer) options.get(MINIMUM));
}
@@ -56,6 +56,6 @@
return options(pass(""),pass("aaa"),pass("123"),
pass("",MINIMUM,2),pass("vv",MINIMUM,2),pass("vvv",MINIMUM,2),
pass("",MAXIMUM,2),pass("vv",MAXIMUM,2),pass("123",MAXIMUM,2),
-
pass("",MINIMUM,3,MAXIMUM,5),pass("ddd",MINIMUM,3,MAXIMUM,5),pass("dddd",MINIMUM,3,MAXIMUM,5),pass("abcdefg",MINIMUM,3,MAXIMUM,5));
+
pass("",MINIMUM,3,MAXIMUM,5,IGNORE_MESSAGE,true),pass("ddd",MINIMUM,3,MAXIMUM,5),pass("dddd",MINIMUM,3,MAXIMUM,5),pass("abcdefg",MINIMUM,3,MAXIMUM,5,IGNORE_MESSAGE,true));
}
}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.LongRangeValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class LongRangeValidatorTest extends ValidatorTestBase {
+
+ private static final String MINIMUM = "minimum";
+ private static final String MAXIMUM = "maximum";
+ /**
+ * @param criteria
+ */
+ public LongRangeValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ LongRangeValidator validator = new LongRangeValidator();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(MINIMUM)){
+ validator.setMinimum((Long) options.get(MINIMUM));
+ }
+ if(options.containsKey(MAXIMUM)){
+ validator.setMaximum((Long) options.get(MAXIMUM));
+ }
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateLongRange";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(0L),pass(3L),pass(Long.MAX_VALUE),
+
pass(0L,MINIMUM,2L),pass(2L,MINIMUM,2L),pass(3L,MINIMUM,2L),pass(-3L,MINIMUM,2L),
+
pass(0L,MAXIMUM,2L),pass(2L,MAXIMUM,2L),pass(3L,MAXIMUM,2L),pass(-3L,MAXIMUM,2L),
+
pass(0L,MINIMUM,3L,MAXIMUM,5L),pass(3L,MINIMUM,3L,MAXIMUM,5L),pass(4L,MINIMUM,3L,MAXIMUM,5L),pass(7L,MINIMUM,3L,MAXIMUM,5L));
+ }
+}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.LengthValidator;
+import javax.faces.validator.Validator;
+import javax.validation.constraints.Max;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MaxValidatorTest extends BeanValidatorTestBase {
+
+ private static final String MAXIMUM = "value";
+ /**
+ * @param criteria
+ */
+ public MaxValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateMax";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(
+
pass(0,PROP,"number",MAXIMUM,2),pass(2,PROP,"number",MAXIMUM,2),pass(123,PROP,"number",MAXIMUM,2)
+ );
+ }
+
+ public static final class Bean {
+
+ @Max(2)
+ public int getNumber() {
+ return 0;
+ }
+
+ }
+
+ @Override
+ protected Class<?> getBeanType() {
+ return Bean.class;
+ }
+}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,56 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.RegexValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class RegexValidatorTest extends ValidatorTestBase {
+
+ private static final String PATTERN = "pattern";
+ /**
+ * @param criteria
+ */
+ public RegexValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ RegexValidator validator = new RegexValidator();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(PATTERN)){
+ validator.setPattern((String) options.get(PATTERN));
+ }
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateRegex";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return
options(/*pass(""),pass("aaa"),pass("123"),*/
+
pass("",PATTERN,".*"),pass("vv",PATTERN,"\\S*"),pass("123",PATTERN,"\\d+")
+ );
+ }
+}
Copied:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
(from rev 21134,
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java)
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
(rev 0)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -0,0 +1,52 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.RequiredValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class RequiredValidatorTest extends ValidatorTestBase {
+
+ /**
+ * @param criteria
+ */
+ public RequiredValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ RequiredValidator validator = new RequiredValidator();
+ Map<String, Object> options = getOptions();
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateRequired";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(""),pass("aaa"),pass("123"),
+ pass(null)
+ );
+ }
+}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -3,8 +3,7 @@
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
-import java.util.Collections;
-
+import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
@@ -17,13 +16,20 @@
import org.ajax4jsf.javascript.JSFunction;
import org.junit.Test;
+import org.richfaces.javascript.Message;
import org.richfaces.javascript.client.MockTestBase;
import org.richfaces.javascript.client.RunParameters;
+import org.richfaces.validator.FacesValidatorServiceImpl;
import com.gargoylesoftware.htmlunit.ScriptException;
public abstract class ValidatorTestBase extends MockTestBase {
+ /**
+ * <p class="changed_added_4_0">TODO remove to check all
messages.</p>
+ * @deprecated Remove this option then all messages will be passed properly.
+ */
+ public static final String IGNORE_MESSAGE = "ignoreMessage";
private static final Converter NUMBER_CONVERTER = new Converter() {
public String getAsString(FacesContext context, UIComponent component, Object
value) {
@@ -35,7 +41,6 @@
return Double.valueOf(value);
}
};
-
public ValidatorTestBase(RunParameters criteria) {
super(criteria);
}
@@ -45,38 +50,45 @@
Validator validator = createValidator();
try {
validator.validate(facesEnvironment.getFacesContext(), component,
criteria.getValue());
- validateOnClient();
+ validateOnClient(validator);
} catch (ValidatorException e) {
// client-side script has to throw exception too.
try {
- validateOnClient();
- assertFalse("JSF validator throws exception for value: " +
criteria.getValue(), true);
+ validateOnClient(validator);
+ assertFalse("JSF validator throws exception for value: " +
criteria.getValue()
+ + ", validator options: " + getOptions(), true);
} catch (ScriptException e2) {
// both methods throws exceptions - it's ok.
- e2.printStackTrace();
Throwable cause = e2.getCause();
assertTrue(cause instanceof JavaScriptException);
- NativeObject value = (NativeObject) ((JavaScriptException)
cause).getValue();
- assertEquals(getErrorMessage().getDetail(),
value.get("detail"));
+ if (!getOptions().containsKey(IGNORE_MESSAGE)) {
+ NativeObject value = (NativeObject) ((JavaScriptException)
cause).getValue();
+ assertEquals(e.getFacesMessage().getDetail(),
value.get("detail"));
+ assertEquals(e.getFacesMessage().getSummary(),
value.get("summary"));
+ }
}
}
}
- protected Object validateOnClient() throws ValidationException {
+ protected Object validateOnClient(Validator validator) throws ValidationException {
JSFunction clientSideFunction =
- new JSFunction("RichFaces.csv." + getJavaScriptFunctionName(),
criteria.getValue(), getErrorMessage(),
- getJavaScriptOptions());
+ new JSFunction("RichFaces.csv." + getJavaScriptFunctionName(),
criteria.getValue(), TEST_COMPONENT_ID,
+ getJavaScriptOptions(), getErrorMessage(validator));
return qunit.runScript(clientSideFunction.toScript());
}
+ private Object getErrorMessage(Validator validator) {
+ FacesValidatorServiceImpl validatorService = new FacesValidatorServiceImpl();
+ FacesMessage message =
validatorService.getMessage(facesEnvironment.getFacesContext(), validator);
+ return new Message(message);
+ }
+
protected abstract Validator createValidator();
@Override
protected void recordMocks() {
super.recordMocks();
- expect(component.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
-
expect(component.getClientId(facesEnvironment.getFacesContext())).andStubReturn("testComponent");
expect(facesEnvironment.getApplication().createConverter("javax.faces.Number")).andStubReturn(NUMBER_CONVERTER);
}
-}
+}
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -10,7 +10,6 @@
import javax.faces.convert.NumberConverter;
import javax.faces.validator.RegexValidator;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
import org.jboss.test.faces.mock.Mock;
import org.jboss.test.faces.mock.MockTestRunner;
import org.junit.After;
@@ -62,7 +61,7 @@
expect(scriptService.getScript(environment.getFacesContext(),
RegexValidator.class)).andThrow(new ScriptNotFoundException());
controller.replay();
- Collection<? extends ScriptWithDependencies> clientSideValidatorScript =
renderer.getClientSideValidatorScript(
+ Collection<? extends LibraryScriptFunction> clientSideValidatorScript =
renderer.getClientSideValidatorScript(
environment.getFacesContext(), descriptors);
assertTrue(clientSideValidatorScript.isEmpty());
controller.verify();
@@ -87,11 +86,10 @@
expect(script.getName()).andReturn(REGEX_VALIDATOR).atLeastOnce();
expect(script.getResources()).andReturn(CLIENT_VALIDATOR_LIBRARY);
controller.replay();
- Collection<? extends ScriptWithDependencies> clientSideScripts =
renderer.getClientSideValidatorScript(environment.getFacesContext(), descriptors);
+ Collection<? extends LibraryScriptFunction> clientSideScripts =
renderer.getClientSideValidatorScript(environment.getFacesContext(), descriptors);
LibraryScriptFunction clientSideScript = (LibraryScriptFunction)
Iterables.getOnlyElement(clientSideScripts);
- assertEquals(ClientValidatorRenderer.CONVERTED_VALUE_LITERAL,
clientSideScript.getParameters().get(0));
- assertEquals(VALIDATOR_MESSAGE, clientSideScript.getParameters().get(1));
- assertEquals(VALIDATOR_PARAMS, clientSideScript.getParameters().get(2));
+ assertEquals(VALIDATOR_MESSAGE, clientSideScript.getMessage());
+ assertEquals(VALIDATOR_PARAMS, clientSideScript.getParameters());
assertEquals(CLIENT_VALIDATOR_LIBRARY, clientSideScript.getResources());
controller.verify();
}
@@ -108,9 +106,8 @@
controller.replay();
LibraryScriptFunction clientSideScript =
(LibraryScriptFunction)
renderer.getClientSideConverterScript(environment.getFacesContext(),
converterDescriptor);
- assertEquals(ClientValidatorRenderer.VALUE_LITERAL,
clientSideScript.getParameters().get(0));
- assertEquals(VALIDATOR_MESSAGE, clientSideScript.getParameters().get(1));
- assertEquals(VALIDATOR_PARAMS, clientSideScript.getParameters().get(2));
+ assertEquals(VALIDATOR_MESSAGE, clientSideScript.getMessage());
+ assertEquals(VALIDATOR_PARAMS, clientSideScript.getParameters());
assertEquals(CLIENT_VALIDATOR_LIBRARY, clientSideScript.getResources());
controller.verify();
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2011-01-20
23:59:35 UTC (rev 21135)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2011-01-21
00:29:53 UTC (rev 21136)
@@ -9,15 +9,12 @@
import java.util.Collection;
import java.util.Map;
-import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.NumberConverter;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
-import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -26,6 +23,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.javascript.LibraryFunction;
+import org.richfaces.javascript.Message;
import org.richfaces.javascript.ScriptNotFoundException;
import org.richfaces.resource.ResourceKey;
import org.richfaces.validator.ConverterDescriptor;
@@ -200,14 +198,15 @@
}
private LibraryScriptFunction createValidatorFunction() {
- return createFunction(REGEX_VALIDATOR,
ClientValidatorRenderer.CONVERTED_VALUE_VAR, FACES_VALIDATOR_MESSAGE);
+ return createFunction(REGEX_VALIDATOR, VALIDATOR_MESSAGE);
}
private LibraryScriptFunction createConverterFunction() {
- return createFunction(NUMBER_CONVERTER, ClientValidatorRenderer.VALUE_VAR,
FACES_VALIDATOR_MESSAGE);
+ return createFunction(NUMBER_CONVERTER, VALIDATOR_MESSAGE);
}
- private LibraryScriptFunction createFunction(final String name, String var,
FacesMessage validatorMessage) {
+
+ private LibraryScriptFunction createFunction(final String name, Message
validatorMessage) {
LibraryFunction libraryScript = new LibraryFunction() {
@@ -220,7 +219,7 @@
return CLIENT_VALIDATOR_LIBRARY;
}
};
- return new LibraryScriptFunction(libraryScript, new JSReference(var),
validatorMessage, VALIDATOR_PARAMS);
+ return new LibraryScriptFunction(libraryScript, validatorMessage,
VALIDATOR_PARAMS);
}
private ClientValidatorRenderer createStubRenderer(final LibraryScriptFunction
converterFunction,
@@ -238,7 +237,7 @@
}
@Override
- Collection<? extends ScriptWithDependencies>
getClientSideValidatorScript(FacesContext facesContext,
+ Collection<? extends LibraryScriptFunction>
getClientSideValidatorScript(FacesContext facesContext,
Collection<ValidatorDescriptor> validators) {
return Lists.newArrayList(validatorFunctions);
}