You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephan Windmüller <st...@cs.tu-dortmund.de> on 2009/08/14 11:55:33 UTC
Upload component in onValidate
Hello!
We are using the upload component of tapestry and want to validate the
content type during the upload. To accomplish this we wrote the
following code:
| @Property
| private UploadedFile file;
|
| [...]
|
| void onValidate() {
|
| if(file.getContentType().toLowerCase(Locale.ENGLISH)
| .equals("application/pdf")) {
| [...]
| }
| }
To our surprise, the field "file" is always null during the validation,
but not in onSuccess.
Is it not possible to validate this? Or do we have to put a manual
validation in onSuccess?
TIA
Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: Antwort: Re: Upload component in onValidate
Posted by "Newham, Cameron" <ca...@bl.uk>.
>From JumpStart for a Form it is:
pageAttached()
onActivate()
...onPrepareForSubmit()
...onPrepare()
...onSelected()
...onValidateForm()
...onSuccess()
...onSubmit()
...Tapestry creates a URL to next page
pageDetached()
...Tapestry redirects to render next page
-----Original Message-----
...
The order of events seems to be now:
onValidate()
setters
onValidateForm()
onSuccess()/onFailure()
onSubmit
I didn't find a summary in the docs on the exact order, and on the
default
event method names (that incorporate the form id).
Also, I don't know what happens if there is, for example, a onSubmit(),
onSubmitFromXXX() and a method annotated with @OnEvent(value="submit",
component="XXX")
in the page.
So, in short, try using onValidateForm() instead of onValidate().
Dirk
**************************************************************************
Experience the British Library online at www.bl.uk
The British Library's new interactive Annual Report and Accounts 2007/08 : www.bl.uk/knowledge
Help the British Library conserve the world's knowledge. Adopt a Book. www.bl.uk/adoptabook
The Library's St Pancras site is WiFi - enabled
*************************************************************************
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the postmaster@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
*************************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Antwort: Re: Upload component in onValidate
Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
dirk.lattermann@bgs-ag.de wrote:
> So, in short, try using onValidateForm() instead of onValidate().
That solved my problem. Thank you very much for this simple solution!
Regards
Stephan Windmüller
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Antwort: Re: Upload component in onValidate
Posted by di...@bgs-ag.de.
> 2009/8/14 Stephan Windmüller <st...@cs.tu-dortmund.de>
>
> > Hello!
> >
> > We are using the upload component of tapestry and want to validate the
> > content type during the upload. To accomplish this we wrote the
> > following code:
> >
> > | @Property
> > | private UploadedFile file;
> > |
> > | [...]
> > |
> > | void onValidate() {
> > |
> > | if(file.getContentType().toLowerCase(Locale.ENGLISH)
> > | .equals("application/pdf")) {
> > | [...]
> > | }
> > | }
> >
> > To our surprise, the field "file" is always null during the
validation,
> > but not in onSuccess.
> >
I had a similar problem recently, although with ordinary form validation,
not with upload. So I'm not sure this is relevant.
I also used onValidate() to do the form validation as it is explained in
my Tapestry5 book (Kolesnikov). It turned out that
this method is called before the setters of the properties used in the
form, so the properties were still null in onValidate().
Looking around in the online docs, I found that there is onValidateForm()
which is called after the setters.
Maybe this has changed in some recent tapestry version.
The order of events seems to be now:
onValidate()
setters
onValidateForm()
onSuccess()/onFailure()
onSubmit
I didn't find a summary in the docs on the exact order, and on the default
event method names (that incorporate the form id).
Also, I don't know what happens if there is, for example, a onSubmit(),
onSubmitFromXXX() and a method annotated with @OnEvent(value="submit",
component="XXX")
in the page.
So, in short, try using onValidateForm() instead of onValidate().
Dirk
BGS Beratungsgesellschaft
Software Systemplanung AG Niederlassung Köln/Bonn
Grantham-Allee 2-8
53757 Sankt Augustin
Fon: +49 (0) 2241 / 166-500
Fax: +49 (0) 2241 / 166-680
www.bgs-ag.de Geschäftssitz Mainz
Registergericht
Amtsgericht Mainz
HRB 62 50
Aufsichtsratsvorsitzender
Klaus Hellwig
Vorstand
Hermann Kiefer
Nils Manegold
Thomas Reitz
Re: Upload component in onValidate
Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Otho wrote:
> From skimming the sources I would guess that you need to provide your own
> FieldValidator<Object> as a component parameter to <t:upload>
Thanks for the quick reply!
I wrote the FieldValidator, but where do I register it and how do I set
the component parameter?
<t:upload t:validate="myValidator"> gives me this error:
| Unknown validator type 'myValidator'. Configured validators are email,
| max, maxlength, min, minlength, regexp, required.
The class contains this code:
| public FieldValidator<UploadedFile> getMyValidator() {
| return new FieldValidator<UploadedFile>() {
| ...
| }
| }
Is there any documentation about how to use custom field validators?
Regards
Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Upload component in onValidate
Posted by Otho <ta...@googlemail.com>.
>From skimming the sources I would guess that you need to provide your own
FieldValidator<Object> as a component parameter to <t:upload>
2009/8/14 Stephan Windmüller <st...@cs.tu-dortmund.de>
> Hello!
>
> We are using the upload component of tapestry and want to validate the
> content type during the upload. To accomplish this we wrote the
> following code:
>
> | @Property
> | private UploadedFile file;
> |
> | [...]
> |
> | void onValidate() {
> |
> | if(file.getContentType().toLowerCase(Locale.ENGLISH)
> | .equals("application/pdf")) {
> | [...]
> | }
> | }
>
> To our surprise, the field "file" is always null during the validation,
> but not in onSuccess.
>
> Is it not possible to validate this? Or do we have to put a manual
> validation in onSuccess?
>
> TIA
> Stephan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Upload component in onValidate
Posted by Ulrich Stärk <ul...@spielviel.de>.
onValidate() gets called for every form component inside your form. The NullPointerException you are
getting is likely due to some other form component also validating. Change the method name to match
your upload component's id, e.g. onValidateFromUpload() if your component's id is upload. That
should do the trick. onValidateForm() can be used to do validation across multiple fields and isn't
meant to do validation for just one field.
Uli
On 14.08.2009 11:55 schrieb Stephan Windmüller:
> Hello!
>
> We are using the upload component of tapestry and want to validate the
> content type during the upload. To accomplish this we wrote the
> following code:
>
> | @Property
> | private UploadedFile file;
> |
> | [...]
> |
> | void onValidate() {
> |
> | if(file.getContentType().toLowerCase(Locale.ENGLISH)
> | .equals("application/pdf")) {
> | [...]
> | }
> | }
>
> To our surprise, the field "file" is always null during the validation,
> but not in onSuccess.
>
> Is it not possible to validate this? Or do we have to put a manual
> validation in onSuccess?
>
> TIA
> Stephan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org