> 2009/8/14 Stephan Windmüller <stephan.windmuel...@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