I had envisioned this a little differently
AlertManager would know when rendering is active
AlertManager would bypass storage, and directly invoke JSS, when adding new 
transient alerts during render

The Heartbeat assumes that the Alerts component is very high level on the page, 
but I can imagine page structures that may allow added alerts to be lost 
because they are outside the heartbeat.

Likewise, I'm not certain that Alerts added during an Ajax render will be 
handled correctly, but I'm away from the code right now so I can't check.

Sent from my iPad

On Jul 26, 2012, at title6:53 AM, [email protected] wrote:

> Updated Branches:
>  refs/heads/5.3 3aa74a333 -> da6ce37bb
>  refs/heads/master fd1874490 -> ec216f2a0
> 
> 
> [TAP5-1949] Defer alerts initialization to catch them all
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
> Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/da6ce37b
> Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/da6ce37b
> Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/da6ce37b
> 
> Branch: refs/heads/5.3
> Commit: da6ce37bb5fbdd2472d0b011a22a05e362ca8986
> Parents: 3aa74a3
> Author: Massimo Lusetti <[email protected]>
> Authored: Thu Jul 26 15:47:19 2012 +0200
> Committer: Massimo Lusetti <[email protected]>
> Committed: Thu Jul 26 15:50:04 2012 +0200
> 
> ----------------------------------------------------------------------
> .../tapestry5/corelib/components/Alerts.java       |   18 +++++---
> .../tapestry5/integration/app1/AlertsTests.groovy  |    9 ++++
> .../app1/components/ErrorComponent.java            |   35 +++++++++++++++
> .../integration/app1/pages/AlertsDemo.java         |   11 +++++
> .../integration/app1/pages/AlertsDemo.tml          |   11 ++++-
> 5 files changed, 77 insertions(+), 7 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/da6ce37b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Alerts.java
> ----------------------------------------------------------------------
> diff --git 
> a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Alerts.java
>  
> b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Alerts.java
> index c3b4c40..a8728a3 100644
> --- 
> a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Alerts.java
> +++ 
> b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Alerts.java
> @@ -77,12 +77,7 @@ public class Alerts implements ClientElement
> 
>         if (storage != null)
>         {
> -            for (Alert alert : storage.getAlerts())
> -            {
> -                javaScriptSupport.addInitializerCall("addAlert", 
> alert.toJSON());
> -            }
> -
> -            storage.dismissNonPersistent();
> +            addAlertsFromStorage();
>         }
> 
> 
> @@ -106,4 +101,15 @@ public class Alerts implements ClientElement
> 
>         return new JSONObject();
>     }
> +
> +    @HeartbeatDeferred
> +    void addAlertsFromStorage()
> +    {
> +        for (Alert alert : storage.getAlerts())
> +        {
> +            javaScriptSupport.addInitializerCall("addAlert", alert.toJSON());
> +        }
> +
> +        storage.dismissNonPersistent();
> +    }
> }
> 
> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/da6ce37b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
> ----------------------------------------------------------------------
> diff --git 
> a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
>  
> b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
> index 4936cee..60b8e19 100644
> --- 
> a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
> +++ 
> b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
> @@ -116,4 +116,13 @@ class AlertsTests extends SeleniumTestCase
>         assertTrue isElementPresent("//div[@class='alert-class']")
>     }
> 
> +    /** TAP5-1949 - alerts initialization should be deferred to include 
> every component's alerts */
> +    @Test
> +    void make_sure_alerts_are_added_last()
> +    {
> +        openLinks 'Alerts Demo', 'reset', 'show error component'
> +
> +        assertTextPresent ('Error from ErrorComponent')
> +    }
> +
> }
> 
> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/da6ce37b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ErrorComponent.java
> ----------------------------------------------------------------------
> diff --git 
> a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ErrorComponent.java
>  
> b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ErrorComponent.java
> new file mode 100644
> index 0000000..01a2b0a
> --- /dev/null
> +++ 
> b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ErrorComponent.java
> @@ -0,0 +1,35 @@
> +// Copyright 2006, 2007 The Apache Software Foundation
> +//
> +// Licensed under the Apache License, Version 2.0 (the "License");
> +// you may not use this file except in compliance with the License.
> +// You may obtain a copy of the License at
> +//
> +//     http://www.apache.org/licenses/LICENSE-2.0
> +//
> +// Unless required by applicable law or agreed to in writing, software
> +// distributed under the License is distributed on an "AS IS" BASIS,
> +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +// See the License for the specific language governing permissions and
> +// limitations under the License.
> +
> +package org.apache.tapestry5.integration.app1.components;
> +
> +import org.apache.tapestry5.alerts.AlertManager;
> +import org.apache.tapestry5.alerts.Duration;
> +import org.apache.tapestry5.alerts.Severity;
> +import org.apache.tapestry5.annotations.SetupRender;
> +import org.apache.tapestry5.ioc.annotations.Inject;
> +
> +/**
> + * Store a simple error message in the {@link AlertManager}.
> + */
> +public class ErrorComponent
> +{
> +    @Inject
> +    private AlertManager alertManager;
> +
> +    @SetupRender
> +    void addErrorMessage() {
> +        alertManager.alert(Duration.SINGLE, Severity.ERROR, "Error from 
> ErrorComponent");
> +    }
> +}
> 
> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/da6ce37b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
> ----------------------------------------------------------------------
> diff --git 
> a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
>  
> b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
> index 04ea78b..7a371ed 100644
> --- 
> a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
> +++ 
> b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
> @@ -1,10 +1,12 @@
> package org.apache.tapestry5.integration.app1.pages;
> 
> +import org.apache.tapestry5.PersistenceConstants;
> import org.apache.tapestry5.alerts.AlertManager;
> import org.apache.tapestry5.alerts.AlertStorage;
> import org.apache.tapestry5.alerts.Duration;
> import org.apache.tapestry5.alerts.Severity;
> import org.apache.tapestry5.annotations.InjectComponent;
> +import org.apache.tapestry5.annotations.Persist;
> import org.apache.tapestry5.annotations.Property;
> import org.apache.tapestry5.annotations.SessionState;
> import org.apache.tapestry5.beaneditor.ReorderProperties;
> @@ -32,6 +34,10 @@ public class AlertsDemo
>     @Width(80)
>     private String message;
> 
> +    @Persist(PersistenceConstants.FLASH)
> +    @Property
> +    private boolean showErrorComponent;
> +
>     @InjectComponent
>     private Zone formZone;
> 
> @@ -64,4 +70,9 @@ public class AlertsDemo
>     {
>         storage.dismissAll();
>     }
> +
> +    void onShowErrorComponent()
> +    {
> +        showErrorComponent = true;
> +    }
> }
> 
> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/da6ce37b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
> ----------------------------------------------------------------------
> diff --git 
> a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
>  
> b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
> index 372d446..7c652b0 100644
> --- 
> a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
> +++ 
> b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
> @@ -1,4 +1,5 @@
> -<html t:type="Border" 
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> +<html t:type="Border" 
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";
> +        xmlns:p="tapestry:parameter">
> 
> <h1>Alerts Demo</h1>
> 
> @@ -27,4 +28,12 @@
> </p>
> 
> <t:alerts class='alert-class' dismissText="Zenbu Kesu"/>
> +
> +<t:if test="showerrorcomponent">
> +    <t:errorcomponent />
> +    <p:else>
> +        <t:eventlink event="showerrorcomponent">show error 
> component</t:eventlink>
> +    </p:else>
> +</t:if>
> +
> </html>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to