JBoss Rich Faces SVN: r19215 - in management/design-4x: collapsiblePanel and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: admitriev
Date: 2010-09-15 09:07:19 -0400 (Wed, 15 Sep 2010)
New Revision: 19215
Added:
management/design-4x/collapsiblePanel/
management/design-4x/collapsiblePanel/collapsiblePanel.html
Log:
Added: management/design-4x/collapsiblePanel/collapsiblePanel.html
===================================================================
--- management/design-4x/collapsiblePanel/collapsiblePanel.html (rev 0)
+++ management/design-4x/collapsiblePanel/collapsiblePanel.html 2010-09-15 13:07:19 UTC (rev 19215)
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
+
+<html>
+<head>
+ <title>Untitled</title>
+<style>
+
+.cp_container {width : 300px /*visible width*/; border : 1px solid #a6a6a6 /*panelBorderColor*/; border-bottom : 0px; background : #FFFFFF /*generalBackgroundColor*/;}
+.cp_label { border-bottom : 1px solid #a6a6a6 /*panelBorderColor*/; background : url(images/bg_header.png) /*from headerGradientColor to headerBackgroundColor, picture height 20px*/ repeat-x top left #C0D1E7 /*headerBackgroundColor*/; padding : 8px 10px 7px 10px;font-weight : bold /*headerWeightFont*/; color : #000000 /*headerTextColor*/; font-family : verdana /*headerFamilyFont*/; font-size : 11px /*headerSizeFont*/; cursor : pointer;}
+
+.cp_content_hidden {display : none;}
+.cp_content_scroller { border-bottom : 1px solid #a6a6a6 /*panelBorderColor*/; height : 100px/*visible collapsible panel height minus header height*/; overflow : auto; overflow-x : hidden;}
+.cp_content { padding : 10px; color : #000000 /*generalTextColor*/; font-family : verdana /*generalFamilyFont*/; font-size : 11px /*generalSizeFont*/;}
+.cp_arrow { float : right; border : 1px solid #a6a6a6 /*panelBorderColor*/; background : #527EB6 /*generalLinkColor*/}
+
+
+</style>
+</head>
+
+<body style="margin : 30px">
+
+ <div class="cp_container">
+ <div>
+ <div class="cp_label">
+ <img src="images/arrow_down.png" width="13" height="11" alt="" border="0" class="cp_arrow">
+ Level
+ </div>
+ <div class="cp_content_scroller cp_content_hidden ">
+ <div class="cp_content">
+ Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here.
+ </div>
+ </div>
+ </div>
+ </div>
+
+<br>
+
+ <div class="cp_container">
+ <div>
+ <div class="cp_label">
+ <img src="images/arrow_up.png" width="13" height="11" alt="" border="0" class="cp_arrow">
+ Level
+ </div>
+ <div class="cp_content_scroller">
+ <div class="cp_content">
+ Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here. Content will be here.
+ </div>
+ </div>
+ </div>
+ </div>
+
+
+
+
+
+</body>
+</html>
14 years, 3 months
JBoss Rich Faces SVN: r19214 - modules/tests/metamer/trunk/ftest.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-09-15 07:50:39 -0400 (Wed, 15 Sep 2010)
New Revision: 19214
Modified:
modules/tests/metamer/trunk/ftest/pom.xml
Log:
added support for choosing jsf.config and deployable.classifier based on profiles; ad-hoc changing jsf.config in jboss6x-snapshot configuration (RFPL-811)
Modified: modules/tests/metamer/trunk/ftest/pom.xml
===================================================================
--- modules/tests/metamer/trunk/ftest/pom.xml 2010-09-15 10:37:07 UTC (rev 19213)
+++ modules/tests/metamer/trunk/ftest/pom.xml 2010-09-15 11:50:39 UTC (rev 19214)
@@ -83,6 +83,7 @@
<deployable.version>4.0.0-SNAPSHOT</deployable.version>
<ftest.source.version>4.0.0-SNAPSHOT</ftest.source.version>
<testng.suite.xml>src/test/resources/testng.xml</testng.suite.xml>
+ <container.home>target/installs/${container.dir.deflatted}/${container.dir.unflatted}</container.home>
</properties>
<repositories>
@@ -311,6 +312,73 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>tomcat6x-mojarra</id>
+ <properties>
+ <deployable.classifier>mojarra</deployable.classifier>
+ </properties>
+ </profile>
+ <profile>
+ <id>tomcat6x-myfaces</id>
+ <properties>
+ <deployable.classifier>myfaces</deployable.classifier>
+ </properties>
+ </profile>
+ <profile>
+ <id>jboss6x-myfaces</id>
+ <properties>
+ <deployable.classifier>myfaces</deployable.classifier>
+ </properties>
+ </profile>
+ <profile>
+ <id>jboss6x-snapshot-mojarra</id>
+ <properties>
+ <deployable.classifier>jee6</deployable.classifier>
+ <jsf.config>Mojarra-2.0</jsf.config>
+ </properties>
+ </profile>
+ <profile>
+ <id>jboss6x-snapshot-myfaces</id>
+ <properties>
+ <deployable.classifier>jee6</deployable.classifier>
+ <jsf.config>MyFaces-2.0</jsf.config>
+ </properties>
+ </profile>
+ <profile>
+ <id>jboss6x-snapshot-rewrite-default-jsf-config</id>
+ <activation>
+ <property>
+ <name>containerId</name>
+ <value>jboss6x-snapshot</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.google.code.maven-replacer-plugin</groupId>
+ <artifactId>maven-replacer-plugin</artifactId>
+ <version>1.3.2</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ <configuration>
+ <file>${container.home}/server/${container.configuration}/deployers/jsf.deployer/META-INF/jsf-integration-deployer-jboss-beans.xml</file>
+ <regex>true</regex>
+ <regexFlags>
+ <regexFlag>MULTILINE</regexFlag>
+ </regexFlags>
+ <token><property name="defaultJSFConfig">\s*<value>[a-zA-Z0-9\.\-]+</value></token>
+ <value><property name="defaultJSFConfig"><value>${jsf.config}</value></value>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
<build>
14 years, 3 months
JBoss Rich Faces SVN: r19213 - branches/RF-9151.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-09-15 06:37:07 -0400 (Wed, 15 Sep 2010)
New Revision: 19213
Modified:
branches/RF-9151/
Log:
Initialized merge tracking via "svnmerge" with revisions "1-19211" from
https://svn.jboss.org/repos/richfaces/trunk
Property changes on: branches/RF-9151
___________________________________________________________________
Name: svnmerge-integrated
+ /trunk:1-19211
14 years, 3 months
JBoss Rich Faces SVN: r19212 - branches.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-09-15 06:27:17 -0400 (Wed, 15 Sep 2010)
New Revision: 19212
Added:
branches/RF-9151/
Log:
RF-9151 creation of dev branch
Copied: branches/RF-9151 (from rev 19211, trunk)
14 years, 3 months
JBoss Rich Faces SVN: r19211 - modules/tests/metamer/trunk/ftest.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-09-15 05:33:33 -0400 (Wed, 15 Sep 2010)
New Revision: 19211
Modified:
modules/tests/metamer/trunk/ftest/pom.xml
Log:
added profile jboss6x-snapshot (RFPL-811)
Modified: modules/tests/metamer/trunk/ftest/pom.xml
===================================================================
--- modules/tests/metamer/trunk/ftest/pom.xml 2010-09-15 07:58:13 UTC (rev 19210)
+++ modules/tests/metamer/trunk/ftest/pom.xml 2010-09-15 09:33:33 UTC (rev 19211)
@@ -256,6 +256,61 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>container-jboss6x</id>
+ <activation>
+ <property>
+ <name>containerId</name>
+ <value>jboss6x-snapshot</value>
+ </property>
+ </activation>
+ <properties>
+ <container.short.version>6.0.0-SNAPSHOT</container.short.version>
+ <container.version>6.0.0-SNAPSHOT</container.version>
+ <container.dir.deflatted>jboss-6.0.x</container.dir.deflatted>
+ <container.dir.unflatted>jboss-${container.version}</container.dir.unflatted>
+ <container.installer.url>http://hudson.qa.jboss.com/hudson/view/JBoss%20AS/job/JBoss-AS-6.0.x/last...</container.installer.url>
+ <container.dir>jboss-${container.version}</container.dir>
+ <container.configuration>default</container.configuration>
+ <container.configuration.home>${container.home}/server/${container.configuration}</container.configuration.home>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>undeploy-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>undeploy</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <container>
+ <containerId>jboss6x</containerId>
+ <append>false</append>
+ <timeout>${cargo.timeout.deploy}</timeout>
+ <zipUrlInstaller>
+ <url>${container.installer.url}</url>
+ <installDir>${project.build.directory}/installs</installDir>
+ </zipUrlInstaller>
+ </container>
+ <configuration>
+ <home>${container.home}/server/${container.configuration}</home>
+ <type>existing</type>
+ <properties>
+ <cargo.jboss.configuration>${container.configuration}</cargo.jboss.configuration>
+ <cargo.rmi.port>1099</cargo.rmi.port>
+ </properties>
+ </configuration>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
<build>
14 years, 3 months
JBoss Rich Faces SVN: r19210 - in modules/tests/metamer/trunk/application/src/main: webapp/components/richAutocomplete and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-09-15 03:58:13 -0400 (Wed, 15 Sep 2010)
New Revision: 19210
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichAutocompleteBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/autocomplete.xhtml
Log:
https://jira.jboss.org/browse/RFPL-669
* not testable attributes removed
* fixed typos
* added submit button to the page
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichAutocompleteBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichAutocompleteBean.java 2010-09-15 01:09:27 UTC (rev 19209)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichAutocompleteBean.java 2010-09-15 07:58:13 UTC (rev 19210)
@@ -63,13 +63,17 @@
logger.debug("initializing bean " + getClass().getName());
attributes = Attributes.getUIComponentAttributes(UIAutocomplete.class, getClass());
+ attributes.setAttribute("converterMessage", "converter message");
attributes.setAttribute("mode", "cachedAjax");
attributes.setAttribute("rendered", true);
+ attributes.setAttribute("tokens", ", ");
+ attributes.setAttribute("validatorMessage", "validator message");
-
attributes.remove("autocompleteMethod");
attributes.remove("converter");
+ attributes.remove("fetchValue");
attributes.remove("itemConverter");
+ attributes.remove("validator");
// these are hidden attributes
attributes.remove("autocompleteList");
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/autocomplete.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/autocomplete.xhtml 2010-09-15 01:09:27 UTC (rev 19209)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/autocomplete.xhtml 2010-09-15 07:58:13 UTC (rev 19210)
@@ -84,10 +84,9 @@
required="#{richAutocompleteBean.attributes['required'].value}"
requiredMessage="#{richAutocompleteBean.attributes['requiredMessage'].value}"
selectFirst="#{richAutocompleteBean.attributes['selectFirst'].value}"
- selectItemClass="#{richAutocompleteBean.attributes['selectItemClass'].value}"
+ selectedItemClass="#{richAutocompleteBean.attributes['selectedItemClass'].value}"
showButton="#{richAutocompleteBean.attributes['showButton'].value}"
tokens="#{richAutocompleteBean.attributes['tokens'].value}"
- validator="#{richAutocompleteBean.attributes['validator'].value}"
validatorMessage="#{richAutocompleteBean.attributes['validatorMessage'].value}"
value="#{richAutocompleteBean.attributes['value'].value}"
valueChangeListener="#{richAutocompleteBean.attributes['valueChangeListener'].value}"
@@ -100,6 +99,8 @@
</ui:remove>
</rich:autocomplete>
+ <h:commandButton id="sendButton" execute="@form" render="outputPanel,messages" value="Submit"/>
+
<br/><br/>
<a4j:outputPanel id="outputPanel" layout="block">
Your selection: <h:outputText id="output" value="#{richAutocompleteBean.attributes['value'].value}"/>
14 years, 3 months
JBoss Rich Faces SVN: r19209 - modules/docs/branches/M3_draft/Component_Reference/src/main/docbook/en-US.
by richfaces-svn-commits@lists.jboss.org
Author: SeanRogers
Date: 2010-09-14 21:09:27 -0400 (Tue, 14 Sep 2010)
New Revision: 19209
Modified:
modules/docs/branches/M3_draft/Component_Reference/src/main/docbook/en-US/chap-Component_Reference-Tables_and_grids.xml
Log:
Updated rich:dataGrid description (RF-9141)
Modified: modules/docs/branches/M3_draft/Component_Reference/src/main/docbook/en-US/chap-Component_Reference-Tables_and_grids.xml
===================================================================
--- modules/docs/branches/M3_draft/Component_Reference/src/main/docbook/en-US/chap-Component_Reference-Tables_and_grids.xml 2010-09-14 23:40:15 UTC (rev 19208)
+++ modules/docs/branches/M3_draft/Component_Reference/src/main/docbook/en-US/chap-Component_Reference-Tables_and_grids.xml 2010-09-15 01:09:27 UTC (rev 19209)
@@ -467,6 +467,9 @@
<para>
The <sgmltag><rich:dataGrid></sgmltag> component is used to arrange data objects in a grid. Values in the grid can be updated dynamically from the data model, and Ajax updates can be limited to specific rows. The component supports <literal>header</literal>, <literal>footer</literal>, and <literal>caption</literal> facets.
</para>
+ <para>
+ The <sgmltag><rich:dataGrid></sgmltag> component is similar in function to the JavaServer Faces <sgmltag><h:panelGrid></sgmltag> component. However, the <sgmltag><rich:dataGrid></sgmltag> component additionally allows iteration through the data model rather than just aligning child components in a grid layout.
+ </para>
<figure id="figu-Component_Reference-richdataGrid-The_richdataGrid_component">
<title>The <sgmltag><rich:dataGrid></sgmltag> component</title>
<mediaobject>
14 years, 3 months
JBoss Rich Faces SVN: r19208 - branches/RF-8742/ui/validator/ui/src/test/java.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-09-14 19:40:15 -0400 (Tue, 14 Sep 2010)
New Revision: 19208
Added:
branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java
Log:
https://jira.jboss.org/browse/RF-9219
Added: branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java 2010-09-14 23:40:15 UTC (rev 19208)
@@ -0,0 +1,112 @@
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIOutput;
+import javax.faces.component.behavior.ClientBehaviorContext;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockController;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.jboss.test.faces.mock.Stub;
+import org.jboss.test.faces.mock.Environment.Feature;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.component.ClientValidatorBehavior;
+
+
+/**
+ * <p class="changed_added_4_0">This class tests client validator behavior.
+ * as it described at https://community.jboss.org/wiki/ClientSideValidation # Server-side rendering algorithm</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class ClientValidatorBehaviorTest {
+
+ @Mock()
+ @Environment({Feature.APPLICATION})
+ protected MockFacesEnvironment environment;
+
+ @Stub
+ private UIOutput output;
+
+ @Mock
+ protected UIInput input;
+
+ @Mock
+ private ClientBehaviorContext behaviorContext;
+
+ protected MockController controller;
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm .1</p>
+ */
+ @Test(expected=FacesException.class)
+ public void testGetScriptForIllegalComponent() {
+ getScript(output);
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm .2</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetScriptWithoutMessageComponent() throws Exception {
+
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm .3 - determine client-side converter</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetClientConverter() throws Exception {
+
+ }
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm .3</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetScriptWithoutClientConverter() throws Exception {
+
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm .3</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetScriptWithClientConverter() throws Exception {
+
+ }
+
+ private String getScript(UIComponent component) {
+ ClientValidatorBehavior behavior = createBehavior();
+ controller.replay();
+ String script = behavior.getScript(setupBehaviorContext(component));
+ controller.verify();
+ return script;
+ }
+
+ private ClientBehaviorContext setupBehaviorContext(UIComponent component) {
+ expect(behaviorContext.getComponent()).andStubReturn(component);
+ expect(behaviorContext.getFacesContext()).andStubReturn(environment.getFacesContext());
+ return behaviorContext;
+ }
+
+ private ClientValidatorBehavior createBehavior() {
+ return new ClientValidatorBehavior();
+ }
+
+ @Test
+ public void testDecode() {
+ fail("Not yet implemented");
+ }
+
+}
14 years, 3 months
JBoss Rich Faces SVN: r19207 - in branches/RF-8742: ui/validator/api/src/main/java/org/richfaces/validator and 11 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-09-14 19:05:28 -0400 (Tue, 14 Sep 2010)
New Revision: 19207
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/NullValueValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java
branches/RF-8742/ui/validator/impl/src/main/resources/
branches/RF-8742/ui/validator/impl/src/main/resources/META-INF/
branches/RF-8742/ui/validator/impl/src/main/resources/META-INF/services/
branches/RF-8742/ui/validator/impl/src/main/resources/META-INF/services/org.richfaces.application.Module
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIRichMessages.java
branches/RF-8742/ui/validator/ui/src/test/resources/
Removed:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/
Modified:
branches/RF-8742/core/api/src/main/java/org/richfaces/el/util/CapturingELResolver.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
Log:
RESOLVED - issue RF-9214: CSV: create project in sandbox
https://jira.jboss.org/browse/RF-9214
Import BeanValidator code from 3.3
Modified: branches/RF-8742/core/api/src/main/java/org/richfaces/el/util/CapturingELResolver.java
===================================================================
--- branches/RF-8742/core/api/src/main/java/org/richfaces/el/util/CapturingELResolver.java 2010-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/core/api/src/main/java/org/richfaces/el/util/CapturingELResolver.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -30,7 +30,7 @@
* @author Nick Belaevski
* @since 3.3.0
*/
-class CapturingELResolver extends ELResolverWrapper {
+public class CapturingELResolver extends ELResolverWrapper {
private Object base;
private Object property;
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -0,0 +1,25 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * This interface should be implemented by the JSF {@link Validator} which able to
+ * validate entire graph.
+ * @author asmirnov
+ *
+ */
+public interface GraphValidator {
+
+ public Collection<String> validateGraph(FacesContext context, UIComponent component, Object value,
+ Set<String> profiles) throws ValidatorException ;
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/NullValueValidator.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/NullValueValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/NullValueValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import javax.faces.validator.Validator;
+
+/**
+ * Marker interface for validators that allows null-values to validate.
+ * @author asmirnov
+ *
+ */
+public interface NullValueValidator extends Validator {
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/NullValueValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -17,11 +17,9 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Application;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.component.ClonedObjectResolver;
import org.richfaces.el.ELContextWrapper;
@@ -33,31 +31,10 @@
protected static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters is not correct.";
private static final String LOCALE_IS_NOT_SET = "Locale is not set";
private static final String VIEW_ROOT_IS_NOT_INITIALIZED = "ViewRoot is not initialized";
- private static final Object MUTEX = new Object();
- private static final Log log = LogFactory.getLog(ObjectValidator.class);
protected final ObjectValidator parent;
- /**
- * Create BeanValidator instance. For a Junit tests only.
- *
- * @return
- */
- static ObjectValidator createInstance() {
- // TODO - get instance class name from a "META-INF/service"
- // If the Seam framework is active, org.jboss.seam.core.Validators
- // component should be used.
- ObjectValidator validator = null;
- try {
- validator = new BeanValidator();
- } catch (Throwable e){
- // JSR-303 is not avalable.
- log.warn("Validator implementations not found at classpath, default NullValidator will be used.");
- validator = new NullValidator();
- }
- return validator;
- }
ObjectValidator() {
this.parent = null;
@@ -74,21 +51,7 @@
* @return
*/
public static ObjectValidator getInstance(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- externalContext.getContext();
- ObjectValidator instance;
- // TODO - use properly synchronization mutex ?
- synchronized (MUTEX) {
- Map<String, Object> applicationMap = externalContext
- .getApplicationMap();
- instance = (ObjectValidator) applicationMap.get(VALIDATOR_PARAM);
- if (null == instance) {
- // Vaildator not initialized - create and store new instance.
- instance = createInstance();
- applicationMap.put(VALIDATOR_PARAM, instance);
- }
- }
- return instance;
+ return ServiceTracker.getService(context, ObjectValidator.class);
}
public abstract Collection<String> validateGraph(FacesContext context, Object value,
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -0,0 +1,61 @@
+/*
+ * $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.application;
+
+import org.richfaces.validator.BeanValidator;
+import org.richfaces.validator.NullValidator;
+import org.richfaces.validator.ObjectValidator;
+
+/**
+ * <p class="changed_added_4_0">This class initializes validator-related services</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ValidatorModule implements Module {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.application.Module#configure(org.richfaces.application.ServicesFactory)
+ */
+ public void configure(ServicesFactory factory) {
+ factory.setInstance(ObjectValidator.class, createInstance());
+
+ }
+ /**
+ * Create BeanValidator instance. For a Junit tests only.
+ *
+ * @return
+ */
+ static ObjectValidator createInstance() {
+ ObjectValidator validator = null;
+ try {
+ validator = new BeanValidator();
+ } catch (Throwable e){
+ // JSR-303 is not avalable.
+// log.warn("Validator implementations not found at classpath, default NullValidator will be used.");
+ validator = new NullValidator();
+ }
+ return validator;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -29,7 +29,7 @@
private final ValidatorFactory validatorFactory;
private ValidatorContext validatorContext;
- BeanValidator() {
+ public BeanValidator() {
// Enforce class to load
ValidatorFactory.class.getName();
// Check Factory, to avoid instantiation errors
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -30,14 +30,12 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
-
/**
* Implementation of the JSF validator to use with Bean Validation / Hibernate
* validator
@@ -45,7 +43,7 @@
* @author asmirnov
*
*/
-public class FacesBeanValidator implements NullValueValidator,Serializable, GraphValidator {
+public class FacesBeanValidator implements Serializable, Validator, GraphValidator {
/**
*
@@ -59,7 +57,7 @@
private ValueExpression profilesExpression = null;
- private Object profiles = null;
+ private Set<String> profiles = null;
/**
* @return the summary
*/
@@ -149,9 +147,9 @@
}
public Collection<String> validateGraph(FacesContext context, UIComponent component,
- Object value, Object profiles) throws ValidatorException {
+ Object value, Set<String> profiles) throws ValidatorException {
ObjectValidator beanValidator = ObjectValidator.getInstance(context);
- Collection<String> messages = beanValidator.validateGraph(context, value,AjaxRendererUtils.asSet(profiles));
+ Collection<String> messages = beanValidator.validateGraph(context, value,profiles);
return messages;
}
@@ -159,19 +157,19 @@
* @return the profiles
*/
public Set<String> getProfiles() {
- Object profiles;
+ Set<String> profiles;
if(null != profilesExpression){
- profiles = profilesExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ profiles = (Set<String>) profilesExpression.getValue(FacesContext.getCurrentInstance().getELContext());
}else {
profiles = this.profiles;
}
- return AjaxRendererUtils.asSet(profiles);
+ return profiles;
}
/**
* @param profiles the profiles to set
*/
- public void setProfiles(Object profiles) {
+ public void setProfiles(Set<String> profiles) {
this.profiles = profiles;
}
Added: branches/RF-8742/ui/validator/impl/src/main/resources/META-INF/services/org.richfaces.application.Module
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/resources/META-INF/services/org.richfaces.application.Module (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/resources/META-INF/services/org.richfaces.application.Module 2010-09-14 23:05:28 UTC (rev 19207)
@@ -0,0 +1 @@
+org.richfaces.application.ValidatorModule
\ No newline at end of file
Modified: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -26,8 +26,6 @@
import java.util.Iterator;
import java.util.Set;
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
@@ -42,14 +40,8 @@
import javax.faces.event.PhaseId;
import org.ajax4jsf.component.AjaxComponent;
-import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.component.AjaxSupport;
-import org.ajax4jsf.component.EventValueExpression;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.event.AjaxEvent;
-import org.ajax4jsf.event.AjaxListener;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
-import org.ajax4jsf.webapp.taglib.MethodExpressionAjaxListener;
import org.richfaces.event.ValidatorEvent;
/**
@@ -84,10 +76,10 @@
"Parent component must be an EditableValueHolder");
}
- if (null != getEvent()) {
- ValueExpression binding = new EventValueExpression(this);
- parent.setValueExpression(getEvent(), binding);
- }
+// if (null != getEvent()) {
+// ValueExpression binding = new EventValueExpression(this);
+// parent.setValueExpression(getEvent(), binding);
+// }
}
@Override
@@ -98,13 +90,6 @@
if (event instanceof ValidatorEvent) {
// ByPass UpdateModelValue
context.renderResponse();
- } else if (event instanceof AjaxEvent) {
- // TODO - find all UIMessages components for a parent UIInput.
- // for an ajaxSingle component, re-render only target message.
- AjaxContext ajaxContext = AjaxContext
- .getCurrentInstance(context);
- ajaxContext.setSubmittedRegionClientId(this
- .getClientId(context));
}
}
}
@@ -132,8 +117,8 @@
if (null != onsubmit) {
buildOnEvent.append(onsubmit).append(";");
}
- buildOnEvent.append(AjaxRendererUtils.buildOnEvent(this,
- getFacesContext(), getEvent(), true));
+// buildOnEvent.append(AjaxRendererUtils.buildOnEvent(this,
+// getFacesContext(), getEvent(), true));
String script = buildOnEvent.toString();
return script;
}
@@ -152,7 +137,7 @@
}
}
// Write information about encoded areas after submission.
- AjaxRendererUtils.encodeAreas(context, this);
+// AjaxRendererUtils.encodeAreas(context, this);
}
public Set<UIComponent> getMessages(FacesContext context) {
@@ -220,71 +205,4 @@
return found;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.ajax4jsf.event.AjaxSource#addAjaxListener(org.ajax4jsf.event.AjaxListener
- * )
- */
- public void addAjaxListener(AjaxListener listener) {
- addFacesListener(listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.event.AjaxSource#getAjaxListeners()
- */
- public AjaxListener[] getAjaxListeners() {
- return (AjaxListener[]) getFacesListeners(AjaxListener.class);
- }
-
- /*
- * (non-Javadoc)
- *
- * @seeorg.ajax4jsf.event.AjaxSource#removeAjaxListener(org.ajax4jsf.event.
- * AjaxListener)
- */
- public void removeAjaxListener(AjaxListener listener) {
- removeFacesListener(listener);
- }
-
- public void setAjaxListener(MethodExpression listener) {
- AjaxListener[] ajaxListeners = getAjaxListeners();
- for (int i = 0; i < ajaxListeners.length; i++) {
- AjaxListener ajaxListener = ajaxListeners[i];
- if (ajaxListener.getClass().equals(
- MethodExpressionAjaxListener.class)) {
- MethodExpressionAjaxListener expressionListener = (MethodExpressionAjaxListener) ajaxListener;
- if (expressionListener.getExpression() != listener) {
- removeAjaxListener(ajaxListener);
-
- if (listener == null) {
-
- return;
- } else {
-
- break;
- }
- }
- }
- }
-
- addAjaxListener(new MethodExpressionAjaxListener(listener));
- }
-
- public MethodExpression getAjaxListener() {
- AjaxListener[] ajaxListeners = getAjaxListeners();
- for (int i = 0; i < ajaxListeners.length; i++) {
- AjaxListener ajaxListener = ajaxListeners[i];
- if (ajaxListener.getClass().equals(
- MethodExpressionAjaxListener.class)) {
- MethodExpressionAjaxListener expressionListener = (MethodExpressionAjaxListener) ajaxListener;
- return expressionListener.getExpression();
- }
- }
-
- return null;
- }
}
Modified: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -24,10 +24,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import javax.el.ELContext;
@@ -38,28 +36,11 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
-import javax.faces.component.UIInput;
-import javax.faces.component.UIMessage;
-import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
import javax.faces.validator.Validator;
-import org.ajax4jsf.component.AjaxComponent;
-import org.ajax4jsf.component.AjaxContainer;
-import org.ajax4jsf.component.AjaxSupport;
-import org.ajax4jsf.component.EventValueExpression;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.el.ELContextWrapper;
-import org.ajax4jsf.event.AjaxEvent;
-import org.ajax4jsf.event.AjaxListener;
-import org.ajax4jsf.renderkit.AjaxContainerRenderer;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
-import org.ajax4jsf.util.CapturingELResolver;
-import org.richfaces.event.ValidatorEvent;
-import org.richfaces.validator.HibernateValidator;
+import org.richfaces.el.ELContextWrapper;
+import org.richfaces.el.util.CapturingELResolver;
import org.richfaces.validator.FacesBeanValidator;
import org.richfaces.validator.GraphValidator;
@@ -112,7 +93,7 @@
*
* @return
*/
- public abstract Object getProfiles();
+ public abstract Set<String> getProfiles();
/**
* Set set of profiles for validation
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIRichMessages.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIRichMessages.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIRichMessages.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -0,0 +1,41 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import javax.faces.component.UIMessages;
+import javax.faces.context.FacesContext;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class UIRichMessages extends UIMessages {
+
+ public void updateMessages(FacesContext context, String clientId) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIRichMessages.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-09-14 22:30:39 UTC (rev 19206)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-09-14 23:05:28 UTC (rev 19207)
@@ -16,6 +16,7 @@
public static final String RENDERER_TYPE = "org.richfaces.ClientValidatorRenderer";
+
public ClientValidatorRenderer () {
super();
}
14 years, 3 months
JBoss Rich Faces SVN: r19206 - in branches/RF-8742/ui/validator: api and 19 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-09-14 18:30:39 -0400 (Tue, 14 Sep 2010)
New Revision: 19206
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/
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/taglib/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
Modified:
branches/RF-8742/ui/validator/api/pom.xml
branches/RF-8742/ui/validator/api/src/main/java/META-INF/MANIFEST.MF
branches/RF-8742/ui/validator/impl/pom.xml
branches/RF-8742/ui/validator/pom.xml
branches/RF-8742/ui/validator/ui/pom.xml
Log:
RESOLVED - issue RF-9214: CSV: create project in sandbox
https://jira.jboss.org/browse/RF-9214
Modified: branches/RF-8742/ui/validator/api/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/api/pom.xml 2010-09-14 18:41:14 UTC (rev 19205)
+++ branches/RF-8742/ui/validator/api/pom.xml 2010-09-14 22:30:39 UTC (rev 19206)
@@ -52,6 +52,12 @@
<groupId>org.richfaces.ui.common</groupId>
<artifactId>richfaces-ui-common-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<scm>
Property changes on: branches/RF-8742/ui/validator/api/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/META-INF/MANIFEST.MF
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,68 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+/**
+ *
+ */
+package org.richfaces.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ValidatorEvent extends FacesEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5593837134704144777L;
+
+ public ValidatorEvent(UIComponent component) {
+ super(component);
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+ @Override
+ public boolean isAppropriateListener(FacesListener listener) {
+ // TODO Auto-generated method stub
+ return listener instanceof ValidatorListener;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+ @Override
+ public void processListener(FacesListener listener) {
+ if (listener instanceof ValidatorListener) {
+ ValidatorListener validationListener = (ValidatorListener) listener;
+ validationListener.processValidation(this);
+ }
+
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,34 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.event;
+
+import javax.faces.event.FacesListener;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public interface ValidatorListener extends FacesListener {
+
+ public void processValidation(ValidatorEvent event);
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,480 @@
+package org.richfaces.validator;
+
+import java.beans.FeatureDescriptor;
+import java.util.Collection;
+import java.util.EmptyStackException;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.Stack;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.component.ClonedObjectResolver;
+import org.richfaces.el.ELContextWrapper;
+
+public abstract class ObjectValidator {
+
+ private static final String RESOURCE_BUNDLE_IS_NOT_REGISTERED_FOR_CURRENT_LOCALE = "Resource bundle is not registered for current locale";
+
+ private static final String FACES_CONTEXT_IS_NULL = "Faces context is null";
+ protected static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters is not correct.";
+ private static final String LOCALE_IS_NOT_SET = "Locale is not set";
+ private static final String VIEW_ROOT_IS_NOT_INITIALIZED = "ViewRoot is not initialized";
+ private static final Object MUTEX = new Object();
+
+ private static final Log log = LogFactory.getLog(ObjectValidator.class);
+
+ protected final ObjectValidator parent;
+
+ /**
+ * Create BeanValidator instance. For a Junit tests only.
+ *
+ * @return
+ */
+ static ObjectValidator createInstance() {
+ // TODO - get instance class name from a "META-INF/service"
+ // If the Seam framework is active, org.jboss.seam.core.Validators
+ // component should be used.
+ ObjectValidator validator = null;
+ try {
+ validator = new BeanValidator();
+ } catch (Throwable e){
+ // JSR-303 is not avalable.
+ log.warn("Validator implementations not found at classpath, default NullValidator will be used.");
+ validator = new NullValidator();
+ }
+ return validator;
+ }
+
+ ObjectValidator() {
+ this.parent = null;
+ }
+
+ ObjectValidator(ObjectValidator parent){
+ this.parent = parent;
+ }
+ /**
+ * Return BeanValidator object from a ServletContext attribute. Create new
+ * instance if none is defined.
+ *
+ * @param context
+ * @return
+ */
+ public static ObjectValidator getInstance(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ externalContext.getContext();
+ ObjectValidator instance;
+ // TODO - use properly synchronization mutex ?
+ synchronized (MUTEX) {
+ Map<String, Object> applicationMap = externalContext
+ .getApplicationMap();
+ instance = (ObjectValidator) applicationMap.get(VALIDATOR_PARAM);
+ if (null == instance) {
+ // Vaildator not initialized - create and store new instance.
+ instance = createInstance();
+ applicationMap.put(VALIDATOR_PARAM, instance);
+ }
+ }
+ return instance;
+ }
+
+ public abstract Collection<String> validateGraph(FacesContext context, Object value,
+ Set<String> profiles);
+
+ /**
+ * Perform Validation for a new value.
+ *
+ * @param context
+ * current faces context.
+ * @param target
+ * {@link ValueExpression} for a value assignment.
+ * @param value
+ * new value for validation
+ * @param profiles TODO
+ * @return null if no validation errors. Array of the validation messages
+ * otherwise.
+ * @throws FacesException
+ * if locale or context not properly initialized
+ */
+ public Collection<String> validate(FacesContext context, ValueExpression target,
+ Object value, Set<String> profiles) {
+ if (null == context) {
+ throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
+ }
+ Collection<String> validationMessages = null;
+ if (null != target) {
+ ELContext elContext = context.getELContext();
+ ValidationResolver validationResolver = createValidationResolver(
+ context, elContext.getELResolver(),profiles);
+ ELContextWrapper wrappedElContext = new ELContextWrapper(elContext,
+ validationResolver);
+ try {
+ target.setValue(wrappedElContext, value);
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ if (!validationResolver.isValid()) {
+ validationMessages = validationResolver.getValidationMessages();
+ }
+ if(null != parent){
+ Collection<String> parentMessages = parent.validate(context, target, value, profiles);
+ if (null != validationMessages) {
+ if (null != parentMessages) {
+ validationMessages.addAll(parentMessages);
+ }
+ } else {
+ validationMessages = parentMessages;
+ }
+ }
+
+ }
+ return validationMessages;
+ }
+
+ /**
+ * Validate bean property for a new value.
+ * @param facesContext TODO
+ * @param base
+ * - bean
+ * @param property
+ * - bean property name.
+ * @param value
+ * new value.
+ * @param profiles TODO
+ *
+ * @return null for a valid value, array of the validation messages
+ * othervise.
+ */
+ protected abstract Collection<String> validate(FacesContext facesContext, Object base,
+ String property, Object value, Set<String> profiles);
+
+ static Locale calculateLocale(FacesContext context) {
+ if (null == context.getViewRoot()) {
+ throw new FacesException(VIEW_ROOT_IS_NOT_INITIALIZED);
+ } else if (null == context.getViewRoot().getLocale()) {
+ throw new FacesException(LOCALE_IS_NOT_SET);
+ }
+ Locale locale = context.getViewRoot().getLocale();
+ return locale;
+ }
+
+ static ResourceBundle getResourceBundle(FacesContext facesContext, String name) {
+ ResourceBundle bundle = null;
+ if (null != facesContext) {
+ Application application = facesContext.getApplication();
+ try {
+ bundle = application.getResourceBundle(facesContext,
+ name);
+
+ } catch (Exception e) {
+ // Let one more attempt to load resource
+ }
+ }
+ if (null == bundle) {
+ ClassLoader classLoader = Thread.currentThread()
+ .getContextClassLoader();
+ if (null == classLoader) {
+ classLoader = ObjectValidator.class.getClassLoader();
+ }
+ try {
+ bundle = ResourceBundle.getBundle(name, calculateLocale(facesContext),
+ classLoader);
+
+ } catch (MissingResourceException e) {
+ // Do nothing, use default bundle.
+ }
+ }
+ return bundle;
+ }
+
+ protected ValidationResolver createValidationResolver(FacesContext context,
+ ELResolver parent, Set<String> profiles) {
+ return new ValidationResolver(parent, context, profiles);
+ }
+
+ /**
+ * @author asmirnov
+ *
+ */
+ protected static class BasePropertyPair {
+ private final Object base;
+ private final Object property;
+
+ /**
+ * @param base
+ * @param property
+ */
+ public BasePropertyPair(Object base, Object property) {
+ this.base = base;
+ this.property = property;
+ }
+
+ /**
+ * @return the base
+ */
+ public Object getBase() {
+ return base;
+ }
+
+ /**
+ * @return the property
+ */
+ public Object getProperty() {
+ return property;
+ }
+
+ }
+
+ /**
+ * Class for identify validator instance by locale
+ *
+ * @author amarkhel
+ *
+ */
+ protected static class ValidatorKey {
+ private final Class<? extends Object> validatableClass;
+ private final Locale locale;
+
+ /**
+ * Constructor for ValidatorKey object
+ *
+ * @param validatableClass
+ * - class to validate
+ * @param locale
+ * - User locale to determine Resource bundle, used during
+ * validation process
+ */
+ public ValidatorKey(Class<? extends Object> validatableClass,
+ Locale locale) {
+ this.validatableClass = validatableClass;
+ this.locale = locale;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((locale == null) ? 0 : locale.hashCode());
+ result = prime
+ * result
+ + ((validatableClass == null) ? 0 : validatableClass
+ .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 (!(obj instanceof ValidatorKey))
+ return false;
+ ValidatorKey other = (ValidatorKey) obj;
+ if (locale == null) {
+ if (other.locale != null)
+ return false;
+ } else if (!locale.equals(other.locale))
+ return false;
+ if (validatableClass == null) {
+ if (other.validatableClass != null)
+ return false;
+ } else if (!validatableClass.equals(other.validatableClass))
+ return false;
+ return true;
+ }
+
+ }
+
+ /**
+ * Wrapper class for a {@link ELResolver}. For a setValue method, perform
+ * validation instead of real assignment.
+ *
+ * @author asmirnov
+ *
+ */
+ final class ValidationResolver extends ELResolver {
+
+ /**
+ * Original resolver.
+ */
+ private final ELResolver parent;
+
+ private boolean valid = true;
+
+ private Collection<String> validationMessages = null;
+
+ private Stack<BasePropertyPair> valuesStack;
+
+ private Set<String> profiles;
+
+ private FacesContext facesContext;
+
+ private boolean clonedObject = false;
+
+ /**
+ * @param parent
+ * @param context
+ */
+ public ValidationResolver(ELResolver parent, FacesContext context, Set<String> profiles) {
+ this.parent = parent;
+ this.valuesStack = new Stack<BasePropertyPair>();
+ this.profiles = profiles;
+ this.facesContext = context;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @return
+ * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext,
+ * java.lang.Object)
+ */
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return parent.getCommonPropertyType(context, base);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @return
+ * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext,
+ * java.lang.Object)
+ */
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(
+ ELContext context, Object base) {
+ return parent.getFeatureDescriptors(context, base);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#getType(javax.el.ELContext,
+ * java.lang.Object, java.lang.Object)
+ */
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ return parent.getType(context, base, property);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#getValue(javax.el.ELContext,
+ * java.lang.Object, java.lang.Object)
+ */
+ public Object getValue(ELContext context, Object base, Object property) {
+ Object value = ClonedObjectResolver.resolveCloned(context, base, property);
+ if(null != value){
+ this.clonedObject =true;
+ context.setPropertyResolved(true);
+ } else {
+ value = parent.getValue(context, base, property);
+ }
+ valuesStack.push(new BasePropertyPair(base, property));
+ return value;
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext,
+ * java.lang.Object, java.lang.Object)
+ */
+ public boolean isReadOnly(ELContext context, Object base,
+ Object property) {
+ return parent.isReadOnly(context, base, property);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @param value
+ * @see javax.el.ELResolver#setValue(javax.el.ELContext,
+ * java.lang.Object, java.lang.Object, java.lang.Object)
+ */
+ public void setValue(ELContext context, Object base, Object property,
+ Object value) {
+ if (null != base && null != property) {
+ // TODO - detect value object from inderect references ( e.g. data table variables ).
+ if(this.clonedObject){
+ parent.setValue(context, base, property, value);
+ }
+ context.setPropertyResolved(true);
+ // For Arrays, Collection or Map use parent base and property.
+ BasePropertyPair basePropertyPair = lookupBeanProperty(new BasePropertyPair(
+ base, property));
+ base = basePropertyPair.getBase();
+ property = basePropertyPair.getProperty();
+ if (null != base && null != property) {
+ // https://jira.jboss.org/jira/browse/RF-4034
+ // apache el looses locale information during value
+ // resolution,
+ // so we use our own
+ validationMessages = validate(facesContext, base,
+ property.toString(), value, profiles);
+ valid = null == validationMessages
+ || 0 == validationMessages.size();
+
+ }
+ }
+ }
+
+ private BasePropertyPair lookupBeanProperty(BasePropertyPair pair) {
+ Object base = pair.getBase();
+ if (null != base
+ && (base instanceof Collection || base instanceof Map || base
+ .getClass().isArray())) {
+ try {
+ pair = lookupBeanProperty(valuesStack.pop());
+ } catch (EmptyStackException e) {
+ // Do nothing, this is a first item.
+ }
+ }
+ return pair;
+ }
+
+ /**
+ * @return the validationMessages
+ */
+ public Collection<String> getValidationMessages() {
+ return validationMessages;
+ }
+
+ }
+
+}
\ No newline at end of file
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/RF-8742/ui/validator/impl/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/impl/pom.xml 2010-09-14 18:41:14 UTC (rev 19205)
+++ branches/RF-8742/ui/validator/impl/pom.xml 2010-09-14 22:30:39 UTC (rev 19206)
@@ -1,69 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
+ <!--
+ 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.
+ -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.richfaces.ui</groupId>
- <artifactId>richfaces-ui-parent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../../parent/pom.xml</relativePath>
- </parent>
+ <parent>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>richfaces-ui-parent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
- <groupId>org.richfaces.ui.validator</groupId>
- <artifactId>richfaces-ui-validator-impl</artifactId>
- <name>Richfaces UI Components: validator impl</name>
- <packaging>jar</packaging>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
+ <groupId>org.richfaces.ui.validator</groupId>
+ <artifactId>richfaces-ui-validator-impl</artifactId>
+ <name>Richfaces UI Components: validator impl</name>
+ <packaging>jar</packaging>
- <dependencies>
- <dependency>
- <!-- todo remove this dependency or move to test scope -->
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-impl</artifactId>
- </dependency>
- <dependency>
- <groupId>org.richfaces.ui.common</groupId>
- <artifactId>richfaces-ui-common-ui</artifactId>
- </dependency>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <!-- todo remove this dependency or move to test scope -->
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.ui.common</groupId>
+ <artifactId>richfaces-ui-common-ui</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.richfaces.ui.validator</groupId>
- <artifactId>richfaces-ui-validator-api</artifactId>
- </dependency>
- </dependencies>
-
- <scm>
- <connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/trunk/ui/validator/impl</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/trunk/ui/validator/impl</developerConnection>
- <url>http://fisheye.jboss.org/browse/richfaces</url>
- </scm>
+
+ <dependency>
+ <groupId>org.richfaces.ui.validator</groupId>
+ <artifactId>richfaces-ui-validator-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/trunk/ui/validator/impl</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/trunk/ui/validator/impl</developerConnection>
+ <url>http://fisheye.jboss.org/browse/richfaces</url>
+ </scm>
</project>
Property changes on: branches/RF-8742/ui/validator/impl/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,163 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.validation.ConstraintViolation;
+import javax.validation.MessageInterpolator;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class BeanValidator extends ObjectValidator {
+
+ private static final Class[] DEFAULT_PROFILE = new Class[] {};
+ private final ValidatorFactory validatorFactory;
+ private ValidatorContext validatorContext;
+
+ BeanValidator() {
+ // Enforce class to load
+ ValidatorFactory.class.getName();
+ // Check Factory, to avoid instantiation errors
+ // https://jira.jboss.org/jira/browse/RF-7226
+ validatorFactory = Validation
+ .buildDefaultValidatorFactory();
+ validatorContext = validatorFactory.usingContext();
+ MessageInterpolator jsfMessageInterpolator = new JsfMessageInterpolator(
+ validatorFactory.getMessageInterpolator());
+ validatorContext.messageInterpolator(jsfMessageInterpolator);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.validator.ObjectValidator#validate(java.lang.Object,
+ * java.lang.String, java.lang.Object, java.util.Locale)
+ */
+ @Override
+ protected Collection<String> validate(FacesContext facesContext, Object base, String property,
+ Object value, Set<String> profiles) {
+ Class beanType = base.getClass();
+ Set<ConstraintViolation<Object>> constrains = getValidator(facesContext)
+ .validateValue(beanType, property, value, getGroups(profiles));
+ return extractMessages(constrains);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.validator.ObjectValidator#validateGraph(javax.faces.context
+ * .FacesContext, java.lang.Object, java.util.Set)
+ */
+ @Override
+ public Collection<String> validateGraph(FacesContext context, Object value,
+ Set<String> profiles) {
+ Class<?>[] groups = getGroups(profiles);
+ Set<ConstraintViolation<Object>> violations = getValidator(
+ context).validate(value, groups);
+ Collection<String> messages = extractMessages(violations);
+ if(null != parent){
+ Collection<String> parentMessages = parent.validateGraph(context, value, profiles);
+ if (null != messages) {
+ if (null != parentMessages) {
+ messages.addAll(parentMessages);
+ }
+ } else {
+ messages = parentMessages;
+ }
+ }
+ return messages;
+ }
+
+ private Class<?>[] getGroups(Set<String> profiles) {
+ Class<?> groups[] = null;
+ if (null != profiles) {
+ groups = new Class<?>[profiles.size()];
+ int i = 0;
+ for (String group : profiles) {
+ try {
+ groups[i] = Class.forName(group, false, Thread
+ .currentThread().getContextClassLoader());
+ } catch (ClassNotFoundException e) {
+ try {
+ groups[i] = Class.forName(group);
+ } catch (ClassNotFoundException e1) {
+ throw new FacesException(
+ "Bean validation group not found " + group, e1);
+ }
+ }
+ i++;
+ }
+
+ } else {
+ groups = DEFAULT_PROFILE;
+ }
+ return groups;
+ }
+
+ private Collection<String> extractMessages(Set<ConstraintViolation<Object>> violations) {
+ Collection<String> messages = null;
+ if (null != violations && violations.size() > 0) {
+ messages = new ArrayList<String>(violations.size());
+ for (ConstraintViolation<? extends Object> constraintViolation : violations) {
+ messages.add(constraintViolation.getMessage());
+ }
+
+ }
+ return messages;
+ }
+
+ protected Validator getValidator(FacesContext facesContext) {
+ Validator beanValidator = validatorContext.getValidator();
+ return beanValidator;
+ }
+
+ private static class JsfMessageInterpolator implements MessageInterpolator {
+
+ private MessageInterpolator delegate;
+
+ public JsfMessageInterpolator(
+ MessageInterpolator delegate) {
+ this.delegate = delegate;
+ }
+
+ public String interpolate(String messageTemplate, Context context) {
+
+ Locale locale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ if (null != locale) {
+ return delegate.interpolate(messageTemplate, context,
+ locale);
+ } else {
+ return delegate.interpolate(messageTemplate, context);
+ }
+ }
+
+ public String interpolate(String messageTemplate, Context context,
+ Locale locale) {
+ Locale faceslocale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ if (null != faceslocale) {
+ return delegate.interpolate(messageTemplate, context,
+ faceslocale);
+ } else {
+ return delegate.interpolate(messageTemplate, context, locale);
+ }
+ }
+
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,181 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.validator;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+
+/**
+ * Implementation of the JSF validator to use with Bean Validation / Hibernate
+ * validator
+ *
+ * @author asmirnov
+ *
+ */
+public class FacesBeanValidator implements NullValueValidator,Serializable, GraphValidator {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -264568176252121853L;
+ public static final String BEAN_VALIDATOR_TYPE = "org.richfaces.BeanValidator";
+
+ private ValueExpression summaryExpression = null;
+
+ private String summary = null;
+
+ private ValueExpression profilesExpression = null;
+
+ private Object profiles = null;
+ /**
+ * @return the summary
+ */
+ public String getSummary() {
+ String summaryString = null;
+ if(null != summaryExpression){
+ summaryString = (String) summaryExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ }else {
+ summaryString = this.summary;
+ }
+ return summaryString;
+ }
+
+ /**
+ * @param summary the summary to set
+ */
+ public void setSummary(ValueExpression summary) {
+ this.summaryExpression = summary;
+ }
+
+
+ /**
+ * @param summary the summary to set
+ */
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent, java.lang.Object)
+ */
+ public void validate(FacesContext context, UIComponent component,
+ Object convertedValue) throws ValidatorException {
+ if (component instanceof EditableValueHolder) {
+ // Validate input component
+ EditableValueHolder input = (EditableValueHolder) component;
+ try {
+ ValueExpression valueExpression = component
+ .getValueExpression("value");
+ if (null != valueExpression) {
+ Collection<String> messages = ObjectValidator.getInstance(context)
+ .validate(context, valueExpression, convertedValue, getProfiles());
+ if (null != messages) {
+ input.setValid(false);
+ Object label = getLabel(context, component);
+ Locale locale = context.getViewRoot().getLocale();
+ // send all validation messages.
+ for (String msg : messages) {
+ // https://jira.jboss.org/jira/browse/RF-7636 -
+ // format values.
+ msg = formatMessage(msg, locale, label,convertedValue); // create Summary message ?
+ String summaryString = getSummary() != null ? getSummary()
+ : msg;
+ summaryString = formatMessage(summaryString, locale, label,convertedValue);
+ context.addMessage(component.getClientId(context), new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, summaryString , msg));
+ }
+ }
+ }
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ }
+ }
+
+ static String formatMessage(String msg, Locale locale, Object... messageParams) {
+ if (msg.contains("{")) {
+ try {
+ MessageFormat messageFormat = new MessageFormat(
+ msg, locale);
+ msg = messageFormat.format(messageParams);
+ } catch (IllegalArgumentException e) {
+ // Do nothing, use original string unchanged.
+ }
+ }
+ return msg;
+ }
+
+ static Object getLabel(FacesContext context, UIComponent component) {
+ Object label = component.getAttributes().get("label");
+ if(null == label || 0 == label.toString().length()){
+ label = component.getClientId(context);
+ }
+ return label;
+ }
+
+ public Collection<String> validateGraph(FacesContext context, UIComponent component,
+ Object value, Object profiles) throws ValidatorException {
+ ObjectValidator beanValidator = ObjectValidator.getInstance(context);
+ Collection<String> messages = beanValidator.validateGraph(context, value,AjaxRendererUtils.asSet(profiles));
+ return messages;
+ }
+
+ /**
+ * @return the profiles
+ */
+ public Set<String> getProfiles() {
+ Object profiles;
+ if(null != profilesExpression){
+ profiles = profilesExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ }else {
+ profiles = this.profiles;
+ }
+ return AjaxRendererUtils.asSet(profiles);
+ }
+
+ /**
+ * @param profiles the profiles to set
+ */
+ public void setProfiles(Object profiles) {
+ this.profiles = profiles;
+ }
+
+ public void setProfiles(ValueExpression profilesExpression) {
+ this.profilesExpression = profilesExpression;
+ }
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class NullValidator extends ObjectValidator {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.validator.ObjectValidator#validate(java.lang.Object, java.lang.String, java.lang.Object, java.util.Locale)
+ */
+ @Override
+ protected Collection<String> validate(FacesContext facesContext, Object base, String property,
+ Object value, Set<String> profiles) {
+ // do nothing.
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.validator.ObjectValidator#validateGraph(javax.faces.context.FacesContext, java.lang.Object, java.util.Set)
+ */
+ @Override
+ public Collection<String> validateGraph(FacesContext context, Object value,
+ Set<String> profiles) {
+ // do nothing
+ return null;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Property changes on: branches/RF-8742/ui/validator/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified: branches/RF-8742/ui/validator/ui/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/ui/pom.xml 2010-09-14 18:41:14 UTC (rev 19205)
+++ branches/RF-8742/ui/validator/ui/pom.xml 2010-09-14 22:30:39 UTC (rev 19206)
@@ -56,6 +56,18 @@
<groupId>org.richfaces.ui.common</groupId>
<artifactId>richfaces-ui-common-ui</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
Property changes on: branches/RF-8742/ui/validator/ui/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,34 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.component.behavior.ClientBehaviorBase;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ClientValidatorBehavior extends ClientBehaviorBase {
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,103 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.UIGraphValidator.GraphValidatorState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ClonedObjectResolver extends ELResolver {
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ // Do nothing
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
+ Object base) {
+ // do nothing
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ Object cloned = resolveCloned(context, base, property);
+ if(null != cloned){
+ context.setPropertyResolved(true);
+ return cloned.getClass();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ Object cloned = resolveCloned(context, base, property);
+ if(null != cloned){
+ context.setPropertyResolved(true);
+ }
+ return cloned;
+ }
+
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object base, Object property,
+ Object value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public static Object resolveCloned(ELContext context, Object base, Object property){
+ if(null != base || null != property){
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ for (String key : requestMap.keySet()) {
+ if(null != key && key.startsWith(UIGraphValidator.STATE_ATTRIBUTE_PREFIX)){
+ UIGraphValidator.GraphValidatorState state = (GraphValidatorState) requestMap.get(key);
+ if(state.isSame(base, property)){
+ return state.getCloned();
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,290 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIMessage;
+import javax.faces.component.UIMessages;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.component.AjaxComponent;
+import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.component.EventValueExpression;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.event.AjaxListener;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.webapp.taglib.MethodExpressionAjaxListener;
+import org.richfaces.event.ValidatorEvent;
+
+/**
+ * JSF component class
+ *
+ */
+public abstract class UIAjaxValidator extends UIComponentBase implements
+ AjaxComponent, AjaxSupport, AjaxContainer {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.AjaxValidator";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.AjaxValidator";
+
+ public static final String BEAN_VALIDATOR_FACET = "org.richfaces.validator.";
+
+ @Override
+ public void setParent(UIComponent parent) {
+ super.setParent(parent);
+
+ if (null != parent && parent instanceof EditableValueHolder) {
+ setParentProperties(parent);
+ }
+ }
+
+ /**
+ * @param parent
+ * @throws FacesException
+ */
+ public void setParentProperties(UIComponent parent) throws FacesException {
+ if (!(parent instanceof EditableValueHolder)) {
+ throw new FacesException(
+ "Parent component must be an EditableValueHolder");
+ }
+
+ if (null != getEvent()) {
+ ValueExpression binding = new EventValueExpression(this);
+ parent.setValueExpression(getEvent(), binding);
+ }
+ }
+
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+ if (event.getComponent() == this) {
+ FacesContext context = getFacesContext();
+ if (event instanceof ValidatorEvent) {
+ // ByPass UpdateModelValue
+ context.renderResponse();
+ } else if (event instanceof AjaxEvent) {
+ // TODO - find all UIMessages components for a parent UIInput.
+ // for an ajaxSingle component, re-render only target message.
+ AjaxContext ajaxContext = AjaxContext
+ .getCurrentInstance(context);
+ ajaxContext.setSubmittedRegionClientId(this
+ .getClientId(context));
+ }
+ }
+ }
+
+ @Override
+ public void queueEvent(FacesEvent event) {
+ if (event instanceof ValidatorEvent && event.getComponent() == this) {
+ UIComponent parent = getParent();
+ if (parent instanceof UIInput) {
+ UIInput input = (UIInput) parent;
+ if (input.isImmediate()) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else {
+ event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ }
+ }
+ }
+ super.queueEvent(event);
+ }
+
+ public String getEventString() {
+ StringBuffer buildOnEvent = new StringBuffer();
+ String onsubmit = getOnsubmit();
+ // Insert script to call before submit ajax request.
+ if (null != onsubmit) {
+ buildOnEvent.append(onsubmit).append(";");
+ }
+ buildOnEvent.append(AjaxRendererUtils.buildOnEvent(this,
+ getFacesContext(), getEvent(), true));
+ String script = buildOnEvent.toString();
+ return script;
+ }
+
+ public UIComponent getSingleComponent() {
+ return getParent();
+ }
+
+ public void encodeAjax(FacesContext context) throws IOException {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ Set<String> renderedAreas = ajaxContext.getAjaxRenderedAreas();
+ for (UIComponent message : getMessages(context)) {
+ if (message.isRendered()) {
+ message.encodeAll(context);
+ renderedAreas.add(message.getClientId(context));
+ }
+ }
+ // Write information about encoded areas after submission.
+ AjaxRendererUtils.encodeAreas(context, this);
+ }
+
+ public Set<UIComponent> getMessages(FacesContext context) {
+ Set<UIComponent> messages = new HashSet<UIComponent>();
+ findMessages(this.getParent(), this, messages,false);
+ findRichMessages(context, context.getViewRoot(), messages);
+ return messages;
+ }
+
+
+ /**
+ * Find all instances of the {@link UIRichMessages} and update list of the rendered messages.
+ * @param context
+ * @param component
+ * @param messages
+ */
+ protected void findRichMessages(FacesContext context,UIComponent component, Set<UIComponent> messages) {
+ Iterator<UIComponent> facetsAndChildren = component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = (UIComponent) facetsAndChildren.next();
+ if (child instanceof UIRichMessages) {
+ UIRichMessages richMessage = (UIRichMessages) child;
+ if(null == richMessage.getFor()){
+ richMessage.updateMessages(context, this.getParent().getClientId(context));
+ messages.add(richMessage);
+ }
+ } else {
+ findRichMessages(context, child, messages);
+ }
+ }
+ }
+
+ /**
+ * Recursive search messages for the parent component.
+ * @param parent
+ * @param component
+ * @param messages
+ * @return
+ */
+ protected boolean findMessages(UIComponent parent, UIComponent component,
+ Set<UIComponent> messages,boolean found) {
+ Iterator<UIComponent> facetsAndChildren = parent.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = (UIComponent) facetsAndChildren.next();
+ if (child != component) {
+ if (child instanceof UIMessage || child instanceof UIMessages) {
+ UIComponent message = (UIComponent) child;
+ Object targetId = message.getAttributes().get("for");
+ if (null != targetId
+ && targetId.equals(getParent().getId())) {
+ messages.add(message);
+ found = true;
+ }
+ } else {
+ found |= findMessages(child, null, messages,found);
+ }
+ }
+ }
+ if(!(found && parent instanceof NamingContainer) && component != null){
+ UIComponent newParent = parent.getParent();
+ if(null != newParent){
+ found = findMessages(newParent, parent, messages,found);
+ }
+ }
+ return found;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.event.AjaxSource#addAjaxListener(org.ajax4jsf.event.AjaxListener
+ * )
+ */
+ public void addAjaxListener(AjaxListener listener) {
+ addFacesListener(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.event.AjaxSource#getAjaxListeners()
+ */
+ public AjaxListener[] getAjaxListeners() {
+ return (AjaxListener[]) getFacesListeners(AjaxListener.class);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.ajax4jsf.event.AjaxSource#removeAjaxListener(org.ajax4jsf.event.
+ * AjaxListener)
+ */
+ public void removeAjaxListener(AjaxListener listener) {
+ removeFacesListener(listener);
+ }
+
+ public void setAjaxListener(MethodExpression listener) {
+ AjaxListener[] ajaxListeners = getAjaxListeners();
+ for (int i = 0; i < ajaxListeners.length; i++) {
+ AjaxListener ajaxListener = ajaxListeners[i];
+ if (ajaxListener.getClass().equals(
+ MethodExpressionAjaxListener.class)) {
+ MethodExpressionAjaxListener expressionListener = (MethodExpressionAjaxListener) ajaxListener;
+ if (expressionListener.getExpression() != listener) {
+ removeAjaxListener(ajaxListener);
+
+ if (listener == null) {
+
+ return;
+ } else {
+
+ break;
+ }
+ }
+ }
+ }
+
+ addAjaxListener(new MethodExpressionAjaxListener(listener));
+ }
+
+ public MethodExpression getAjaxListener() {
+ AjaxListener[] ajaxListeners = getAjaxListeners();
+ for (int i = 0; i < ajaxListeners.length; i++) {
+ AjaxListener ajaxListener = ajaxListeners[i];
+ if (ajaxListener.getClass().equals(
+ MethodExpressionAjaxListener.class)) {
+ MethodExpressionAjaxListener expressionListener = (MethodExpressionAjaxListener) ajaxListener;
+ return expressionListener.getExpression();
+ }
+ }
+
+ return null;
+ }
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+/**
+ * Stage class to keep backward compatibility.
+ * @author asmirnov
+ * @deprecated That class has been renamed, Use {@link UIAjaxValidator} instead
+ *
+ */
+public abstract class UIBeanValidator extends UIAjaxValidator {
+
+ /* (non-Javadoc)
+ * @see javax.faces.component.UIComponent#getFamily()
+ */
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,377 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.validator.Validator;
+
+import org.ajax4jsf.component.AjaxComponent;
+import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.component.EventValueExpression;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.el.ELContextWrapper;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.event.AjaxListener;
+import org.ajax4jsf.renderkit.AjaxContainerRenderer;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.util.CapturingELResolver;
+import org.richfaces.event.ValidatorEvent;
+import org.richfaces.validator.HibernateValidator;
+import org.richfaces.validator.FacesBeanValidator;
+import org.richfaces.validator.GraphValidator;
+
+
+/**
+ * JSF component class
+ *
+ */
+public abstract class UIGraphValidator extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.GraphValidator";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.GraphValidator";
+
+ public static final String STATE_ATTRIBUTE_PREFIX = COMPONENT_TYPE+NamingContainer.SEPARATOR_CHAR;
+
+
+
+
+ /**
+ * Get object for validation
+ *
+ * @return
+ */
+ public abstract Object getValue();
+
+ /**
+ * Set object for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setValue(Object newvalue);
+
+ /**
+ * Get object for validation
+ *
+ * @return
+ */
+ public abstract String getSummary();
+
+ /**
+ * Set object for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setSummary(String newvalue);
+
+ /**
+ * Get set of profiles for validation
+ *
+ * @return
+ */
+ public abstract Object getProfiles();
+
+ /**
+ * Set set of profiles for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setProfiles(Object newvalue);
+
+ /**
+ * Get graph validator Id.
+ * @return
+ */
+ public abstract String getType();
+
+ /**
+ * Set graph validator Id.
+ * @param newvalue
+ */
+ public abstract void setType(String newvalue);
+
+
+ @Override
+ public void processDecodes(FacesContext context) {
+ GraphValidatorState validatorState = null;
+ // Detect value EL-expression.
+ ValueExpression valueExpression = getValueExpression("value");
+ if (null != valueExpression) {
+
+
+ Object value = getValue();
+ if (null !=value && value instanceof Cloneable) {
+ try {
+ ELContext initialELContext = context.getELContext();
+
+ CapturingELResolver capturingELResolver = new CapturingELResolver(initialELContext.getELResolver());
+ Class<?> type = valueExpression.getType(new ELContextWrapper(initialELContext, capturingELResolver));
+ if(null != type) {
+ validatorState = new GraphValidatorState();
+ Method method = getCloneMethod(value.getClass());
+ if(!Modifier.isPublic(method.getModifiers())){
+ // Method Object#clone() is protected by default. Make it public
+ // unless developer did it.
+ method.setAccessible(true);
+ }
+ validatorState.cloned = method.invoke(value);
+ validatorState.base = capturingELResolver.getBase();
+ validatorState.property = capturingELResolver.getProperty();
+ validatorState.active = true;
+ context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
+ }
+ } catch (NoSuchMethodException e) {
+ // do nothing, that is really not possible.
+ } catch (InvocationTargetException e) {
+ throw new FacesException(e);
+ } catch (IllegalArgumentException e) {
+ // do nothing, that is really not possible.
+ } catch (IllegalAccessException e) {
+ throw new FacesException(e);
+ }
+ }
+ }
+ super.processDecodes(context);
+ if(null != validatorState){
+ validatorState.active = false;
+ }
+ }
+
+ private Method getCloneMethod(Class<?> clazz) throws NoSuchMethodException {
+ try {
+ return clazz.getDeclaredMethod("clone");
+ } catch( NoSuchMethodException e){
+ if(null != clazz.getSuperclass()){
+ return getCloneMethod(clazz.getSuperclass());
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ protected String getStateId(FacesContext context) {
+ String stateId = STATE_ATTRIBUTE_PREFIX+getClientId(context);
+ return stateId;
+ }
+
+ protected GraphValidatorState getValidatorState(FacesContext context){
+ return (GraphValidatorState) context.getExternalContext().getRequestMap().get(getStateId(context));
+ }
+
+ @Override
+ public void processValidators(FacesContext context) {
+ GraphValidatorState validatorState = getValidatorState(context);
+ if(null != validatorState){
+ validatorState.active = true;
+ }
+ super.processValidators(context);
+ if(null != validatorState){
+ validatorState.active = false;
+ validateObject(context, validatorState.cloned);
+ context.getExternalContext().getRequestMap().remove(getStateId(context));
+ }
+ }
+
+ @Override
+ public void processUpdates(FacesContext context) {
+ super.processUpdates(context);
+ Object value = getValue();
+ validateObject(context, value);
+ }
+
+ private void validateObject(FacesContext context, Object value) {
+ if (null != value) {
+ Validator validator = context.getApplication().createValidator(getType());
+ if (validator instanceof GraphValidator) {
+ GraphValidator graphValidator = (GraphValidator) validator;
+ Collection<String> messages = graphValidator.validateGraph(context,this, value,getProfiles());
+ if (null != messages) {
+ context.renderResponse();
+ // send all validation messages.
+ String clientId = getClientId(context);
+ for (String msg : messages) {
+ // TODO - create Summary message ?
+ String summary = null != getSummary() ? getSummary() + msg : msg;
+ context.addMessage(clientId, new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, summary, msg));
+ }
+ }
+
+ } else {
+ throw new FacesException("Validator "+FacesBeanValidator.BEAN_VALIDATOR_TYPE+" does not implement GraphValidator");
+ }
+
+ }
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException {
+ super.encodeBegin(context);
+ FacesBeanValidator validator = (FacesBeanValidator)context.getApplication().createValidator(getType());
+ validator.setSummary(getSummary());
+ ValueExpression expression = getValueExpression("profiles");
+ if(null != expression){
+ validator.setProfiles(expression);
+ } else {
+ validator.setProfiles(getProfiles());
+ }
+ setupValidators(this,validator);
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context) throws IOException {
+ if(isRendered()){
+ for (UIComponent child : getChildren()) {
+ if(child.isRendered()){
+ child.encodeAll(context);
+ }
+ }
+ }
+ }
+
+ private void setupValidators(UIComponent component,
+ Validator validator) {
+ Iterator<UIComponent> facetsAndChildren = component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = facetsAndChildren.next();
+ if (child instanceof EditableValueHolder) {
+ EditableValueHolder input = (EditableValueHolder) child;
+ setupValidator(input,validator);
+ }
+ setupValidators(child, validator);
+ }
+ }
+
+ /**
+ * @param input
+ */
+ private void setupValidator(EditableValueHolder input,Validator validator) {
+ Validator[] validators = input.getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ if(validators[i] instanceof FacesBeanValidator){
+ return;
+ }
+ }
+ input.addValidator(validator);
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ public static final class GraphValidatorState {
+ private boolean active = false;
+ private Object cloned;
+ private Object base;
+ private Object property;
+ /**
+ * @return the active
+ */
+ public boolean isActive() {
+ return active;
+ }
+ /**
+ * @param active the active to set
+ */
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+ /**
+ * @return the cloned
+ */
+ public Object getCloned() {
+ return cloned;
+ }
+ /**
+ * @param cloned the cloned to set
+ */
+ public void setCloned(Object cloned) {
+ this.cloned = cloned;
+ }
+ /**
+ * @return the base
+ */
+ public Object getBase() {
+ return base;
+ }
+ /**
+ * @param base the base to set
+ */
+ public void setBase(Object base) {
+ this.base = base;
+ }
+ /**
+ * @return the property
+ */
+ public Object getProperty() {
+ return property;
+ }
+ /**
+ * @param property the property to set
+ */
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+
+ public boolean isSameBase(Object base){
+ return (null == base && null == this.base)||(base == this.base);
+ }
+
+ public boolean isSameProperty(Object property){
+ if(null == this.property){
+ return null == property;
+ } else {
+ return this.property.equals(property);
+ }
+ }
+
+ public boolean isSame(Object base, Object property){
+ return isSameBase(base)&& isSameProperty(property)&& active;
+ }
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,25 @@
+
+package org.richfaces.renderkit.html;
+
+
+//
+// Imports
+//
+import javax.faces.render.ClientBehaviorRenderer;
+
+
+
+/**
+ * Renderer for component class org.richfaces.renderkit.html.AjaxValidatorRenderer
+ */
+public class ClientValidatorRenderer extends ClientBehaviorRenderer {
+
+
+ public static final String RENDERER_TYPE = "org.richfaces.ClientValidatorRenderer";
+ public ClientValidatorRenderer () {
+ super();
+ }
+
+
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,142 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.taglib;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.webapp.taglib.AjaxComponentHandler;
+import org.richfaces.component.UIAjaxValidator;
+import org.richfaces.validator.FacesBeanValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.FaceletException;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.TagException;
+import com.sun.facelets.tag.TagHandler;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxValidatorHandler extends TagHandler {
+
+ /**
+ * A UIComponent for capturing a child UIComponent, representative of the
+ * desired Facet
+ *
+ * @author Jacob Hookom
+ *
+ */
+ private final static class UIFacet extends UIComponentBase {
+ public String getFamily() {
+ return null;
+ }
+ }
+
+ private TagAttribute _event;
+ private TagAttribute _summary;
+ private TagAttribute _profiles;
+ private AjaxComponentHandler _validatorHandler;
+
+ /**
+ * @param config
+ */
+ public AjaxValidatorHandler(ComponentConfig config) {
+ super(config);
+ _event = getAttribute("event");
+ _summary = getAttribute("summary");
+ _profiles = getAttribute("profiles");
+ _validatorHandler = new AjaxComponentHandler(config){
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ return super.createMetaRuleset(type).ignore("summary").ignore("profiles");
+ }
+ };
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent)
+ throws IOException, FacesException, FaceletException, ELException {
+ if (parent == null || !(parent instanceof EditableValueHolder)) {
+ throw new TagException(this.tag,
+ "Parent not an instance of EditableValueHolder: " + parent);
+ }
+ if (null == parent.getParent()) {
+ // New created component, add validator.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ FacesBeanValidator validator = (FacesBeanValidator) facesContext
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ if (null != _summary) {
+ if (_summary.isLiteral()) {
+ validator.setSummary(_summary.getValue(ctx));
+
+ } else {
+ validator.setSummary(_summary.getValueExpression(ctx,
+ String.class));
+ }
+ }
+ if( null != _profiles){
+ if(_profiles.isLiteral()){
+ validator.setProfiles(_profiles.getValue());
+ } else {
+ validator.setProfiles(_profiles.getValueExpression(ctx, Set.class));
+ }
+ }
+ ((EditableValueHolder) parent).addValidator(validator);
+ }
+ if (null != this._event) {
+ UIComponent c;
+ UIFacet facet = new UIFacet();
+ // Find facet for client validation component
+ String eventName = _event.getValue();
+ String facetName = UIAjaxValidator.BEAN_VALIDATOR_FACET + eventName;
+ c = parent.getFacet(facetName);
+ if (null != c) {
+ parent.getFacets().remove(facetName);
+ facet.getChildren().add(c);
+ }
+ this._validatorHandler.apply(ctx, facet);
+ c = (UIComponent) facet.getChildren().get(0);
+ parent.getFacets().put(facetName, c);
+
+ }
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,150 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.taglib;
+
+import javax.el.ValueExpression;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.webapp.UIComponentClassicTagBase;
+import javax.servlet.jsp.JspException;
+
+import org.ajax4jsf.webapp.taglib.UIComponentTagBase;
+import org.richfaces.component.UIAjaxValidator;
+import org.richfaces.renderkit.html.ClientValidatorRenderer;
+import org.richfaces.validator.FacesBeanValidator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxValidatorTagBase extends UIComponentTagBase {
+
+ /**
+ * Generate script for given event ( onclick, onenter ... )
+ */
+ private String event = null;
+
+ private ValueExpression summary = null;
+
+ private ValueExpression profiles = null;
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentTagBase#getComponentType()
+ */
+ @Override
+ public String getComponentType() {
+ return UIAjaxValidator.COMPONENT_TYPE;
+ }
+
+ /**
+ * @param event
+ * the event to set
+ */
+ public void setEvent(String event) {
+ this.event = event;
+ }
+
+ /**
+ * @param summary
+ * the summary to set
+ */
+ public void setSummary(ValueExpression summary) {
+ this.summary = summary;
+ }
+
+ @Override
+ public int doStartTag() throws JspException {
+ // Locate our parent UIComponentTag
+ UIComponentClassicTagBase tag = UIComponentClassicTagBase
+ .getParentUIComponentClassicTagBase(pageContext);
+ if (tag == null) {
+ // PENDING i18n
+ throw new JspException(
+ "Not nested in a UIComponentTag Error for tag with handler class:"
+ + this.getClass().getName());
+ }
+ UIComponent component = tag.getComponentInstance();
+ if (!(component instanceof EditableValueHolder)) {
+ // PENDING i18n
+ throw new JspException(
+ "Not nested in a UIInput component. Error for tag with handler class:"
+ + this.getClass().getName());
+
+ }
+ // Nothing to do unless this tag created a component
+ if (tag.getCreated()) {
+ // New created component, add validator.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ FacesBeanValidator validator = (FacesBeanValidator) facesContext
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ if (null != summary) {
+ if(summary.isLiteralText()){
+ validator.setSummary(summary.getExpressionString());
+ } else {
+ validator.setSummary(summary);
+ }
+ }
+ if(null != profiles){
+ if(profiles.isLiteralText()){
+ validator.setProfiles(profiles.getExpressionString());
+ } else {
+ validator.setProfiles(profiles);
+ }
+ }
+ ((EditableValueHolder) component).addValidator(validator);
+
+ }
+ return super.doStartTag();
+ }
+
+ @Override
+ protected void setProperties(UIComponent component) {
+ super.setProperties(component);
+ setStringProperty(component, "event", event);
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ event = null;
+ summary = null;
+ profiles = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentTagBase#getRendererType()
+ */
+ @Override
+ public String getRendererType() {
+ return ClientValidatorRenderer.RENDERER_TYPE;
+ }
+
+ @Override
+ protected String getFacetName() {
+ return UIAjaxValidator.BEAN_VALIDATOR_FACET
+ + (null == event ? "" : event);
+ }
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,71 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.taglib;
+
+import java.util.Set;
+
+import javax.faces.validator.Validator;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.richfaces.validator.FacesBeanValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.TagConfig;
+import com.sun.facelets.tag.jsf.ValidateHandler;
+import com.sun.facelets.tag.jsf.ValidatorConfig;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class BeanValidatorHandler extends ValidateHandler {
+
+
+ private TagAttribute _profiles;
+
+
+
+ /**
+ * @param config
+ */
+ public BeanValidatorHandler(ValidatorConfig config) {
+ super(config);
+ _profiles = getAttribute("profiles");
+ }
+
+ @Override
+ protected Validator createValidator(FaceletContext ctx) {
+ FacesBeanValidator validator = (FacesBeanValidator) ctx.getFacesContext()
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ if(null != _profiles){
+ if(_profiles.isLiteral()){
+ validator.setProfiles(AjaxRendererUtils.asSet(_profiles.getValue()));
+ } else {
+ validator.setProfiles(_profiles.getValueExpression(ctx, Set.class));
+ }
+ }
+ return validator;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,139 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.taglib;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.servlet.jsp.JspException;
+
+import org.richfaces.validator.HibernateValidator;
+import org.richfaces.validator.FacesBeanValidator;
+
+public class BeanValidatorTag extends javax.faces.webapp.ValidatorELTag {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5230299574915210593L;
+ // Fields
+
+ /*
+ * summary Summary message for a validation errors.
+ */
+ private ValueExpression _summary;
+
+ /**
+ * <p>The {@link javax.el.ValueExpression} that evaluates to an object that
+ * implements {@link HibernateValidator}.</p>
+ */
+ private ValueExpression binding = null;
+
+
+ private ValueExpression profiles = null;
+
+ /**
+ * Summary message for a validation errors. Setter for summary
+ *
+ * @param summary
+ * - new value
+ */
+ public void setSummary(ValueExpression __summary) {
+ this._summary = __summary;
+ }
+
+ /**
+ * <p>Set the expression that will be used to create a
+ * {@link javax.el.ValueExpression} that references a backing bean property
+ * of the {@link HibernateValidator} instance to be created.</p>
+ *
+ * @param binding The new expression
+ */
+ public void setBinding(ValueExpression binding) {
+ this.binding = binding;
+ }
+
+ /**
+ * @param profiles the profiles to set
+ */
+ public void setProfiles(ValueExpression profiles) {
+ this.profiles = profiles;
+ }
+
+ protected Validator createValidator() throws JspException {
+ ValueExpression ve = this.binding;
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ FacesBeanValidator validator = null;
+
+ try {
+ ELContext elContext = facesContext.getELContext();
+ if (ve != null) {
+ validator = (FacesBeanValidator) ve.getValue(elContext);
+ }
+
+ if (validator == null) {
+ validator = (FacesBeanValidator) FacesContext
+ .getCurrentInstance().getApplication().createValidator(
+ "org.richfaces.BeanValidator");
+
+ if (ve != null && validator != null) {
+ ve.setValue(elContext, validator);
+ }
+ }
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ _setProperties(validator);
+
+ return validator;
+ }
+
+ @Override
+ public void release() {
+ this.binding = null;
+ this._summary = null;
+ this.profiles = null;
+ super.release();
+ }
+ // Support method to wire in properties
+ private void _setProperties(FacesBeanValidator validator)
+ throws JspException {
+ if (_summary != null) {
+ if (_summary.isLiteralText()) {
+ validator.setSummary(_summary.getExpressionString());
+ } else {
+ validator.setSummary(_summary);
+ }
+ }
+ if(null != profiles){
+ if(profiles.isLiteralText()){
+ validator.setProfiles(profiles.getExpressionString());
+ } else {
+ validator.setProfiles(profiles);
+ }
+ }
+ }
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java (rev 0)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java 2010-09-14 22:30:39 UTC (rev 19206)
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package org.richfaces.taglib;
+
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.richfaces.component.UIGraphValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+import com.sun.facelets.tag.jsf.ComponentHandler;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class GraphValidatorHandler extends ComponentHandler {
+
+ private TagAttribute _profiles;
+
+ /**
+ * @param config
+ */
+ public GraphValidatorHandler(ComponentConfig config) {
+ super(config);
+ _profiles = getAttribute("profiles");
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ return super.createMetaRuleset(type).ignore("profiles");
+ }
+
+
+ @Override
+ protected void onComponentCreated(FaceletContext ctx, UIComponent c,
+ UIComponent parent) {
+ super.onComponentCreated(ctx, c, parent);
+ if (c instanceof UIGraphValidator) {
+ UIGraphValidator graphValidator = (UIGraphValidator) c;
+ if(null != _profiles){
+ if (_profiles.isLiteral()) {
+ graphValidator.setProfiles(AjaxRendererUtils.asSet(_profiles.getValue()));
+ } else {
+ graphValidator.setValueExpression("profiles", _profiles.getValueExpression(ctx, Set.class));
+ }
+ }
+
+ }
+ }
+}
Property changes on: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 3 months