Re: Forms created in a loop - problem with validation

2015-07-24 Thread Geoff Callender
These examples might help...

If you’re not using AJAX then it probably makes more sense to put the Form 
around the Loop:

T5.4: 
http://jumpstart.doublenegative.com.au/jumpstart7/examples/tables/editableloop1 
http://jumpstart.doublenegative.com.au/jumpstart7/examples/tables/editableloop1

http://jumpstart.doublenegative.com.au/jumpstart7/examples/tables/editableloopforupdate1
 
http://jumpstart.doublenegative.com.au/jumpstart7/examples/tables/editableloopforupdate1
T5.3: 
http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/editableloop1 
http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/editableloop1

http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/editableloopforupdate1
 
http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/editableloopforupdate1

If you’re using AJAX, then a Form per row works well:

T5.4: 
http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/formsinaloop 
http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/formsinaloop
T5.3: 
http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formsinaloop 
http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formsinaloop

Geoff

 On 24 Jul 2015, at 6:55 pm, Matthias Bieber mabi1...@gmx.de wrote:
 
 
 Hello,
  
 I have a loop that creates a few forms and I have implemented the onValidate 
 method to validate the input. If an error occours in the textarea of the 
 first form, the textareas of all other forms are marked as erroneous too, 
 although the forms and textareas have different IDs. Whats wrong?
  
 Thanks in advance.
 M.B.
  
  
 Source code:
  
 Index.java:
 public class Index
 {  
 @Property
 private int[] integers= { 1, 2, 3, 4, 5 };
 
 @Property
 private int anInteger;
 
 public Index()
 {
 }
 }
  
 Index.tml:
 html t:type=layout title=HelloWorld Index t:sidebarTitle=Framework 
 Version xmlns:t=http://tapestry.apache.org/schema/tapestry_5_3.xsd; 
 xmlns:p=tapestry:parameter
 t:Loop t:source=integers t:value=anInteger
 div${anInteger}/div
 t:MyForm id=anInteger /
 /t:Loop
 /html
  
 MyForm.java:
 
 public class MyForm
 {
 @Parameter(required=true)
 @Property
 private int id;
 
 @Property
 private String text;
 
 @InjectComponent
 private Form form;
 
 @InjectComponent
 private TextArea textarea;
 
 @Inject
 Logger logger;
 
 @Inject
 Messages messages;
 
 void onPrepareForSubmitFromForm(int id) {
 this.id = id;
 }
 public void onSuccess() {
 logger.info(onSuccess());
 }
 
 void onValidateFromForm() {
 logger.info(id:  + id);
 form.recordError(textarea, Error);
 }
 
 public String getFormId() {
 return form_ + id;
 }
 
 public String getTextareaId() {
 return textarea_ + id;
 }
 
 public String getSubmitId() {
 return submit_ + id;
 }
 }
  
 MyForm.tml:
  
 t:container xmlns:t=http://tapestry.apache.org/schema/tapestry_5_3.xsd; 
 xmlns:p=tapestry:parameter
 t:form t:id=form id=prop:formId t:context=id 
 t:textarea t:id=textarea id=prop:textareaId value=text 
 rows=3 cols=50 /
 t:submit t:id=submit id=prop:submitId class=btn btn-large 
 btn-primary value=Send /
 /t:form
 /t:container
  
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 



Re: Forms created in a loop - problem with validation

2015-07-24 Thread Lance Java
I think this is caused by the field being reused in the loop. You might
need to recordError with a FieldSnapshot.

Example here
http://t5stitch-lazan.rhcloud.com/mapbindingdemo