You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by davidb82 <da...@thisisnumero.com> on 2009/08/03 18:36:13 UTC
Re: AjaxFormLoop: property changes have no effect
Andy Pahne-7 wrote:
>
>
> 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;
>
> }
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
I think the problem is with your ValueEncoder - it just instantiates a new
Vehicle which doesn't get stored back in your list.
Your code would probably work better if you did something like:
public class VehicleValueEncoder implements ValueEncoder<Integer>{
@Override
public Integer toClient(Vehicle value) {
return vehicles.indexOf(value);
}
@Override
public Vehicle toValue(Integer clientValue) {
return vehicles.get(clientValue);
}
}
Or something like that anyway...
--
View this message in context: http://www.nabble.com/AjaxFormLoop%3A-property-changes-have-no-effect-tp24754470p24793930.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org