Author: alexsmirnov
Date: 2011-01-13 20:03:54 -0500 (Thu, 13 Jan 2011)
New Revision: 21013
Modified:
branches/RF-9797/examples/validator-demo/pom.xml
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
Log:
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current wiki
document
https://issues.jboss.org/browse/RF-9797
Modified: branches/RF-9797/examples/validator-demo/pom.xml
===================================================================
--- branches/RF-9797/examples/validator-demo/pom.xml 2011-01-13 20:32:21 UTC (rev 21012)
+++ branches/RF-9797/examples/validator-demo/pom.xml 2011-01-14 01:03:54 UTC (rev 21013)
@@ -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:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -2,7 +2,6 @@
import java.util.Collection;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
import com.google.common.collect.Iterables;
@@ -14,8 +13,8 @@
final String ajaxScript;
- 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;
}
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -5,36 +5,34 @@
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
public class ClientOnlyScript extends ValidatorScriptBase {
- protected final ScriptWithDependencies converter;
- protected final Collection<? extends ScriptWithDependencies> validators;
+ protected final LibraryScriptFunction converter;
+ protected final Collection<? 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 = validatorScripts;
-
+ LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
+ if (null != converter) {
+ Iterables.addAll(resources, converter.getResources());
+ }
+ for (LibraryScriptFunction scriptString : validators) {
+ Iterables.addAll(resources, scriptString.getResources());
+ }
+ 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;
}
@@ -42,33 +40,19 @@
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);
- }
- 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}");*/
- JSFunction callValidator = new JSFunction("RichFaces.csv.validate",
- new JSReference("event"),
- new JSReference("id"),
- new JSReference("element"),
- new JSReference("c"),
- new JSReference("v"),
- new JSReference("p"));
+ /*
+ * 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); }
+ * 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}");
+ */
+ JSFunction callValidator =
+ new JSFunction("RichFaces.csv.validate", new
JSReference("event"), new JSReference("id"), new JSReference(
+ "element"), new JSReference("c"), new
JSReference("v"), new JSReference("p"));
body.append(callValidator);
return body;
}
@@ -80,7 +64,9 @@
body.append(EOL).append("}\n");
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -92,7 +78,9 @@
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -124,5 +112,4 @@
return true;
}
-
}
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -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);
+ 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) {
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:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -23,11 +23,13 @@
package org.richfaces.renderkit.html;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.ScriptWithDependencies;
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 +38,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 Object parameters;
- public LibraryScriptFunction(LibraryFunction libraryScript, Object... parameters) {
- super(libraryScript.getName(), parameters);
- this.resources = libraryScript.getResources();
+ public LibraryScriptFunction(LibraryFunction libraryScript, Message message, Object
parameters) {
+ this.message = message;
+ this.parameters = parameters;
+ this.resources = ImmutableSet.copyOf(libraryScript.getResources());
this.name = libraryScript.getName();
}
@@ -60,6 +65,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 Object getParameters() {
+ return this.parameters;
+ }
+
/*
* (non-Javadoc)
*
@@ -69,9 +94,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 +118,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:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -28,7 +28,7 @@
private boolean bodyProcessed = false;
public ValidatorScriptBase() {
- super(CLIENT_ID,EVENT,ELEMENT);
+ super(CLIENT_ID,ELEMENT,EVENT);
}
public void appendScript(Appendable target) throws IOException {
Modified:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -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:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2011-01-13
20:32:21 UTC (rev 21012)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2011-01-14
01:03:54 UTC (rev 21013)
@@ -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);
}