I'm trying to generate a form with a variable - on the server side - number of text fields. The tapestry page looks similar to:
<form t:id="form">
<t:loop source="typesOfIncome" value="typeOfIncome">
<input t:type="TextField" t:id="typeOfIncome-${typeOfIncome.propertyIndex}" value="100"/>
</t:loop>
</form>
That is not accepted by Tapestry, as it bails out with
Component id 'typeOfIncome-${typeOfIncome.propertyIndex}' is not valid; component ids must be valid Java identifiers: start with a letter, and consist of letters, numbers and underscores.
How can I achieve this with Tapestry? And how would the Java code look like in the component?
Update:
With a component which looks like:
public class FormSample {
@Component
private Form _form;
@Inject
private Logger _log;
@Property
private List<String> _typesOfIncome;
@Property
private String _typeOfIncome;
@SetupRender
void setupRender() {
_typesOfIncome = Arrays.asList("First", "Second");
}
void onSuccess() {
_log.info("Got values " + _typesOfIncome + " .");
}
}
and a page containing
<form t:id="form">
<t:loop source="typesOfIncome" value="typeOfIncome">
<input t:type="TextField" t:id="typeOfIncome" t:value="typeOfIncome"/> <br/>
</t:loop>
<input type="submit" value="Save"/>
</form>
in onSuccess
the values list is null. The values are POSTed as:
typeOfIncome First
typeOfIncome_0 Second