You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nquirynen <na...@pensionarchitects.be> on 2012/11/15 10:41:09 UTC

Form server side validation in zone

Hi,

I have a form where I do some server side validation on submit. This form is
in a zone and gets submitted with ajax. Now if I want the fields with errors
to be decorated accordingly, I have to update this zone.
If I don't want to update the full zone, but just decorate these fields with
javascript, should I write a Tapestry.initializer and call this with
AjaxResponseRenderer to which I pass field names and messages? Or is there a
better way / already built in way that I am failing to find?




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026.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


Re: Form server side validation in zone

Posted by nquirynen <na...@pensionarchitects.be>.
It is dynamic as the Form is part of a component and the content of this Form
is filled with informal parameter blocks.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718132.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


Re: Form server side validation in zone

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 15 Nov 2012 09:55:15 -0200, nquirynen  
<na...@pensionarchitects.be> wrote:

> - More client side validation feeling
> - avoid unnecessary rerendering, database queries, etc.
> - some elements in the zone that were visually altered with javascript  
> get reset to their initial state
> - ...

In this case, you're going beyond what a Zone can do. Right now, Tapestry  
doesn't have the support for what you want out-of-the-box. You'd need to  
write some JavaScript code to do the AJAX form submission then, in the  
server-side, get the error messages and their corresponding field ids,  
return them in a JSONObject and show the validation errors yourself. Or  
you could try to implement as much validation as possible client-side and  
only trigger AJAX requests for validations that need to be done  
server-side.

Zones are quite useful and can handle lots of AJAX situations very easily,  
but, of course, it doesn't cover everything nor it should, as it would  
need to be something very complex to write and use.

> Now I add errors using Form.recordError(Field field, String  
> errorMessage) in the onValidate event method.
> Then I hoped i could retrieve these errors and there accompanying Field.  
> But I only see Form.getDefaultTracker().getErrors() which returns just a
> List<String> of the error messages.

Yeah, we could have an improvement here. Feel free to post a JIRA for that.

> So I have no clue how to get a list of the needed fields to get their  
> id's.

Is this form created dinamically?

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form server side validation in zone

Posted by Lance Java <la...@googlemail.com>.
> ValidationTrackerImpl is final, so I cannot extend this class. But I found
ValidationTrackerWrapper class, maybe I should extend this?
Sounds good to me

> Do I set it as a persisted property?
It depends on which tapestry version you are using. Later versions of
tapestry will NOT need flash persistence. Later versions of tapestry do a
forward for validation errors instead of a redirect after post. This avoids
session creation for validation errors.

> And where do I set it's value? 
It's probably easiest to lazy init a field in a getter instead of @Property

   private ValidationFieldTracker validationTracker;

   public ValidationFieldTracker getValidationTracker() {
      if (validationTracker = null) {
         validationTracker = new ValidationFieldTracker(new
ValidationTrackerImpl());
      }
      return validationTracker;
   }



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718136.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


Re: Form server side validation in zone

Posted by nquirynen <na...@pensionarchitects.be>.
ValidationTrackerImpl is final, so I cannot extend this class. But I found
ValidationTrackerWrapper class, maybe I should extend this?

I'm trying something like this:

public class ValidationFieldTracker extends ValidationTrackerWrapper {
	
	private List<Field> fields;

	public ValidationFieldTracker(ValidationTracker delegate) {
		super(delegate);
	}

	public List<Field> getFields() {
		return fields;
	}
	
	@Override
	public void recordError(Field field, String errorMessage) {
		super.recordError(field, errorMessage);
		fields.add(field);
	}
}


I then need to set the tracker to the form like you suggested:

    <t:form t:id="trackedForm" tracker="validationTracker" ...>

But I'm not sure where and how to define/set this tracker. Do I set it as a
persisted property?

        @Persist(PersistenceConstants.FLASH)
	@Property
	private ValidationFieldTracker validationTracker;

And where do I set it's value?

      validationTracker = new
ValidationFieldTracker(trackedForm.getDefaultTracker());

Thanks for the help given already!

Nathan




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718135.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


Re: Form server side validation in zone

Posted by Lance Java <la...@googlemail.com>.
Actually, it's even easier... you don't need to worry about the
environmental.
1. Extend ValidationTrackerImpl and override the recordError() methods to
save the error fields
2. Pass your tracker to the form
   <t:form tracker="myTracker" ...>
3. Profit





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718134.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


Re: Form server side validation in zone

Posted by nquirynen <na...@pensionarchitects.be>.
Hmm I'm not sure I understand what you mean with, or how to achieve something
like that:


Lance Java wrote
> ValidationTracker is an environmental so you could wrap the existing
> ValidationTracker and push() the wrapper onto the environment and keep
> track of the fields this way.

Can you give me a bit of explanation of what to do?

Thanks Nathan





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718131.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


Re: Form server side validation in zone

Posted by Lance Java <la...@googlemail.com>.
ValidationTracker is an environmental so you could wrap the existing
ValidationTracker and push() the wrapper onto the environment and keep track
of the fields this way.

I wonder if you could have a hidden zone in the UI which gets updated when
the form is submitted. You then run some javascript over the hidden zone and
copy/move any interesting attributes from the hidden zone to the visible
form.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718033.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


Re: Form server side validation in zone

Posted by nquirynen <na...@pensionarchitects.be>.
- More client side validation feeling
- avoid unnecessary rerendering, database queries, etc.
- some elements in the zone that were visually altered with javascript get
reset to their initial state
- ...

It's not a big problem, but it would surely be better if I could avoid these
problems. But you are right that maybe it's some work to get it working
right.

Now I add errors using Form.recordError(Field field, String errorMessage) in
the onValidate event method.
Then I hoped i could retrieve these errors and there accompanying Field. But
I only see Form.getDefaultTracker().getErrors() which returns just a
List<String> of the error messages. So I have no clue how to get a list of
the needed fields to get their id's.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718030.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


Re: Form server side validation in zone

Posted by Lance Java <la...@googlemail.com>.
Although I'm sure it can be done... it sounds like a lot of effort for not
much gain. Why don't you want update the full zone?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-server-side-validation-in-zone-tp5718026p5718027.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