Thinking about this a bit more, you can probably avoid @Persist by using an
appropriate ValueEncoder.

eg:
<t:ajaxformloop t:id="foos" source="foos" value="foo"
encoder="lazyEncoder">...</t:ajaxformloop>

public class LazyValueEncoder<T> implements ValueEncoder<T> {
   private static final String CLIENT_NULL = "XXX";
   private ValueEncoder<T> encoder;
   private Class<T> type;
   public LazyValueEncoder<T>(ValueEncoderSource source, Class<T> type) {
      this.encoder = source.getValueEncoder(type);
      this.type = type;
   }
   public String toClient(T value) {
      if (value == null) {
         return CLIENT_NULL;
      }
      return encoder.toClient(value);
   }
   public T toValue(String client) {
      if (CLIENT_NULL.equals(client)) {
         return type.newInstance();
      }
      return encoder.toValue(client);
   }
}

public class MyPage {
   @Property private List<Foo> foos;
   @Property private Foo foo;
   @Inject private ValueEncoderSource source;

   public ValueEncoder<Foo> getLazyEncoder() {
      return new LazyValueEncoder(source, Foo.class);
   }

   public Foo onAddRowFromFoos() {
      return null;
   }
}

Warning: Untested code

Reply via email to