tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Tapestry > BeanEditForm FAQ
Date Fri, 20 May 2011 19:11:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/12/_/styles/combined.css?spaceKey=TAPESTRY&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/TAPESTRY/BeanEditForm+FAQ">BeanEditForm
FAQ</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~hlship">Howard
M. Lewis Ship</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <style type='text/css'>/*<![CDATA[*/
table.ScrollbarTable  {border: none;padding: 3px;width: 100%;padding: 3px;margin: 0px;background-color:
#f0f0f0}
table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width: 16px;border: none;}
table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 16px;border: none;}

/*]]>*/</style><div class="Scrollbar"><table class='ScrollbarTable'><tr><td
width='33%' class='ScrollbarPrevName'>&nbsp;</td><td width='33%' class='ScrollbarParent'><sup><a
href="/confluence/display/TAPESTRY/Page+And+Component+Classes+FAQ"><img border='0' align='middle'
src='/confluence/images/icons/up_16.gif' width='8' height='8'></a></sup><a
href="/confluence/display/TAPESTRY/Page+And+Component+Classes+FAQ">Page And Component Classes
FAQ</a></td><td width='33%' class='ScrollbarNextName'>&nbsp;</td></tr></table></div>


<h2><a name="BeanEditFormFAQ-BeanEditForm"></a>BeanEditForm </h2>

<h3><a name="BeanEditFormFAQ-WhydoIgetexceptionsaboutinstantiatingabeanwhenusingBeanEditForm%3F"></a>Why
do I get exceptions about instantiating a bean when using BeanEditForm?</h3>

<p>When you render a BeanEditForm, or when the rendered form is submitted, Tapestry
must instantiate an instance of the object to be edited. This occurs when the BeanEditForm's
<tt>object</tt> parameter is bound to null: Tapestry instantiates an instance
of the property type so that the BeanEditForm has an object to read default values from, or
to push submitted values into.</p>

<p>By default, this uses the standard <a href="/confluence/display/TAPESTRY/Injection+in+Detail"
title="Injection in Detail">injection mechanism</a>, which means that Tapestry will
identify the public constructor with the most parameters, and attempt to find objects and
other objects for each constructor parameter.</p>

<p>There's two ways to fine tune this so you don't get errors:</p>

<ul>
	<li>Place an @<a href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html"
class="external-link" rel="nofollow">Inject</a> annotation on the correct constructor
to use (often, the constructor with no parameters).</li>
</ul>



<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class MyBean {
   @Inject
   <span class="code-keyword">public</span> MyBean() { ... }


   <span class="code-comment">// For testing
</span>   <span class="code-keyword">public</span> MyBean(<span class="code-object">String</span>
value, <span class="code-object">boolean</span> flag, <span class="code-object">int</span>
index) { ... }

   ...
}
</pre>
</div></div>

<ul>
	<li>Provide an event handler method for the "prepare" event, and put an instantiated
instance into the property.</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class MyPage {
  @Property
  <span class="code-keyword">public</span> MyBean myBean;

  <span class="code-comment">// The template contains &lt;t:beaneditform t:id=<span
class="code-quote">"mybeaneditor"</span>/&gt; ...
</span>
  void onPrepareFromMyBeanEditor() {
    myBean = <span class="code-keyword">new</span> MyBean();
  }
}
</pre>
</div></div>

<style type='text/css'>/*<![CDATA[*/
table.ScrollbarTable  {border: none;padding: 3px;width: 100%;padding: 3px;margin: 0px;background-color:
#f0f0f0}
table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width: 16px;border: none;}
table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 16px;border: none;}

/*]]>*/</style><div class="Scrollbar"><table class='ScrollbarTable'><tr><td
width='33%' class='ScrollbarPrevName'>&nbsp;</td><td width='33%' class='ScrollbarParent'><sup><a
href="/confluence/display/TAPESTRY/Page+And+Component+Classes+FAQ"><img border='0' align='middle'
src='/confluence/images/icons/up_16.gif' width='8' height='8'></a></sup><a
href="/confluence/display/TAPESTRY/Page+And+Component+Classes+FAQ">Page And Component Classes
FAQ</a></td><td width='33%' class='ScrollbarNextName'>&nbsp;</td></tr></table></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://cwiki.apache.org/confluence/display/TAPESTRY/BeanEditForm+FAQ">View
Online</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message