I'm trying to create a component that could add a set of fields upon request
to a table.
I'm using a Collection class and iterating over it using Foreach.
To add a new set of fields, i'm trying to post to the server using a submit
method in the main page,
that method adds another entry to the collection class. This in turn should
make the foreach component
in my Custom component render an additional field.
Currently i'm getting two exceptions depending on a slight change to the JWC
file.
1) Stale Link
2) Class Cast Exception
The JWC file:.
--------------------------
<component-specification class="com.stchome.pam.tapestry.components.NameSet"
allow-body="no" allow-informal-parameters="yes">
<parameter
name="source"
direction="form" <-- if i change this to "in" i get a stale link, leaving it
as "form" gives me a classcastexception
required="yes"
type="java.lang.Object">
</parameter>
<parameter name="listener"
direction="auto"
required="yes"
type="org.apache.tapestry.IActionListener">
</parameter>
<component id="elements" type="Foreach">
<inherited-binding name="source" parameter-name="source"/>
</component>
<component id="fName" type="TextField">
<binding name='value' expression="components.elements.value.fName
"></binding>
</component>
<component id="lName" type="TextField">
<binding name='value' expression="components.elements.value.lName
"></binding>
</component>
<component id="iNetHandle" type="TextField">
<binding name='value' expression="components.elements.value.iNetHandle
"></binding>
</component>
<component id="addMore" type="Submit">
<binding name="listener" expression="launch()"></binding>
</component>
</component-specification>
The Class File:
-----------------------
public abstract class NameSet extends BaseComponent{
private Object source;
public abstract IActionListener getListener();
public Object getSource() {
return source;
}
public void setSource(Object source) {
this.source = source;
}
public void launch( ) {
IActionListener listener = this.getListener();
listener.actionTriggered(this,this.getPage().getRequestCycle());
}
}
The HTML template:
--------------------------------
<span jwcid="$content$">
<table width="100%">
<span jwcid="elements">
<tr>
<td><input type="text" jwcid="fName"/></td>
<td><input type="text" jwcid="lName"/></td>
</tr>
<tr>
<td><input type="text" jwcid="iNetHandle"/></td>
</tr>
</span>
<tr><td><input jwcid="addMore" value="Add more names"
type="Submit"/></td></tr>
</table>
</span>
The MainPage's page file (this is where i'm trying to use the component)
----------------------------------------------------------------------------------------------------
<page-specification class="com.stchome.pam.tapestry.pages.NewCaseInterview">
<component id="nameSet" type="NameSet">
<binding name="source" expression="getPersonNames()"></binding>
<binding name="listener" expression="listeners.anotherNameType"></binding>
</component>
</page-specification>
The anotherNameType method which is in the Main page's Class file:
---------------------------------------------------------------------------------------------------
/* Adds another entry into the collection class which stores person names */
public void anotherNameType(IRequestCycle cycle) {
this.getInterview().getPerson().addPersonName(new PersonName());
}