Author: alexsmirnov
Date: 2008-07-14 20:00:44 -0400 (Mon, 14 Jul 2008)
New Revision: 9587
Added:
trunk/samples/beanValidatorSample/src/main/resources/logging.properties
trunk/ui/beanValidator/src/main/config/faces/
trunk/ui/beanValidator/src/main/config/faces/standart-components.xml
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputTextarea.java
Modified:
trunk/samples/beanValidatorSample/pom.xml
trunk/samples/beanValidatorSample/src/main/java/org/richfaces/DataBean.java
trunk/samples/beanValidatorSample/src/main/webapp/WEB-INF/web.xml
trunk/samples/beanValidatorSample/src/main/webapp/index.jsp
trunk/samples/beanValidatorSample/src/main/webapp/pages/index.jsp
trunk/samples/beanValidatorSample/src/main/webapp/pages/index.xhtml
trunk/ui/beanValidator/pom.xml
trunk/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java
Log:
Beutify validator sample.
Create an "wrapper" versions of the standart HtmlInputtext and
HtmlInputTextarea.
Modified: trunk/samples/beanValidatorSample/pom.xml
===================================================================
--- trunk/samples/beanValidatorSample/pom.xml 2008-07-14 18:37:55 UTC (rev 9586)
+++ trunk/samples/beanValidatorSample/pom.xml 2008-07-15 00:00:44 UTC (rev 9587)
@@ -2,7 +2,7 @@
<project>
<parent>
<artifactId>samples</artifactId>
- <groupId>org.richfaces.sandbox</groupId>
+ <groupId>org.richfaces</groupId>
<version>3.2.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Modified: trunk/samples/beanValidatorSample/src/main/java/org/richfaces/DataBean.java
===================================================================
--- trunk/samples/beanValidatorSample/src/main/java/org/richfaces/DataBean.java 2008-07-14
18:37:55 UTC (rev 9586)
+++ trunk/samples/beanValidatorSample/src/main/java/org/richfaces/DataBean.java 2008-07-15
00:00:44 UTC (rev 9587)
@@ -10,187 +10,43 @@
import java.util.ListIterator;
import org.hibernate.validator.Max;
+import org.hibernate.validator.Valid;
/**
* @author asmirnov
*
*/
-public class DataBean implements List<Validable> {
+public class DataBean {
- private final List<Validable> backend;
+ private final List<Validable> beans;
+ /**
+ * @return the beans
+ */
+ @Valid
+ public List<Validable> getBeans() {
+ return beans;
+ }
+
public DataBean() {
- backend = new ArrayList<Validable>(6);
- backend.add(new NotNullBean());
- backend.add(new NotEmptyBean());
- backend.add(new LengthBean());
- backend.add(new MinBean());
- backend.add(new MaxBean());
- backend.add(new MinMaxBean());
+ beans = new ArrayList<Validable>(6);
+ beans.add(new NotNullBean());
+ beans.add(new NotEmptyBean());
+ beans.add(new LengthBean());
+ beans.add(new MinBean());
+ beans.add(new MaxBean());
+ beans.add(new MinMaxBean());
}
@Max(value=20,message="Total value should be less then 20")
public int getTotal(){
int total = 0;
- for (Validable bean : backend) {
+ for (Validable bean : beans) {
total += bean.getIntValue();
}
return total;
}
- /**
- * @param o
- * @return
- * @see java.util.List#contains(java.lang.Object)
- */
- public boolean contains(Object o) {
- return backend.contains(o);
- }
- /**
- * @param c
- * @return
- * @see java.util.List#containsAll(java.util.Collection)
- */
- public boolean containsAll(Collection<?> c) {
- return backend.containsAll(c);
- }
- /**
- * @param index
- * @return
- * @see java.util.List#get(int)
- */
- public Validable get(int index) {
- return backend.get(index);
- }
- /**
- * @param o
- * @return
- * @see java.util.List#indexOf(java.lang.Object)
- */
- public int indexOf(Object o) {
- return backend.indexOf(o);
- }
-
- /**
- * @return
- * @see java.util.List#isEmpty()
- */
- public boolean isEmpty() {
- return backend.isEmpty();
- }
-
- /**
- * @return
- * @see java.util.List#iterator()
- */
- public Iterator<Validable> iterator() {
- return backend.iterator();
- }
-
- /**
- * @param o
- * @return
- * @see java.util.List#lastIndexOf(java.lang.Object)
- */
- public int lastIndexOf(Object o) {
- return backend.lastIndexOf(o);
- }
-
- /**
- * @return
- * @see java.util.List#listIterator()
- */
- public ListIterator<Validable> listIterator() {
- return backend.listIterator();
- }
-
- /**
- * @param index
- * @return
- * @see java.util.List#listIterator(int)
- */
- public ListIterator<Validable> listIterator(int index) {
- return backend.listIterator(index);
- }
-
- /**
- * @return
- * @see java.util.List#size()
- */
- public int size() {
- return backend.size();
- }
-
- /**
- * @param fromIndex
- * @param toIndex
- * @return
- * @see java.util.List#subList(int, int)
- */
- public List<Validable> subList(int fromIndex, int toIndex) {
- return backend.subList(fromIndex, toIndex);
- }
-
- /**
- * @return
- * @see java.util.List#toArray()
- */
- public Object[] toArray() {
- return backend.toArray();
- }
-
- /**
- * @param <T>
- * @param a
- * @return
- * @see java.util.List#toArray(T[])
- */
- public <T> T[] toArray(T[] a) {
- return backend.toArray(a);
- }
-
- public boolean add(Validable o) {
- throw new IllegalAccessError();
- }
-
- public void add(int index, Validable element) {
- throw new IllegalAccessError();
- }
-
- public boolean addAll(Collection<? extends Validable> c) {
- throw new IllegalAccessError();
- }
-
- public boolean addAll(int index, Collection<? extends Validable> c) {
- throw new IllegalAccessError();
- }
-
- public void clear() {
- throw new IllegalAccessError();
- }
-
- public boolean remove(Object o) {
- throw new IllegalAccessError();
- }
-
- public Validable remove(int index) {
- throw new IllegalAccessError();
- }
-
- public boolean removeAll(Collection<?> c) {
- throw new IllegalAccessError();
- }
-
- public boolean retainAll(Collection<?> c) {
- throw new IllegalAccessError();
- }
-
- public Validable set(int index, Validable element) {
- throw new IllegalAccessError();
- }
-
-
-
}
Added: trunk/samples/beanValidatorSample/src/main/resources/logging.properties
===================================================================
--- trunk/samples/beanValidatorSample/src/main/resources/logging.properties
(rev 0)
+++ trunk/samples/beanValidatorSample/src/main/resources/logging.properties 2008-07-15
00:00:44 UTC (rev 9587)
@@ -0,0 +1,25 @@
+handlers org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+org.apache.juli.FileHandler.level ALL
+org.apache.juli.FileHandler.directory ${catalina.base}/logs
+org.apache.juli.FileHandler.prefix beanValidator.
+
+
+java.util.logging.ConsoleHandler.level ALL
+java.util.logging.ConsoleHandler.formatter java.util.logging.SimpleFormatter
+
+facelets.level=ALL
+com.sun.faces.level=ALL
+javax.faces.level=ALL
+org.apache.myfaces.level=INFO
+org.ajax4jsf.io.level=ERROR
+org.ajax4jsf.webapp.level=ALL
+org.ajax4jsf.application.level=ALL
+org.ajax4jsf.context.level=ALL
+javax.enterprise.resource.webcontainer.jsf.level=ALL
+org.richfaces.level=ALL
+
\ No newline at end of file
Property changes on:
trunk/samples/beanValidatorSample/src/main/resources/logging.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/samples/beanValidatorSample/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/beanValidatorSample/src/main/webapp/WEB-INF/web.xml 2008-07-14 18:37:55
UTC (rev 9586)
+++ trunk/samples/beanValidatorSample/src/main/webapp/WEB-INF/web.xml 2008-07-15 00:00:44
UTC (rev 9587)
@@ -1,40 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>Archetype Created Web Application</display-name>
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
- <param-value>server</param-value>
- </context-param>
- <!--
- -->
- <filter>
- <display-name>Ajax4jsf Filter</display-name>
- <filter-name>ajax4jsf</filter-name>
- <filter-class>org.ajax4jsf.Filter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>ajax4jsf</filter-name>
- <servlet-name>Faces Servlet</servlet-name>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>INCLUDE</dispatcher>
- <dispatcher>ERROR</dispatcher>
- </filter-mapping>
- <servlet>
- <servlet-name>Faces Servlet</servlet-name>
- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>/faces/*</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>*.jsf</url-pattern>
- </servlet-mapping>
- <login-config>
- <auth-method>BASIC</auth-method>
- </login-config>
-</web-app>
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>Archetype Created Web Application</display-name>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>server</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.ajax4jsf.SKIN</param-name>
+ <param-value>classic</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.richfaces.CONTROL_SKINNING</param-name>
+ <param-value>enable</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
+ <param-value>com.sun.facelets.FaceletViewHandler</param-value>
+ </context-param>
+ <context-param>
+ <param-name>facelets.VIEW_MAPPINGS</param-name>
+ <param-value>*.xhtml</param-value>
+ </context-param>
+ <!--
+ -->
+ <filter>
+ <display-name>Ajax4jsf Filter</display-name>
+ <filter-name>ajax4jsf</filter-name>
+ <filter-class>org.ajax4jsf.Filter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ajax4jsf</filter-name>
+ <servlet-name>Faces Servlet</servlet-name>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ </login-config>
+</web-app>
\ No newline at end of file
Modified: trunk/samples/beanValidatorSample/src/main/webapp/index.jsp
===================================================================
--- trunk/samples/beanValidatorSample/src/main/webapp/index.jsp 2008-07-14 18:37:55 UTC
(rev 9586)
+++ trunk/samples/beanValidatorSample/src/main/webapp/index.jsp 2008-07-15 00:00:44 UTC
(rev 9587)
@@ -5,7 +5,7 @@
<head></head>
<body>
- <jsp:forward page="/pages/index.jsf" />
+ <jsp:forward page="/faces/pages/index.xhtml" />
</body>
</html>
\ No newline at end of file
Modified: trunk/samples/beanValidatorSample/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/samples/beanValidatorSample/src/main/webapp/pages/index.jsp 2008-07-14 18:37:55
UTC (rev 9586)
+++ trunk/samples/beanValidatorSample/src/main/webapp/pages/index.jsp 2008-07-15 00:00:44
UTC (rev 9587)
@@ -1,7 +1,7 @@
<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib
-
uri="http://labs.jboss.com/jbossrichfaces/ui/ui/beanValidator"
+
uri="http://labs.jboss.com/jbossrichfaces/ui/beanValidator"
prefix="v"%>
<%@taglib
uri="http://richfaces.org/rich" prefix="rich"%>
<%@taglib prefix="a4j"
uri="http://richfaces.org/a4j"%>
@@ -11,12 +11,11 @@
</head>
<body>
<h1>Using Hibernate validator annotations in the JSF beans</h1>
-<p>Validation requests send as AJAX from "onblur" event</p>
<f:view>
<h:form id="form">
<rich:panel>
<f:facet name="header">
- <h2>Single input field with label and message. Validated by AJAX on every
char.</h2>
+ <h:outputText>Single input field with label and message. Validated by AJAX on
every char.</h:outputText>
</f:facet>
<h:outputLabel for="ltext"
value="#{lengthBean.textDescription}" />
<h:inputText id="ltext" value="#{lengthBean.text}">
@@ -26,7 +25,7 @@
</rich:panel>
<h2>Input fields with label and message in the JSF dataTable. Each field
validated by AJAX on "onblur" event</h2>
<v:graphValidator value="#{data}" >
- <h:dataTable value="#{data}" var="bean"
id="table">
+ <rich:dataTable value="#{data.beans}" var="bean"
id="table">
<f:facet name="header">
<h:outputText value="Validate values in the data table. Total sum for an all
integer values validated for a value less then 20" />
</f:facet>
@@ -51,9 +50,14 @@
</h:inputText>
<rich:message for="intValue" showDetail="true"
showSummary="true" />
</h:column>
- </h:dataTable>
+ <f:facet name="footer">
+ <h:panelGroup>
+ <h:outputText>in addition to fields validation, total sum for an all integer
values validated for a value less then 20.</h:outputText>
+ <h:commandButton value="Submit all fields"></h:commandButton>
+ </h:panelGroup>
+ </f:facet>
+ </rich:dataTable>
</v:graphValidator>
- <h:commandButton value="Non-AJAX Post submit"></h:commandButton>
</h:form>
<rich:messages />
</f:view>
Modified: trunk/samples/beanValidatorSample/src/main/webapp/pages/index.xhtml
===================================================================
--- trunk/samples/beanValidatorSample/src/main/webapp/pages/index.xhtml 2008-07-14
18:37:55 UTC (rev 9586)
+++ trunk/samples/beanValidatorSample/src/main/webapp/pages/index.xhtml 2008-07-15
00:00:44 UTC (rev 9587)
@@ -4,9 +4,64 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
-
xmlns:c="http://java.sun.com/jsp/jstl/core"
+
xmlns:c="http://java.sun.com/jsp/jstl/core"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:v="http://labs.jboss.com/jbossrichfaces/ui/beanValidator"
- <f:view>
+<head>
+<title>Hibernate validator test</title>
+</head>
+<body>
+<h1>Using Hibernate validator annotations in the JSF beans</h1>
+<f:view>
+ <h:form id="form">
+ <rich:panel>
+ <f:facet name="header">
+ <h:outputText>Single input field with label and message. Validated by AJAX on
every char.</h:outputText>
+ </f:facet>
+ <h:outputLabel for="ltext"
value="#{lengthBean.textDescription}" />
+ <h:inputText id="ltext" value="#{lengthBean.text}">
+ <v:ajaxValidator event="onkeyup" />
+ </h:inputText>
+ <rich:message for="ltext" showDetail="true"
showSummary="true" />
+ </rich:panel>
+ <h2>Input fields with label and message in the JSF dataTable. Each field
validated by AJAX on 'onblur' event</h2>
+ <v:graphValidator value="#{data}" >
+ <rich:dataTable value="#{data.beans}" var="bean"
id="table">
+ <f:facet name="header">
+ <h:outputText value="Validate values in the data table. Total sum for an all
integer values validated for a value less then 20" />
+ </f:facet>
- </f:view>
-</html>
\ No newline at end of file
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="text field" />
+ </f:facet>
+ <h:outputLabel for="text" value="#{bean.textDescription}"
/>
+ <h:inputText id="text" value="#{bean.text}">
+ <v:ajaxValidator event="onblur" />
+ </h:inputText>
+ <rich:message for="text" showDetail="true"
showSummary="true" />
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="integer field" />
+ </f:facet>
+ <h:outputLabel for="intValue" value="#{bean.intDescription}"
/>
+ <h:inputText id="intValue" value="#{bean.intValue}">
+ <v:ajaxValidator event="onblur" />
+ </h:inputText>
+ <rich:message for="intValue" showDetail="true"
showSummary="true" />
+ </h:column>
+ <f:facet name="footer">
+ <h:panelGroup>
+ <h:outputText>in addition to fields validation, total sum for an all integer
values validated for a value less then 20.</h:outputText>
+ <h:commandButton value="Submit all fields"></h:commandButton>
+ </h:panelGroup>
+ </f:facet>
+ </rich:dataTable>
+ </v:graphValidator>
+ </h:form>
+ <rich:messages />
+</f:view>
+</body>
+</html>
Modified: trunk/ui/beanValidator/pom.xml
===================================================================
--- trunk/ui/beanValidator/pom.xml 2008-07-14 18:37:55 UTC (rev 9586)
+++ trunk/ui/beanValidator/pom.xml 2008-07-15 00:00:44 UTC (rev 9587)
@@ -2,7 +2,7 @@
<project>
<parent>
<artifactId>ui</artifactId>
- <groupId>org.richfaces.sandbox</groupId>
+ <groupId>org.richfaces</groupId>
<version>3.2.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Added: trunk/ui/beanValidator/src/main/config/faces/standart-components.xml
===================================================================
--- trunk/ui/beanValidator/src/main/config/faces/standart-components.xml
(rev 0)
+++ trunk/ui/beanValidator/src/main/config/faces/standart-components.xml 2008-07-15
00:00:44 UTC (rev 9587)
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
+ <component>
+ <description><![CDATA[<p>Represents an HTML
<code>input</code> element
+ of type <code>text</code>.</p>]]></description>
+ <display-name>Input Text</display-name>
+ <component-type>javax.faces.HtmlInputText</component-type>
+
<component-class>org.richfaces.component.html.HtmlInputText</component-class>
+ </component>
+ <component>
+ <description><![CDATA[<p>Represents an HTML
<code>textarea</code> element.</p>]]></description>
+ <display-name>Input Textarea</display-name>
+ <component-type>javax.faces.HtmlInputTextarea</component-type>
+
<component-class>org.richfaces.component.html.HtmlInputTextarea</component-class>
+
+ </component>
+</faces-config>
\ No newline at end of file
Property changes on: trunk/ui/beanValidator/src/main/config/faces/standart-components.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java
===================================================================
---
trunk/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java 2008-07-14
18:37:55 UTC (rev 9586)
+++
trunk/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java 2008-07-15
00:00:44 UTC (rev 9587)
@@ -54,7 +54,7 @@
public void setParent(UIComponent parent) {
super.setParent(parent);
- if (null != parent) {
+ if (null != parent && parent instanceof EditableValueHolder) {
setParentProperties(parent);
}
}
Added:
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java
===================================================================
--- trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java
(rev 0)
+++
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java 2008-07-15
00:00:44 UTC (rev 9587)
@@ -0,0 +1,81 @@
+/**
+ *
+ */
+package org.richfaces.component.html;
+
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.richfaces.validator.FacesBeanValidator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class HtmlInputText extends javax.faces.component.html.HtmlInputText {
+
+ @Override
+ protected void validateValue(FacesContext context, Object newValue) {
+ // If our value is valid, enforce the required property if present
+ if (isValid() && isRequired() && isEmpty(newValue)) {
+ super.validateValue(context, newValue);
+ }
+ // If our value is valid and not empty, call all validators
+ if (isValid()) {
+ Validator[] validators = this.getValidators();
+ if (validators != null) {
+ for (Validator validator : validators) {
+ try {
+ if (validator instanceof FacesBeanValidator
+ || !isEmpty(newValue)) {
+ validator.validate(context, this, newValue);
+ }
+ } catch (ValidatorException ve) {
+ // If the validator throws an exception, we're
+ // invalid, and we need to add a message
+ setValid(false);
+ FacesMessage message;
+ String validatorMessageString = getValidatorMessage();
+
+ if (null != validatorMessageString) {
+ message = new FacesMessage(
+ FacesMessage.SEVERITY_ERROR,
+ validatorMessageString,
+ validatorMessageString);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ } else {
+ message = ve.getFacesMessage();
+ }
+ if (message != null) {
+ context.addMessage(getClientId(context), message);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ private static boolean isEmpty(Object value) {
+
+ if (value == null) {
+ return (true);
+ } else if ((value instanceof String) && (((String) value).length() < 1)) {
+ return (true);
+ } else if (value.getClass().isArray()) {
+ if (0 == java.lang.reflect.Array.getLength(value)) {
+ return (true);
+ }
+ } else if (value instanceof List) {
+ if (((List) value).isEmpty()) {
+ return (true);
+ }
+ }
+ return (false);
+ }
+
+}
Property changes on:
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputTextarea.java
===================================================================
---
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputTextarea.java
(rev 0)
+++
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputTextarea.java 2008-07-15
00:00:44 UTC (rev 9587)
@@ -0,0 +1,81 @@
+/**
+ *
+ */
+package org.richfaces.component.html;
+
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.richfaces.validator.FacesBeanValidator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class HtmlInputTextarea extends javax.faces.component.html.HtmlInputText {
+
+ @Override
+ protected void validateValue(FacesContext context, Object newValue) {
+ // If our value is valid, enforce the required property if present
+ if (isValid() && isRequired() && isEmpty(newValue)) {
+ super.validateValue(context, newValue);
+ }
+ // If our value is valid and not empty, call all validators
+ if (isValid()) {
+ Validator[] validators = this.getValidators();
+ if (validators != null) {
+ for (Validator validator : validators) {
+ try {
+ if (validator instanceof FacesBeanValidator
+ || !isEmpty(newValue)) {
+ validator.validate(context, this, newValue);
+ }
+ } catch (ValidatorException ve) {
+ // If the validator throws an exception, we're
+ // invalid, and we need to add a message
+ setValid(false);
+ FacesMessage message;
+ String validatorMessageString = getValidatorMessage();
+
+ if (null != validatorMessageString) {
+ message = new FacesMessage(
+ FacesMessage.SEVERITY_ERROR,
+ validatorMessageString,
+ validatorMessageString);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ } else {
+ message = ve.getFacesMessage();
+ }
+ if (message != null) {
+ context.addMessage(getClientId(context), message);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ private static boolean isEmpty(Object value) {
+
+ if (value == null) {
+ return (true);
+ } else if ((value instanceof String) && (((String) value).length() < 1)) {
+ return (true);
+ } else if (value.getClass().isArray()) {
+ if (0 == java.lang.reflect.Array.getLength(value)) {
+ return (true);
+ }
+ } else if (value instanceof List) {
+ if (((List) value).isEmpty()) {
+ return (true);
+ }
+ }
+ return (false);
+ }
+
+}
Property changes on:
trunk/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputTextarea.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain