Display Session Contents

This page shows what's currently in your session.
To make it a handy monitoring tool just open it in a new window, because in most browsers the new window will share the original window's session.
There is no Session.
References: Persistent Page Data, Session Storage, RenderObject.

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>Display Session Contents</h3>
    
    This page shows what's currently in your session.<br/>
    To make it a handy monitoring tool just open it in a new window, because in most browsers the new window will share the 
    original window's session.

    <div class="eg">
        <div class="t-env-data">
    
        <!-- 
            This next part is based on a portion of Tapestry's default ExceptionReport page.
         -->
            
            <t:if test="hasSession">
                <h4>Session Contents</h4>
                <dl>
                    <t:if test="!session.attributeNames.size()">
                        Session exists but is empty.
                    </t:if>
                    <t:loop source="session.attributeNames" value="attributeName">
                        <dt>${attributeName}</dt>
                        <dd>
                            <t:renderobject object="attributeValue"/>
                        </dd>
                    </t:loop>
                </dl>
            </t:if>
            <t:if test="!hasSession">
                There is no Session.
            </t:if>
    
        </div>
    </div>
    
    References: <a href="http://tapestry.apache.org/persistent-page-data.html">Persistent Page Data</a>, 
    <a href="http://tapestry.apache.org/session-storage.html">Session Storage</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/RenderObject.html">RenderObject</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/state/DisplaySessionContents.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/DisplaySessionContents.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/displaysessioncontents.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.state;

import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.Session;

/**
 * This page is based on the portion of Tapestry's default ExceptionReport page that handles the session.
 */
@Import(stylesheet = "css/examples/displaysessioncontents.css")
public class DisplaySessionContents {

    // Screen fields

    @Property
    private String attributeName;

    // Generally useful bits and pieces

    @Inject
    private Request request;

    // The code

    public boolean getHasSession() {
        return request.getSession(false) != null;
    }

    public Session getSession() {
        return request.getSession(false);
    }

    public Object getAttributeValue() {
        return getSession().getAttribute(attributeName);
    }

}


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

dt {
                color: #666;
}

dd {
                margin-left: 24px;
                color: #888;
}