I am using an AjaxFormLoop component. There is no database involved, so
the code should be simple.
The add operation in onAddRowFromVehicles() works. I can see that
because the list of vehicles has alwas the correct size. But Properties
of Vehicle (like vehicle.model) are never updated, no matter what I type
into the for fields.
Any hints? I have no idea and think that it should work because my list
of vehicles is persisted.
Here is a snippet of my relevant parts:
class Page{
@Property @Persist
private List<Vehicle> vehicles;
@Property
private Vehicle vehicle;
Object onAddRowFromVehicles() {
Vehicle vehicle = new Vehicle();
vehicle.setType(VehicleType.PKW);
this.vehicles.add(vehicle);
return vehicle;
}
public ValueEncoder<Vehicle> getVehicleEncoder(){
return new VehicleValueEncoder();
}
public class VehicleValueEncoder implements ValueEncoder<Vehicle>{
private static final String SEP = "|";
@Override
public String toClient(Vehicle value) {
StringBuffer result = new StringBuffer();
result.append("vehicle");
result.append(SEP);
result.append(value.getType().name());
result.append(SEP);
result.append(value.getModel());
result.append(SEP);
result.append(value.getLicenseNumber());
result.append(SEP);
result.append(value.getLengthCentimeter());
result.append(SEP);
result.append(value.getHeightCentimeter());
result.append(SEP);
return result.toString();
}
@Override
public Vehicle toValue(String clientValue) {
String[] splitted = clientValue.split("\\" + SEP); // use a
regex
Vehicle vehicle = new Vehicle();
vehicle.setType(VehicleType.valueOf(splitted[1]));
vehicle.setModel(splitted[2]);
vehicle.setLicenseNumber(splitted[3]);
vehicle.setLengthCentimeter(Integer.valueOf(splitted[4]));
vehicle.setHeightCentimeter(Integer.valueOf(splitted[5]));
return vehicle;
}
}
}
TML-File
---------------
...
<form t:type="Form"
t:id="request"
t:clientValidation="true"
t:autofocus="false">
...
<fieldset class="column">
<legend>${message:firstName-label}</legend>
<input type="text"
t:type="TextField"
t:value="firstName"
t:id="firstName"
name="first_name"/>
</fieldset>
<t:AjaxFormLoop t:id="vehicles" t:source="vehicles" t:value="vehicle"
encoder="vehicleEncoder">
<fieldset class="column first" style="width:110px;">
<legend>${message:vehicle-type-label}</legend>
<select name="vehicleType"
t:id="vehicleType"
t:type="Select"
t:value="vehicle.type"
t:blankOption="NEVER"
style="width:110px;"></select>
</fieldset>
<fieldset class="column small left"
style="position:relative; left:-10px;">
<legend>${message:vehicle-model-label}</legend>
<input type="text"
t:type="TextField"
t:value="vehicle.model"
t:id="vehicleModel"
style="width:95px;"/>
</fieldset>
<fieldset class="column small right"
style="position:relative; left:-10px; width=95px;">
<legend>${message:vehicle-license-label}</legend>
<input type="text"
t:type="TextField"
t:value="vehicle.licenseNumber"
t:id="vehicleLicenseNumber"
style="width:95px;"/>
</fieldset>
<fieldset class="column last small left"
style="position:relative; left:+10px;">
<legend>${message:vehicle-length-label}</legend>
<input type="text"
t:type="TextField"
t:value="vehicle.lengthCentimeter"
size="4"
t:id="vehicleLength"/>
</fieldset>
<fieldset class="column last small left"
style="position:relative; left:+25px;">
<legend>${message:vehicle-height-label}</legend>
<input type="text"
t:type="TextField"
size="4"
t:value="vehicle.heightCentimeter"
t:id="vehicleHeight"/>
</fieldset>
<fieldset class="clear">
<legend class="hidden">clear</legend>
</fieldset>
</t:AjaxFormLoop>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org