blob: 29e7334c21d67cb5437273a3f8cf1b491747b9c7 [file] [log] [blame]
-----------------------------xyzzyx
Content-Disposition: form-data; name="service"
direct/0/Home/$Form
-----------------------------xyzzyx
Content-Disposition: form-data; name="sp"
S0
-----------------------------xyzzyx
Content-Disposition: form-data; name="$Upload"; filename="context19/long.html"
Content-Type: text/html
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Manual Persistent Component Properties</title><link rel="stylesheet" href="Tapestry.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.59.2"><link rel="home" href="TapestryUsersGuide.html" title="Tapestry User's Guide"><link rel="up" href="state.html" title="Chapter&nbsp;2.&nbsp;Managing Server-Side State"><link rel="previous" href="state.manual-page-properties.html" title="Implementing Persistent Page Properties Manually"><link rel="next" href="state.stateless.html" title="Stateless Applications"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Manual Persistent Component Properties</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="state.manual-page-properties.html"><img src="common-images/prev.png" alt="Prev"></a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;2.&nbsp;Managing Server-Side State</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="state.stateless.html"><img src="common-images/next.png" alt="Next"></a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="state.manual-component-properties"></a>Manual Persistent Component Properties</h2></div></div><p>
Implementing transient and persistent properties inside components involves more work.
The <tt>fireObservedChange()</tt>
method is available to components as well as pages, but the initialization of
the component is more complicated.
</p><p>
Components do not have the equivalent of the <tt>initialize()</tt> method. Instead,
they must register for an event notification to tell them when the page is being <span class="emphasis"><em>detached</em></span>
from the engine (prior to be stored back into the page pool). This event is generated by the page itself.
</p><p>
The Java interface <a href="../api/net/sf/tapestry/event/PageDetachListener.html" target="_self"><tt>PageDetachListener</tt></a> is the event listener interface for this purpose.
By simply implementing this interface, Tapestry will register the component as a listener and ensure that
it receives event notifications at the right time (this works for the two other
page event interfaces, <a href="../api/net/sf/tapestry/event/PageRenderListener.html" target="_self"><tt>PageRenderListener</tt></a> and <a href="../api/net/sf/tapestry/event/PageCleanupListener.html" target="_self"><tt>PageCleanupListener</tt></a> as well; simply
implement the interface and leave the rest to the framework).
</p><p>
Tapestry provides a method, <tt>finishLoad()</tt>, for just this purpose: late initialization.
</p><div class="example"><a name="d0e593"></a><p class="title"><b>Example&nbsp;2.7.&nbsp;Manual Persistent Component Properties</b></p><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">
public class MyComponent extends <a href="../api/net/sf/tapestry/BaseComponent.html" target="_self"><tt>BaseComponent</tt></a> implements <a href="../api/net/sf/tapestry/event/PageDetachListener.html" target="_self"><tt>PageDetachListener</tt></a>
{
private String _myProperty;
public void setMyProperty(String myProperty)
{
_myProperty = myProperty;
fireObservedChange("myProperty", myProperty);
}
public String getMyProperty()
{
return _myProperty;
}
protected void initialize()
{
_myProperty = "<span class="emphasis"><em>a default value</em></span>";
}
protected void finishLoad()
{
initialize();
}
/**
* The method specified by <a href="../api/net/sf/tapestry/event/PageDetachListener.html" target="_self"><tt>PageDetachListener</tt></a>.
*
**/
public void pageDetached(PageEvent event)
{
initialize();
}
}
</pre></td></tr></table></div><p>
Again, there is no particular need to do all this; using the
<a href="spec.property-specification.html" title="property-specification element"><tt class="sgmltag-starttag">&lt;property-specification&gt;</tt></a> element is far, far simpler.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="state.manual-page-properties.html"><img src="common-images/prev.png" alt="Prev"></a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="state.html"><img src="common-images/up.png" alt="Up"></a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="state.stateless.html"><img src="common-images/next.png" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">Implementing Persistent Page Properties Manually&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="TapestryUsersGuide.html"><img src="common-images/home.png" alt="Home"></a></td><td width="40%" align="right" valign="top">&nbsp;Stateless Applications</td></tr></table></div></body></html>
-----------------------------xyzzyx
Content-Disposition: form-data; name="Form0"
$Upload
-----------------------------xyzzyx--