Author: lfryc(a)redhat.com
Date: 2010-11-16 12:05:51 -0500 (Tue, 16 Nov 2010)
New Revision: 20061
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPoll/simple.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTimeWatcher.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/clientTime-updateDifference.js
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java
Log:
a4j:poll - improved sample to use metamer:clientTimeWatcher and added default values
(RFPL-293)
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPoll/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPoll/simple.xhtml 2010-11-16
17:04:02 UTC (rev 20060)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPoll/simple.xhtml 2010-11-16
17:05:51 UTC (rev 20061)
@@ -1,7 +1,7 @@
<?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: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">
<!--
@@ -33,6 +33,7 @@
<f:viewParam name="templates"
value="#{templateBean.templates}">
<f:converter converterId="templatesListConverter" />
</f:viewParam>
+ <f:viewParam name="enabled"
value="#{a4jPollBean.attributes['enabled'].value}" />
</f:metadata>
<h:outputStylesheet library="css"
name="a4jPoll.css"/>
<h:outputScript library="script" name="date-format.js"
/>
@@ -51,37 +52,47 @@
immediate="#{a4jPollBean.attributes['immediate'].value}"
interval="#{a4jPollBean.attributes['interval'].value}"
onbeforedomupdate="#{a4jPollBean.attributes['onbeforedomupdate'].value}"
-
onbegin="#{a4jPollBean.attributes['onbegin'].value}"
-
oncomplete="#{a4jPollBean.attributes['oncomplete'].value}"
-
ontimer="#{a4jPollBean.attributes['ontimer'].value}"
+
onbegin="#{rich:element('timeWatcher:grid')}.begin();
#{a4jPollBean.attributes['onbegin'].value}"
+
oncomplete="#{rich:element('timeWatcher:grid')}.complete();
#{a4jPollBean.attributes['oncomplete'].value}"
+
ontimer="#{rich:element('timeWatcher:grid')}.event();
#{rich:element('timeWatcher:grid')}.difference();
#{a4jPollBean.attributes['ontimer'].value}"
rendered="#{a4jPollBean.attributes['rendered'].value}"
value="#{a4jPollBean.attributes['value'].value}"
- <a4j:ajax event="timer"
render="time" />
+ <a4j:ajax event="timer" render="output" />
</a4j:poll>
</h:panelGroup>
- <h:panelGroup id="time">
+ <script type="text/javascript">
+ //<![CDATA[
+ var lastCounter = null;
+ //]]>
+ </script>
+
+ <h:panelGroup id="output">
<h:outputText value="Server: " />
<h:outputText id="serverDate"
value="#{a4jPollBean.date}" title="#{a4jPollBean.date.time}">
<f:convertDateTime pattern="dd.MM.yyyy HH:mm:ss.SSS"
/>
</h:outputText>
***
- <h:outputText value="Client: " />
- <h:outputText id="clientDate" value=""
title="" />
- <script type="text/javascript">
+ <h:outputText value="Counter: " />
+ <h:outputText id="outputCounter"
value="#{a4jPollBean.counter}"/>
+ <span id="counterDelta"></span>
+ <script type="text/javascript">
//<![CDATA[
- var now = new Date();
- jQuery("div.content span[id$=clientDate]")
- .text(now.format("UTC:dd.mm.yyyy HH:MM:ss.l",
false))
- .attr("title", now.getTime());
+ var counterDelta = document.getElementById('counterDelta');
+ document.title = lastCounter;
+ if (lastCounter) {
+ counterDelta.innerHTML = '(delta: ' +
(#{a4jPollBean.counter} - lastCounter) + ')';
+ }
+ lastCounter = #{a4jPollBean.counter};
//]]>
</script>
- ***
- <h:outputText value="Counter: " />
- <h:outputText id="outputCounter"
value="#{a4jPollBean.counter}"/>
</h:panelGroup>
+
+ <metamer:clientTimeWatcher id="timeWatcher"
reverseOrder="true" />
</ui:define>
+
+
<ui:define name="outOfTemplateAfter">
<metamer:attributes value="#{a4jPollBean.attributes}"
id="attributes" />
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTimeWatcher.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTimeWatcher.xhtml 2010-11-16
17:04:02 UTC (rev 20060)
+++
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTimeWatcher.xhtml 2010-11-16
17:05:51 UTC (rev 20061)
@@ -11,6 +11,7 @@
<h:body>
<composite:interface>
<composite:attribute name="events" type="java.lang.Integer"
default="1" />
+ <composite:attribute name="reverseOrder"
type="java.lang.Boolean" default="false" shortDescription="use
when you are getting negative values since event time is always lower than begin
times" />
</composite:interface>
<composite:implementation>
@@ -52,7 +53,7 @@
var differenceElement = #{rich:element('difference')};
var beginTimeElement = this.getBeginElement();
var eventTimeId = "#{rich:clientId('event1')}".replace(/1$/,
"");
- Metamer.ClientTime.updateDifference(differenceElement, beginTimeElement,
eventTimeId);
+ Metamer.ClientTime.updateDifference(differenceElement, beginTimeElement,
eventTimeId, #{cc.attrs.reverseOrder});
}
grid.getBeginElement = function() {
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/clientTime-updateDifference.js
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/clientTime-updateDifference.js 2010-11-16
17:04:02 UTC (rev 20060)
+++
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/clientTime-updateDifference.js 2010-11-16
17:05:51 UTC (rev 20061)
@@ -6,7 +6,7 @@
Metamer.ClientTime = {};
}
-Metamer.ClientTime.updateDifference = function (differenceTimeElement, beginTimeElement,
eventTimeId) {
+Metamer.ClientTime.updateDifference = function (differenceTimeElement, beginTimeElement,
eventTimeId, reverseOrder) {
var maxEventTime = 0;
for (var i = 1; i < 100; i++) {
@@ -24,5 +24,11 @@
var beginTime = parseInt(beginTimeElement.title);
- jQuery(differenceTimeElement).text(beginTime - maxEventTime);
+ var difference = beginTime - maxEventTime;
+
+ if (reverseOrder) {
+ difference = 0 - difference;
+ }
+
+ jQuery(differenceTimeElement).text(difference);
}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java 2010-11-16
17:04:02 UTC (rev 20060)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java 2010-11-16
17:05:51 UTC (rev 20061)
@@ -56,7 +56,7 @@
IntervalAttributes attributes = new IntervalAttributes();
JQueryLocator time = pjq("span[id$=time]");
- AttributeLocator<?> clientTime =
pjq("span[id$=clientDate]").getAttribute(Attribute.TITLE);
+ AttributeLocator<?> clientTime =
pjq("span[id$=event1:outputTime]").getAttribute(Attribute.TITLE);
long startTime;
@@ -65,7 +65,7 @@
@Override
public URL getTestUrl() {
- return buildUrl(contextPath, "faces/components/a4jPoll/simple.xhtml");
+ return buildUrl(contextPath,
"faces/components/a4jPoll/simple.xhtml?enabled=false");
}
@BeforeMethod