Alerts

Here we demonstrate Tapestry's Alerts component.
You can tailor the appearance of the alerts to suit your needs with CSS.




References: Alerts, AlertManager, Duration, Severity, @Inject.

Home


<!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_4.xsd">
<body class="container">
    <h3>Alerts</h3>
    
    Here we demonstrate Tapestry's Alerts component.<br/>
    You can tailor the appearance of the alerts to suit your needs with CSS.<br/>

    <div class="eg">
        <t:form class="form-horizontal">
            <div class="form-group">
                <t:label class="col-sm-3" for="duration"/>
                <div class="col-sm-6">
                    <t:RadioGroup t:id="duration" value="duration" validate="required">
                        <t:Radio t:id="durationS" value="Duration.SINGLE" label="Single"/>
                        <t:label for="durationS" class="label-radio"/>
                        <t:Radio t:id="durationT" value="Duration.TRANSIENT" label="Transient (a few seconds)"/>
                        <t:label for="durationT" class="label-radio"/>
                        <t:Radio t:id="durationU" value="Duration.UNTIL_DISMISSED" label="Until Dismissed"/>
                        <t:label for="durationU" class="label-radio"/>
                    </t:RadioGroup><br/>
                </div>
            </div>
            <div class="form-group">
                <t:label class="col-sm-3" for="severity"/>
                <div class="col-sm-6">
                    <t:RadioGroup t:id="severity" validate="required">
                        <t:Radio t:id="severityI" value="Severity.INFO" label="Info"/>
                        <t:label for="severityI" class="label-radio"/>
                        <t:Radio t:id="severityS" value="Severity.SUCCESS" label="Success"/>
                        <t:label for="severityS" class="label-radio"/>
                        <t:Radio t:id="severityW" value="Severity.WARN" label="Warn"/>
                        <t:label for="severityW" class="label-radio"/>
                        <t:Radio t:id="severityE" value="Severity.ERROR" label="Error"/>
                        <t:label for="severityE" class="label-radio"/>
                    </t:RadioGroup><br/>
                </div>
            </div>
            <div class="form-group">
                <t:label class="col-sm-3" for="quantity"/>
                <div class="col-sm-6">
                    <t:RadioGroup t:id="quantity" validate="required">
                        <t:Radio t:id="quantity1" value="literal:1" label="1"/>
                        <t:label for="quantity1" class="label-radio"/>
                        <t:Radio t:id="quantity2" value="literal:2" label="2"/>
                        <t:label for="quantity2" class="label-radio"/>
                        <t:Radio t:id="quantity3" value="literal:3" label="3"/>
                        <t:label for="quantity3" class="label-radio"/>
                    </t:RadioGroup><br/>
                </div>
            </div>
            <div class="form-group">
                <t:label class="col-sm-3" for="showDismissAll"/>
                <div class="col-sm-6">
                    <t:RadioGroup t:id="showDismissAll" validate="required">
                        <t:Radio t:id="showDismissAllN" value="literal:false" label="No"/>
                        <t:label for="showDismissAllN" class="label-radio"/>
                        <t:Radio t:id="showDismissAllY" value="literal:true" label="Yes"/>
                        <t:label for="showDismissAllY" class="label-radio"/>
                    </t:RadioGroup><br/>
                </div>
            </div>
            
            <div class="form-group">
                <div class="col-sm-6 col-sm-offset-3">
                    <t:submit/> 
                </div>
            </div>
        </t:form>

        <t:alerts showDismissAll="prop:showDismissAll"/>
        
    </div> 

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

    <t:pagelink page="Index">Home</t:pagelink><br/><br/>

    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/component/Alerts.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/component/Alerts.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/alerts.css"/>
    </t:tabgroup>
</body>
</html>


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.Import;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

@Import(stylesheet = "css/examples/alerts.css")
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 showDismissAll;

    // 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 (showDismissAll == null) {
            showDismissAll = false;
        }
    }

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

}


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

.eg .label-radio {
                font-weight: normal;
                margin-left: 4px;
                margin-right: 12px;
}