Alerts

Here we demonstrate Tapestry's Alerts component.
You can tailor the appearance of the alerts to suit your needs by overriding CSS classes t-alert-container, t-info, t-warn, t-error, etc.
:      
:      
:      
:    
References: Alerts, AlertManager, Duration, Severity, @Inject.

Home

Alerts.tml


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- We need a doctype to allow us to use special characters like &nbsp; 
     We use a "strict" DTD to make IE follow the alignment rules. -->
     
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<head>
    <link rel="stylesheet" type="text/css" href="${context:css/examples/examples.css}"/>
    <style type="text/css">
        .eg th          { text-align: right; padding-right: 14px; font-weight: normal; }
        .eg .buttons    { margin-top: 12px; }
        DIV#alerts      { margin: auto; width: 500px; }
        <t:if test="hideDismiss">
            DIV.t-alert-controls { display: none; }
        </t:if>
    </style>
</head>
<body>
    <h1>Alerts</h1>
    
    Here we demonstrate Tapestry's Alerts component.<br/>
    You can tailor the appearance of the alerts to suit your needs by overriding CSS classes t-alert-container, t-info, t-warn, t-error, etc.<br/>

    <div class="eg">
        <form t:type="Form">
            <table>
            <tr>
                <th>
                    <t:label for="duration"/>:
                </th>
                <td>
                    <t:RadioGroup t:id="duration" value="duration" validate="required">
                        <t:Radio t:id="durationS" value="Duration.SINGLE" label="Single"/><t:label for="durationS"/>&nbsp;
                        <t:Radio t:id="durationT" value="Duration.TRANSIENT" label="Transient (15 seconds)"/><t:label for="durationT"/>&nbsp;
                        <t:Radio t:id="durationU" value="Duration.UNTIL_DISMISSED" label="Until Dismissed"/><t:label for="durationU"/>&nbsp;
                    </t:RadioGroup><br/>
                </td>
            </tr>
            <tr>
                <th>
                    <t:label for="severity"/>:
                </th>
                <td>
                    <t:RadioGroup t:id="severity" validate="required">
                        <t:Radio t:id="severityI" value="Severity.INFO" label="Info"/><t:label for="severityI"/>&nbsp;
                        <t:Radio t:id="severityW" value="Severity.WARN" label="Warn"/><t:label for="severityW"/>&nbsp;
                        <t:Radio t:id="severityE" value="Severity.ERROR" label="Error"/><t:label for="severityE"/>&nbsp;
                    </t:RadioGroup><br/>
                </td>
            </tr>
            <tr>
                <th>
                    <t:label for="quantity"/>:
                </th>
                <td>
                    <t:RadioGroup t:id="quantity" validate="required">
                        <t:Radio t:id="quantity1" value="literal:1" label="1"/><t:label for="quantity1"/>&nbsp;
                        <t:Radio t:id="quantity2" value="literal:2" label="2"/><t:label for="quantity2"/>&nbsp;
                        <t:Radio t:id="quantity3" value="literal:3" label="3"/><t:label for="quantity3"/>&nbsp;
                    </t:RadioGroup><br/>
                </td>
            </tr>
            <tr>
                <th>
                    <t:label for="showDismiss"/>:
                </th>
                <td>
                    <t:RadioGroup t:id="showDismiss" validate="required">
                        <t:Radio t:id="showDismissY" value="literal:true" label="Yes"/><t:label for="showDismissY"/>&nbsp;
                        <t:Radio t:id="showDismissN" value="literal:false" label="No"/><t:label for="showDismissN"/>&nbsp;
                    </t:RadioGroup><br/>
                </td>
            </tr>
            </table>
            
            <div class="buttons">
                <input type="submit" value="Submit"/> 
            </div>
        </form>

        <t:alerts/>
    </div> 

    References: 
    <a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/corelib/components/Alerts.html">Alerts</a>, 
    <a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/alerts/AlertManager.html">AlertManager</a>, 
    <a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/alerts/Duration.html">Duration</a>, 
    <a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/alerts/Severity.html">Severity</a>, 
    <a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">@Inject</a>.<br/><br/> 

    <a t:type="pagelink" t:page="Index" href="#">Home</a><br/><br/>

    <t:sourcecodedisplay src="/web/src/main/java/jumpstart/web/pages/examples/component/Alerts.tml"/>
    <t:sourcecodedisplay src="/web/src/main/java/jumpstart/web/pages/examples/component/Alerts.java"/>
    <t:sourcecodedisplay src="/web/src/main/java/jumpstart/web/css/examples/examples.css"/>
</body>
</html>

Alerts.java


package jumpstart.web.pages.examples.component;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.alerts.AlertManager;
import org.apache.tapestry5.alerts.Duration;
import org.apache.tapestry5.alerts.Severity;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

public class Alerts {
    
    // Screen fields
    
    @Property
    @Persist(PersistenceConstants.FLASH)
    private Duration duration;
    
    @Property
    @Persist(PersistenceConstants.FLASH)
    private Severity severity;
    
    @Property
    @Persist(PersistenceConstants.FLASH)
    private int quantity;
    
    @Property
    @Persist(PersistenceConstants.FLASH)
    private Boolean showDismiss;

    // Generally useful bits and pieces

    @Inject
    private AlertManager alertManager;

    // The code
    
    void setupRender() {
        if (duration == null) {
            duration = Duration.SINGLE;
        }
        if (severity == null) {
            severity = Severity.INFO;
        }
        if (quantity == 0) {
            quantity = 1;
        }
        if (showDismiss == null) {
            showDismiss = true;
        }
    }

    void onValidateFromForm() {
        for (int i = 0; i < quantity; i++) {
            alertManager.alert(duration, severity, "Here is a " + duration + ", " + severity + " alert.");
        }
    }

    public boolean isHideDismiss() {
        return !showDismiss;
    }
}

examples.css


body            { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; color: #333; line-height: 17px; }
h1              { font-size: 26px; line-height: 20px; } /* For IE 7 */
form            { margin: 0; }                  

.eg             { margin: 20px 0; padding: 20px; color: #888; 
                    border: 1px solid #ddd; border-radius: 4px; -webkit-border-radius: 4px; -mox-border-radius: 4px; }

a               { text-decoration: none; color: #3D69B6; }
a:hover         { text-decoration: underline; }

/* For BeanDisplay */
.eg dl          { margin: 0; color: #333; }
.eg dl.t-beandisplay dd.id  { display: inline; margin-left: 0px; }  /* IE 7 hack */