Author: jjamrich
Date: 2011-07-20 08:09:46 -0400 (Wed, 20 Jul 2011)
New Revision: 22558
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/single.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richValidator/TestWrappingValidatorSingle.java
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/list.xhtml
Log:
Add example of simple number input validated on client side
There is suspect that even validators based on javax.validation package
should provide capabilities to perform validation on client side, it in
fact doesn't. Prepared simple page with single input validated acoording
to JSR303 on backing bean, and surrounded by rich:validator, expecting
to achieve client side validation without request to server in case of
incoirrect input.
https://issues.jboss.org/browse/RF-11139
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/list.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/list.xhtml 2011-07-20
10:21:07 UTC (rev 22557)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/list.xhtml 2011-07-20
12:09:46 UTC (rev 22558)
@@ -42,6 +42,10 @@
<metamer:testPageLink id="wrapping" outcome="wrapping"
value="Client side validation for many inputs wrapped by rich:validator">
Simple page that contains many inputs within
<b>rich:validator</b>
</metamer:testPageLink>
+
+ <metamer:testPageLink id="single" outcome="single"
value="Client side validation for only one input component wrapped by
rich:validator">
+ Simple page that contains simple inputs within
<b>rich:validator</b>
+ </metamer:testPageLink>
</ui:define>
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/single.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/single.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richValidator/single.xhtml 2011-07-20
12:09:46 UTC (rev 22558)
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
+
xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="head">
+ <style type="text/css">
+ .rf-msg-err {
+ display: block !important;
+ margin-bottom: 6px;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ var today = new Date();
+ var inPast = new Date(today.getTime() - 4 * 24 * 3600 * 1000);
+ var inFuture = new Date(today.getTime() + 4 * 24 * 3600 * 1000);
+
+ $('input[id$=assertTrue]')[0].checked = true;
+ $('input[id$=assertFalse]')[0].checked = false;
+ $('input[id$=decimalMinMax]').val('3');
+ $('input[id$=digits]').val('2.567');
+ $('input[id$=max]').val('9');
+ $('input[id$=min]').val('4');
+ $('input[id$=minMax]').val('4');
+ $('input[id$=notEmpty]').val('RichFaces 4');
+ $('input[id$=notNull]').val('RichFaces 4');
+ $('input[id$=pattern]').val('richFaces 4');
+ $('input[id$=regexp]').val('100');
+ $('input[id$=custom]').val('RichFaces');
+ $('input[id$=past]').val(inPast.format("d mmm yyyy"));
+ $('input[id$=future]').val(inFuture.format("d mmm
yyyy"));
+ $('input[id$=stringSize]').val('JSF');
+ $('input[value=A]')[0].checked=true
+ $('input[value=B]')[0].checked=true
+ $('input[value=C]')[0].checked=false
+ $('input[value=D]')[0].checked=false
+ $('input[value=E]')[0].checked=false
+ $('input[value=F]')[0].checked=false
+ }
+
+ function setWrongValues() {
+ var today = new Date();
+ var inPast = new Date(today.getTime() - 4 * 24 * 3600 * 1000);
+ var inFuture = new Date(today.getTime() + 4 * 24 * 3600 * 1000);
+
+ $('input[id$=assertTrue]')[0].checked = false;
+ $('input[id$=assertFalse]')[0].checked = true;
+ $('input[id$=decimalMinMax]').val('10.668');
+ $('input[id$=digits]').val('15.627123');
+ $('input[id$=max]').val('122');
+ $('input[id$=min]').val('-544');
+ $('input[id$=minMax]').val('-5');
+ $('input[id$=notEmpty]').val('');
+ $('input[id$=notNull]').val('');
+ $('input[id$=pattern]').val('@@@');
+ $('input[id$=regexp]').val('@@@');
+ $('input[id$=custom]').val('@@@');
+ $('input[id$=past]').val(inFuture.format("d mmm
yyyy"));
+ $('input[id$=future]').val(inPast.format("d mmm
yyyy"));
+ $('input[id$=stringSize]').val('JSF 2');
+ $('input[value=A]')[0].checked=false
+ $('input[value=B]')[0].checked=false
+ $('input[value=C]')[0].checked=false
+ $('input[value=D]')[0].checked=false
+ $('input[value=E]')[0].checked=false
+ $('input[value=F]')[0].checked=true
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button"
value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button"
value="set wrong values" onclick="setWrongValues()"/>
+
+ <h:panelGrid columns="3">
+
+ <rich:validator
data="#{richValidatorBean.attributes['data'].value}"
+
disabled="#{richValidatorBean.attributes['disabled'].value}"
+
immediate="#{richValidatorBean.attributes['immediate'].value}"
+
onbeforedomupdate="#{richValidatorBean.attributes['onbeforedomupdate'].value}"
+
onbeforesubmit="#{richValidatorBean.attributes['onbeforesubmit'].value}"
+
onbegin="#{richValidatorBean.attributes['onbegin'].value}"
+
oncomplete="#{richValidatorBean.attributes['oncomplete'].value}"
+
onerror="#{richValidatorBean.attributes['onerror'].value}"
+
queueId="#{richValidatorBean.attributes['queueId'].value}"
+
status="#{richValidatorBean.attributes['status'].value}"
+ >
+
+ <h:outputLabel for="min"
value="#{minBean.description}" />
+ <h:inputText id="min" value="#{minBean.value}"
label="#{minBean.label}" converter="#{minBean.converter}" />
+ <rich:message id="minMsg" for="min" />
+
+
+ </rich:validator>
+
+ </h:panelGrid>
+
+ <br/>
+
+ <h:commandButton id="hButton" value="h:commandButton"
style="margin-right: 10px;"/>
+ <a4j:commandButton id="a4jButton"
value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richValidatorBean.attributes}"
id="attributes"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richValidator/TestWrappingValidatorSingle.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richValidator/TestWrappingValidatorSingle.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richValidator/TestWrappingValidatorSingle.java 2011-07-20
12:09:46 UTC (rev 22558)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.tests.metamer.ftest.richValidator;
+
+import static
org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.utils.URLUtils;
+import org.testng.annotations.Test;
+
+/**
+ * Selenium tests for page faces/components/richValidator/single.xhtml
+ *
+ * Test no-request handling client side validation.
+ * Validation for min is done by javax.validation.constraints.Min, and this should
completely
+ * handle validation on client side.
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+public class TestWrappingValidatorSingle extends AbstractValidatorsTest {
+
+ /** component page locator */
+ @Override
+ public URL getTestUrl() {
+ return URLUtils.buildUrl(contextPath,
"faces/components/richValidator/single.xhtml");
+ }
+
+ @Test
+ public void testIntegerMin() {
+ selenium.click(pjq("input[id$=setCorrectValuesButton]"));
+
+ // integer input min
+ selenium.type(pjq("input[id$=:min]"), "-544");
+ guardNoRequest(selenium).click(pjq("input[id$=a4jButton]"));
+
+ waitGui.until(textEquals.locator(pjq("span[id$=minMsg]
span.rf-msg-det"))
+ .text("must be greater than or equal to 2"));
+ }
+
+}