Author: alexsmirnov
Date: 2010-12-17 19:11:17 -0500 (Fri, 17 Dec 2010)
New Revision: 20674
Added:
branches/RF-7654/core/api/src/main/java/org/ajax4jsf/javascript/JSWithDependencies.java
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java
Modified:
branches/RF-7654/core/impl/src/main/java/org/richfaces/component/UIScripts.java
branches/RF-7654/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js
branches/RF-7654/ui/validator/ui/src/main/templates/message.template.xml
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
Log:
CODING IN PROGRESS - issue RF-7654: rich:message/rich:messages
https://issues.jboss.org/browse/RF-7654
Added:
branches/RF-7654/core/api/src/main/java/org/ajax4jsf/javascript/JSWithDependencies.java
===================================================================
---
branches/RF-7654/core/api/src/main/java/org/ajax4jsf/javascript/JSWithDependencies.java
(rev 0)
+++
branches/RF-7654/core/api/src/main/java/org/ajax4jsf/javascript/JSWithDependencies.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -0,0 +1,66 @@
+/*
+ * $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.ajax4jsf.javascript;
+
+import java.io.IOException;
+
+import org.richfaces.resource.ResourceKey;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * <p class="changed_added_4_0">Wrapper object that adds dependencies to
any object whether it implements {@link ScriptString} or not.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class JSWithDependencies extends ScriptStringBase implements
ScriptWithDependencies {
+
+ private final Iterable<ResourceKey> resources;
+
+ private final Object wrapped;
+
+ public JSWithDependencies(Object wrapped,Iterable<ResourceKey> resources) {
+ this.wrapped = wrapped;
+ this.resources = ImmutableList.copyOf(resources);
+ }
+
+ public JSWithDependencies(Object wrapped,ResourceKey... resources) {
+ this.wrapped = wrapped;
+ this.resources = ImmutableList.copyOf(resources);
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.resource.ResourceLibrary#getResources()
+ */
+ public Iterable<ResourceKey> getResources() {
+ return resources;
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.javascript.ScriptString#appendScript(java.lang.Appendable)
+ */
+ public void appendScript(Appendable target) throws IOException {
+ ScriptUtils.appendScript(target, wrapped);
+ }
+
+}
Modified: branches/RF-7654/core/impl/src/main/java/org/richfaces/component/UIScripts.java
===================================================================
---
branches/RF-7654/core/impl/src/main/java/org/richfaces/component/UIScripts.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/core/impl/src/main/java/org/richfaces/component/UIScripts.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -50,7 +50,7 @@
private final List<Object> pageReadyScripts = Lists.newArrayList();
- private String target = "form";
+ private String target = "body";
/* (non-Javadoc)
* @see org.richfaces.component.ScriptsHolder#getScripts()
Modified:
branches/RF-7654/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java
===================================================================
---
branches/RF-7654/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -29,10 +29,12 @@
"<html
xmlns=\"http://www.w3.org/1999/xhtml\"\n" +
"
xmlns:ui=\"http://java.sun.com/jsf/facelets\"\n" +
"
xmlns:h=\"http://java.sun.com/jsf/html\">"+
+ "<h:body>\n"+
"<h:form id=\"helloForm\" >"+
" <h:inputText id=\"input\"
value=\"#{test.value}\" />\n" +
" <h:commandButton id=\"command\"
value=\"Ok\" action=\"#{test.action}\"/>\n" +
"</h:form>\n" +
+ "</h:body>\n" +
"</html>").
withResource(FacesEnvironment.FACES_CONFIG_XML,
"org/richfaces/component/faces-config.xml").
start();
Modified:
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -33,9 +33,14 @@
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSObject;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.javascript.JavaScriptService;
import org.richfaces.renderkit.util.RendererUtils;
import com.google.common.base.Predicate;
+import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
@@ -52,15 +57,13 @@
private static final ImmutableMap<Severity, SeverityAttributes> SEVERITY_MAP =
ImmutableMap
.of(FacesMessage.SEVERITY_INFO,
- attrs("infoStyle", "infoClass",
"infoMarkerStyle", "infoMarkerClass", "infoLabelStyle",
"infoLabelClass"),
+ attrs("info", "inf", null),
FacesMessage.SEVERITY_WARN,
- attrs("warnStyle", "warnClass",
"warnMarkerStyle", "warnMarkerClass", "warnLabelStyle",
"warnLabelClass"),
+ attrs("warn","wrn", null),
FacesMessage.SEVERITY_ERROR,
- attrs("errorStyle", "errorClass",
"errorMarkerStyle", "errorMarkerClass", "errorLabelStyle",
- "errorLabelClass"),
+ attrs("error","err", null),
FacesMessage.SEVERITY_FATAL,
- attrs("fatalStyle", "fatalClass",
"fatalMarkerStyle", "fatalMarkerClass", "fatalLabelStyle",
- "fatalLabelClass"));
+ attrs("fatal","ftl",null));
protected Iterator<FacesMessage> getMessages(FacesContext context, String
forClientId, UIComponent component) {
@@ -127,19 +130,58 @@
responseWriter.writeText(message.getSummary(),"value");
}
- static SeverityAttributes attrs(String styleAttribute, String classAttribute, String
markerStyleAttribute,
- String markerClassAttribute, String labelStyleAttribute, String
labelClassAttribute) {
+ protected void encodeScript(FacesContext facesContext, UIComponent component) throws
IOException {
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
+ JSFunction messageObject = new JSObject("RichFaces.ui.Message",
component.getClientId(facesContext));
+ String forId = (String) component.getAttributes().get("for");
+ if(!Strings.isNullOrEmpty(forId)){
+ UIComponent target = RendererUtils.getInstance().findComponentFor(component,
forId);
+ if(null != target){
+ messageObject.addParameter(ImmutableMap.<String,
String>of("forComponentId",target.getClientId(facesContext)));
+ }
+ }
+// RendererUtils.getInstance().writeScript(facesContext, component,
messageObject);
+ javaScriptService.addPageReadyScript(facesContext, messageObject);
+ }
+
+ protected String getMsgClass(FacesContext facesContext, UIComponent component, Object
msg) throws IOException{
+ FacesMessage message = (FacesMessage) msg;
+ SeverityAttributes severityAttributes = SEVERITY_MAP.get(message.getSeverity());
+ String styleClass = buildSeverityAttribute(component,
severityAttributes.skinClass, severityAttributes.classAttribute, ' ');
+ return styleClass;
+ }
+
+ protected String getMsgStyle(FacesContext facesContext, UIComponent component, Object
msg) throws IOException{
+ FacesMessage message = (FacesMessage) msg;
+ SeverityAttributes severityAttributes = SEVERITY_MAP.get(message.getSeverity());
+ String style = buildSeverityAttribute(component, severityAttributes.skinStyle,
severityAttributes.styleAttribute, ';');
+ return style;
+ }
+
+ private String buildSeverityAttribute(UIComponent component, String skinValue, String
attrName, char delimiter) {
+ StringBuilder style = new StringBuilder();
+ if(null != skinValue){
+ style.append(skinValue).append(delimiter);
+ }
+ Object componentStyle = component.getAttributes().get(attrName);
+ if(null != componentStyle){
+ style.append(componentStyle);
+ }
+ return style.toString();
+ }
+
+ static SeverityAttributes attrs(String attPrefix, String skinSuffix,String skinStyle)
{
SeverityAttributes attrs =
- new SeverityAttributes(styleAttribute, classAttribute, markerStyleAttribute,
markerClassAttribute,
- labelStyleAttribute, labelClassAttribute);
+ new SeverityAttributes(attPrefix+"Style",
attPrefix+"Class", "rf-msg-"+skinSuffix, skinStyle,
+ null, null);
return attrs;
}
private static final class SeverityAttributes {
private final String styleAttribute;
private final String classAttribute;
- private final String markerStyleAttribute;
- private final String markerClassAttribute;
+ private final String skinStyle;
+ private final String skinClass;
private final String labelStyleAttribute;
private final String labelClassAttribute;
@@ -147,8 +189,8 @@
String markerClassAttribute2, String labelStyleAttribute2, String
labelClassAttribute2) {
this.styleAttribute = styleAttribute2;
this.classAttribute = classAttribute2;
- this.markerStyleAttribute = markerStyleAttribute2;
- this.markerClassAttribute = markerClassAttribute2;
+ this.skinStyle = markerStyleAttribute2;
+ this.skinClass = markerClassAttribute2;
this.labelStyleAttribute = labelStyleAttribute2;
this.labelClassAttribute = labelClassAttribute2;
}
Modified:
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -8,22 +8,22 @@
public abstract class ValidatorScriptBase extends JSFunctionDefinition implements
ComponentValidatorScript {
- protected static final String ELEMENT = "element";
- protected static final JSReference ELEMENT_LITERAL = new JSReference(ELEMENT);
- protected static final String EVENT = "event";
- protected static final JSReference EVENT_LITERAL = new JSReference(EVENT);
- protected static final String DISABLE_AJAX = "disableAjax";
- protected static final String EOL = ";\n";
- protected static final String CLIENT_ID = "clientId";
- protected static final JSReference CLIENT_ID_LITERAL = new JSReference(CLIENT_ID);
- protected static final String SOURCE_ID = "sourceId";
- protected static final JSReference SOURCE_ID_LITERAL = new JSReference(SOURCE_ID);
- protected static final NullConverterScript NULL_CONVERTER_SCRIPT = new
NullConverterScript();
- protected static final String CSV_NAMESPACE = "RichFaces.csv.";
- protected static final String VALUE_FUNCTION_NAME =
CSV_NAMESPACE+"getValue";
- protected static final JSFunction GET_VALUE_FUNCTION = new
JSFunction(VALUE_FUNCTION_NAME,CLIENT_ID_LITERAL,ELEMENT_LITERAL);
- protected static final JSFunction SEND_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"sendMessage",CLIENT_ID_LITERAL,new
JSReference("e"));
- protected static final JSFunction CLEAR_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"clearMessage",CLIENT_ID_LITERAL);
+ public static final String ELEMENT = "element";
+ public static final JSReference ELEMENT_LITERAL = new JSReference(ELEMENT);
+ public static final String EVENT = "event";
+ public static final JSReference EVENT_LITERAL = new JSReference(EVENT);
+ public static final String DISABLE_AJAX = "disableAjax";
+ public static final String EOL = ";\n";
+ public static final String CLIENT_ID = "clientId";
+ public static final JSReference CLIENT_ID_LITERAL = new JSReference(CLIENT_ID);
+ public static final String SOURCE_ID = "sourceId";
+ public static final JSReference SOURCE_ID_LITERAL = new JSReference(SOURCE_ID);
+ public static final NullConverterScript NULL_CONVERTER_SCRIPT = new
NullConverterScript();
+ public static final String CSV_NAMESPACE = "RichFaces.csv.";
+ public static final String VALUE_FUNCTION_NAME = CSV_NAMESPACE+"getValue";
+ public static final JSFunction GET_VALUE_FUNCTION = new
JSFunction(VALUE_FUNCTION_NAME,CLIENT_ID_LITERAL,ELEMENT_LITERAL);
+ public static final JSFunction SEND_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"sendMessage",CLIENT_ID_LITERAL,new
JSReference("e"));
+ public static final JSFunction CLEAR_ERROR_FUNCTION = new
JSFunction(CSV_NAMESPACE+"clearMessage",CLIENT_ID_LITERAL);
private boolean bodyProcessed = false;
Modified:
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js 2010-12-18
00:11:17 UTC (rev 20674)
@@ -54,16 +54,16 @@
if (!this.options.forComponentId) {
var index = componentHash[data.sourceId];
if (typeof index != undefined) {
- $(rf.getDomElement(this.id+":Content"+index)).remove();
+ $(rf.getDomElement(this.id+index)).remove();
}
- var content = content = $(rf.getDomElement(this.id+":Content"));
+ var content = content = $(rf.getDomElement(this.id));
componentIndex ++;
- if (data.message) content.append('<li
id="'+this.id+":Content"+componentIndex+'">'+data.message.summary+'</li>');
+ if (data.message) content.append('<li
id="'+this.id+componentIndex+'">'+data.message.summary+'</li>');
componentHash[data.sourceId] = componentIndex;
} else if (this.options.forComponentId==data.sourceId) {
- rf.getDomElement(this.id+":Content").innerHTML = data.message ?
'<li>'+data.message.summary+'</li>' : '';
+ rf.getDomElement(this.id).innerHTML = data.message ?
'<li>'+data.message.summary+'</li>' : '';
}
}
Added:
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties
(rev 0)
+++
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties 2010-12-18
00:11:17 UTC (rev 20674)
@@ -0,0 +1 @@
+resources=jquery.js, richfaces.js, richfaces-event.js, richfaces-base-component.js,
org.richfaces:message.js
\ No newline at end of file
Property changes on:
branches/RF-7654/ui/validator/ui/src/main/resources/META-INF/richfaces/org.richfaces/message.library.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/RF-7654/ui/validator/ui/src/main/templates/message.template.xml
===================================================================
--- branches/RF-7654/ui/validator/ui/src/main/templates/message.template.xml 2010-12-17
23:38:58 UTC (rev 20673)
+++ branches/RF-7654/ui/validator/ui/src/main/templates/message.template.xml 2010-12-18
00:11:17 UTC (rev 20674)
@@ -1,46 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
-JBoss, Home of Professional Open Source
-Copyright ${year}, 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.
--->
-<cdk:root
xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
-
xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite"
xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core"
-
xmlns:xi="http://www.w3.org/2001/XInclude">
+<!-- JBoss, Home of Professional Open Source Copyright ${year}, 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. -->
+<cdk:root
xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el"
+
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite"
+
xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core"
xmlns:xi="http://www.w3.org/2001/XInclude">
<cc:interface>
<cdk:class>org.richfaces.renderkit.html.HtmlMessageRenderer</cdk:class>
<cdk:superclass>org.richfaces.renderkit.MessageRendererBase</cdk:superclass>
<cdk:component-family>javax.faces.Message</cdk:component-family>
<cdk:renderer-type>org.richfaces.MessageRenderer</cdk:renderer-type>
- <cdk:resource-dependency library="org.richfaces"
name="base-component.reslib" />
- <cdk:resource-dependency library="org.richfaces"
name="message.js" />
+ <cdk:resource-dependency library="org.richfaces"
+ name="message.reslib" />
</cc:interface>
<cc:implementation>
- <span id="#{clientId}" class="rf-msg
#{component.attributes['styleClass']}" cdk:passThroughWithExclusions="id
class">
- <ul id="#{clientId}:Content" >
- <c:forEach var="msg"
items="#{getVisibleMessages(facesContext,component)}">
-
<li><cdk:call>encodeMessage(facesContext,component,msg)</cdk:call></li>
- </c:forEach>
- </ul>
- </span>
+ <ul id="#{clientId}" class="rf-msg
#{component.attributes['styleClass']}"
+ cdk:passThroughWithExclusions="id class">
+ <c:forEach var="msg"
+ items="#{getVisibleMessages(facesContext,component)}">
+ <li class="#{getMsgClass(facesContext,component,msg)}"
style="#{getMsgStyle(facesContext,component,msg)}">
+ <cdk:call>encodeMessage(facesContext,component,msg)</cdk:call>
+ </li>
+ </c:forEach>
+ <cdk:call>encodeScript(facesContext,component)</cdk:call>
+ </ul>
</cc:implementation>
</cdk:root>
Modified:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -44,7 +44,7 @@
@Test
public void testRequest() throws Exception {
HtmlPage page = requestPage();
- HtmlInput input = hetInput(page);
+ HtmlInput input = getInput(page);
assertNotNull(input);
}
@@ -66,14 +66,14 @@
private void submitValueAndCheckMesage(String value, Matcher<String> matcher)
throws Exception {
HtmlPage page = requestPage();
- HtmlInput input = hetInput(page);
+ HtmlInput input = getInput(page);
input.setValueAttribute(value);
- input.fireEvent("keyup");
- HtmlElement message = page.getElementById("form:message");
+ input.fireEvent("blur");
+ HtmlElement message = page.getElementById("form:uiMessage");
assertThat(message.getTextContent(), matcher);
// System.out.println(page.asXml());
}
- private HtmlInput hetInput(HtmlPage page) {
+ private HtmlInput getInput(HtmlPage page) {
HtmlForm htmlForm = page.getFormByName("form");
assertNotNull(htmlForm);
HtmlInput input = htmlForm.getInputByName("form:text");
@@ -82,7 +82,7 @@
private HtmlPage requestPage() throws MalformedURLException, IOException {
HtmlPage page = environment.getPage("/test.jsf");
-// System.out.println(page.asXml());
+ System.out.println(page.asXml());
return page;
}
Modified:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/component/ClientValidationTest.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -45,17 +45,17 @@
@Test
public void testRequest() throws Exception {
HtmlPage page = requestPage();
- HtmlInput input = hetInput(page);
+ HtmlInput input = getInput(page);
assertNotNull(input);
}
- @Test @Ignore
+ @Test
public void testSubmitTooShortValue() throws Exception {
submitValueAndCheckMesage("",containsString("Error"));
}
- @Test @Ignore
+ @Test
public void testSubmitTooLongValue() throws Exception {
submitValueAndCheckMesage("123456",containsString("Error"));
}
@@ -67,14 +67,15 @@
private void submitValueAndCheckMesage(String value, Matcher<String> matcher)
throws Exception {
HtmlPage page = requestPage();
- HtmlInput input = hetInput(page);
- input.setValueAttribute(value);
- input.fireEvent("keyup");
- HtmlElement message = page.getElementById("form:message");
+ HtmlInput input = getInput(page);
+ page = (HtmlPage) input.setValueAttribute(value);
+ input.fireEvent("blur");
+ System.out.println(page.asXml());
+ HtmlElement message = page.getElementById("form:uiMessage");
assertThat(message.getTextContent(), matcher);
-// System.out.println(page.asXml());
}
- private HtmlInput hetInput(HtmlPage page) {
+
+ private HtmlInput getInput(HtmlPage page) {
HtmlForm htmlForm = page.getFormByName("form");
assertNotNull(htmlForm);
HtmlInput input = htmlForm.getInputByName("form:text");
Modified:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -41,6 +41,7 @@
@Test
public void testClear() throws Exception {
+ setUpMessage();
sendMessage();
HtmlElement htmlElement = getMessageContentElement();
String text = htmlElement.asText();
Added:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java
(rev 0)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -0,0 +1,53 @@
+/*
+ * $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.javascript.client.message;
+
+import static org.junit.Assert.*;
+
+import org.jboss.test.qunit.Qunit.Builder;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class DocumentReadyTest extends MessageTestBase {
+
+ @Override
+ protected Builder createQunitPage() {
+ return
super.createQunitPage().loadContent("$(document).ready(function(){"+MESSAGE_INIT+"});");
+ }
+
+ @Test
+ public void testSend() throws Exception {
+ sendMessage();
+ HtmlElement htmlElement = getMessageContentElement();
+ String text = htmlElement.asText();
+ assertTrue(text.contains(getErrorMessage().getSummary()));
+ }
+
+}
Property changes on:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -16,22 +16,24 @@
@Rule
public final Qunit qunit;
- public static final String COMPONENT = "component";
+ public static final String COMPONENT = "form:component";
- public static final String MY_MESSAGE = "myMessage";
+ public static final String MY_MESSAGE = "form:uiMessage";
+ public static final String MESSAGE_INIT = "new
RichFaces.ui.Message(\"" + MY_MESSAGE + "\",
{forComponentId:\"" + COMPONENT + "\"})";
+
public MessageTestBase() {
this.qunit = createQunitPage().build();
}
public void setUpMessage(){
- qunit.runScript("new RichFaces.ui.Message(\"" + MY_MESSAGE +
"\", {forComponentId:\"" + COMPONENT + "\"})");
+ qunit.runScript(MESSAGE_INIT);
}
protected Builder createQunitPage() {
return
Qunit.builder().loadJsfResource("jquery.js").loadJsfResource("richfaces.js")
.loadJsfResource("richfaces-event.js").loadJsfResource("richfaces-base-component.js").
- loadJsfResource("csv.js",
"org.richfaces").loadJsfResource("message.js",
"org.richfaces").content("<div id=\"" + MY_MESSAGE +
"\" ><ul id=\"" + MY_MESSAGE +
":Content\">"+getMessageContent()+"</ul></div>");
+ loadJsfResource("csv.js",
"org.richfaces").loadJsfResource("message.js",
"org.richfaces").content("<div id=\"foo\" ><ul
id=\"" + MY_MESSAGE +
"\">"+getMessageContent()+"</ul></div>");
}
@@ -40,7 +42,6 @@
}
protected Object sendMessage() {
- setUpMessage();
JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),COMPONENT,getErrorMessage());
return qunit.runScript(clientSideFunction.toScript());
@@ -55,7 +56,7 @@
protected HtmlElement getMessageContentElement() {
HtmlPage page = qunit.getPage();
- HtmlElement htmlElement = page.getElementById(MY_MESSAGE+":Content");
+ HtmlElement htmlElement = page.getElementById(MY_MESSAGE);
assertNotNull(htmlElement);
return htmlElement;
}
Modified:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java 2010-12-18
00:11:17 UTC (rev 20674)
@@ -38,6 +38,7 @@
@Test
public void testSend() throws Exception {
+ setUpMessage();
sendMessage();
HtmlElement htmlElement = getMessageContentElement();
String text = htmlElement.asText();
Modified:
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/client-test.xhtml 2010-12-18
00:11:17 UTC (rev 20674)
@@ -7,10 +7,10 @@
<h:form id="form">
<h:inputText id="text" value="#{test.value}">
<f:validateLength minimum="1" maximum="3"/>
- <csv:validator event="keyup" />
+ <csv:validator event="blur" />
</h:inputText>
<h:outputText id="out"
value="#{test.value}"></h:outputText>
- <csv:message id="message" for="text" />
+ <csv:message id="uiMessage" for="text" />
</h:form>
</h:body>
</html>
Modified:
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml 2010-12-17
23:38:58 UTC (rev 20673)
+++
branches/RF-7654/ui/validator/ui/src/test/resources/org/richfaces/component/test.xhtml 2010-12-18
00:11:17 UTC (rev 20674)
@@ -7,10 +7,10 @@
<h:form id="form">
<h:inputText id="text" value="#{test.value}">
<f:validator validatorId="custom" />
- <csv:validator event="keyup" />
+ <csv:validator event="blur" />
</h:inputText>
<h:outputText id="out"
value="#{test.value}"></h:outputText>
- <csv:message id="message" for="text" />
+ <csv:message id="uiMessage" for="text" />
</h:form>
</h:body>
</html>