Author: alexsmirnov
Date: 2010-10-05 19:51:40 -0400 (Tue, 05 Oct 2010)
New Revision: 19459
Added:
branches/RF-8742/ui/validator/impl/src/test/java/org/
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ConverterNotFoundException.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageNotFoundException.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ValidatorDescriptor.java
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java
Log:
CODING IN PROGRESS - issue RF-9219: CSV: development tests for server side(junit)
https://jira.jboss.org/browse/RF-9219
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-10-05
20:33:34 UTC (rev 19458)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -1,52 +1,35 @@
-/*
- * $Id$
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
package org.richfaces.component.behavior;
-import javax.faces.FacesException;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.behavior.ClientBehaviorBase;
+import java.util.Collection;
+
+import javax.faces.component.UIMessage;
import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.convert.Converter;
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class ClientValidatorBehavior extends ClientBehaviorBase {
+public interface ClientValidatorBehavior {
- @Override
- public String getScript(ClientBehaviorContext behaviorContext) {
- if (!(behaviorContext.getComponent() instanceof EditableValueHolder)) {
- throw new FacesException("Invalid target for client-side validator
behavior");
- }
- return super.getScript(behaviorContext);
- }
/**
- * <p class="changed_added_4_0">This method looks up all {@link
UIMessage} components associated with input for which this behavior belongs to</p>
+ * <p class="changed_added_4_0">
+ * This method looks up all {@link UIMessage} components associated with input for
which this behavior belongs to
+ * </p>
+ *
* @param context
- * @return non-null collection of {@link UIMessage} components associated with terget
input.
+ * @return non-null collection of {@link UIMessage} components associated with target
input.
+ * @throws MessageNotFoundException
+ * if no {@link UIMessage} component points to target UIInput and no
UIMessages found on page.
*/
-// public Collection<UIMessage> findMessages(ClientBehaviorContext context) {
-//
-// }
-}
+ Collection<UIMessage> findMessages(ClientBehaviorContext context) throws
MessageNotFoundException;
+
+ /**
+ * <p class="changed_added_4_0">
+ * Look up for converter associated with target UIInput
+ * </p>
+ *
+ * @param context
+ * @return
+ */
+ Converter getConverter(ClientBehaviorContext context) throws
ConverterNotFoundException;
+
+ Collection<ValidatorDescriptor> getValidators(ClientBehaviorContext context);
+
+}
\ No newline at end of file
Copied:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
(from rev 19442,
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java)
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -0,0 +1,72 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component.behavior;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIMessage;
+import javax.faces.component.behavior.ClientBehaviorBase;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.convert.Converter;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ClientValidatorImpl extends ClientBehaviorBase implements
ClientValidatorBehavior {
+
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext) {
+ if (!(behaviorContext.getComponent() instanceof EditableValueHolder)) {
+ throw new FacesException("Invalid target for client-side validator
behavior");
+ }
+ return super.getScript(behaviorContext);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.component.behavior.ClientValidatorBehavior#findMessages(javax.faces.component.behavior.ClientBehaviorContext)
+ */
+ public Collection<UIMessage> findMessages(ClientBehaviorContext context) throws
MessageNotFoundException {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.component.behavior.ClientValidatorBehavior#getConverter(javax.faces.component.behavior.ClientBehaviorContext)
+ */
+ public Converter getConverter(ClientBehaviorContext context) throws
ConverterNotFoundException {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.component.behavior.ClientValidatorBehavior#getValidators(javax.faces.component.behavior.ClientBehaviorContext)
+ */
+ public Collection<ValidatorDescriptor> getValidators(ClientBehaviorContext
context) {
+ return Collections.emptySet();
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ConverterNotFoundException.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ConverterNotFoundException.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ConverterNotFoundException.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component.behavior;
+
+/**
+ * <p class="changed_added_4_0">This exception thrown if Client validator
cannot determine Converter associated with target UIComponent</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@SuppressWarnings("serial")
+public class ConverterNotFoundException extends Exception {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ */
+ public ConverterNotFoundException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ */
+ public ConverterNotFoundException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param cause
+ */
+ public ConverterNotFoundException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ * @param cause
+ */
+ public ConverterNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ConverterNotFoundException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageNotFoundException.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageNotFoundException.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageNotFoundException.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component.behavior;
+
+/**
+ * <p class="changed_added_4_0">This exception thrown if UIInput
component associated with client side validator has no appropriate UIMessage(s)</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@SuppressWarnings("serial")
+public class MessageNotFoundException extends Exception {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ */
+ public MessageNotFoundException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ */
+ public MessageNotFoundException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param cause
+ */
+ public MessageNotFoundException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ * @param cause
+ */
+ public MessageNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageNotFoundException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ValidatorDescriptor.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ValidatorDescriptor.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ValidatorDescriptor.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -0,0 +1,42 @@
+package org.richfaces.component.behavior;
+
+import java.util.Map;
+
+/**
+ * <p class="changed_added_4_0">
+ * Inmlementations of this interface describe JSF or JSR-303 validators. Because JSF
supports 2 types of validators,
+ * this interface unifies access to them.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface ValidatorDescriptor {
+
+ /**
+ * <p class="changed_added_4_0">
+ * Returns JSF {@link javax.faces.validator.Validator} implementation class or
JSR-303 annotation class.
+ * </p>
+ *
+ * @return
+ */
+ Class<?> getValidatorClass();
+
+ /**
+ * <p class="changed_added_4_0">
+ * Concrete validator parameters
+ * </p>
+ *
+ * @return non null map with validator instance parameters.
+ */
+ Map<String, Object> getValidatorParameters();
+
+ /**
+ * <p class="changed_added_4_0">
+ * Localized validator message
+ * </p>
+ *
+ * @return
+ */
+ String getMessage();
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ValidatorDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-10-05
20:33:34 UTC (rev 19458)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -3,6 +3,8 @@
//
// Imports
//
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.render.ClientBehaviorRenderer;
/**
@@ -16,4 +18,9 @@
super();
}
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
+ // TODO Auto-generated method stub
+ return super.getScript(behaviorContext, behavior);
+ }
}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java 2010-10-05
20:33:34 UTC (rev 19458)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java 2010-10-05
23:51:40 UTC (rev 19459)
@@ -37,31 +37,31 @@
@RunWith(MockTestRunner.class)
public class ClientValidatorBehaviorTest {
- private static final String CLIENT_VALIDATION_FUNCTION = "rf.csv.v";
-
private final class DummyConverter implements Converter {
public String getAsString(FacesContext context, UIComponent component, Object
value) {
return value.toString();
}
-
+
public Object getAsObject(FacesContext context, UIComponent component, String
value) {
return value;
}
}
+ private static final String CLIENT_VALIDATION_FUNCTION = "rf.csv.v";
+
private static final String FORM_ID = "formId";
private static final String INPUT_ID = "inputId";
private static final String MESSAGE_ID = "messageId";
+ @Stub
+ protected UIOutput output;
+
@Mock()
@Environment({Feature.APPLICATION})
protected MockFacesEnvironment environment;
- @Stub
- private UIOutput output;
-
@Mock
protected UIInput input;
@@ -75,11 +75,11 @@
protected MockUIMessage message;
@Mock
- private ClientBehaviorContext behaviorContext;
+ protected ClientBehaviorContext behaviorContext;
protected MockController controller;
- private ClientValidatorBehavior behavior;
+ protected ClientValidatorImpl behavior;
@Before
public void setUp() {
@@ -166,8 +166,8 @@
// root.getChildren().add(form);
}
- private ClientValidatorBehavior createBehavior() {
- return new ClientValidatorBehavior();
+ private ClientValidatorImpl createBehavior() {
+ return new ClientValidatorImpl();
}
@Test