code looks ok, interesting. there are two things we can do: a) you can create a quickstart that reproduces the problem b) you can set a breakpoint in fileuploadfield#getfileupload() and see why it returns null
a couple of other notes: since you are getting fileupload yourself there is no need to give the field a model you are passing in userprofile directly into the panel, most likely it needs to be a loadabledetachablemodel that can load it from the db. -igor On Thu, Nov 6, 2008 at 3:41 AM, Steve Swinsburg <[EMAIL PROTECTED]> wrote: > Sure thing. Essentially, a POJO called UserProfile is a param of the > constructor for the form. One thing that is probably the issue is that I > wasn't sure how to assign an upload field to a corresponding attribute in > the POJO, is this even necessary? > Its so simple so at this stage its all in the constructor for the class: > public class ChangeProfilePicture extends Panel{ > > > > private FileUploadField uploadField; > > > > > > public ChangeProfilePicture(String id, UserProfile userProfile) { > super(id); > > > > //create model > CompoundPropertyModel userProfileModel = new > CompoundPropertyModel(userProfile); > > > > //setup form > Form form = new Form("form", userProfileModel) { > public void onSubmit(){ > > //get the backing model > UserProfile userProfile = (UserProfile) this.getModelObject(); > > //get uploaded file, get the bytes and set into sakaiPerson. > if (uploadField != null) { > System.out.println("1 - uploadField not null"); > FileUpload upload = uploadField.getFileUpload(); > if(upload != null) { > System.out.println("2 - upload not null"); > byte[] photoBytes = upload.getBytes(); > } > } > > } > > }; > > form.setOutputMarkupId(true); > form.setMultiPart(true); > > > > //text > Label textSelectImage = new Label("textSelectImage", new > ResourceModel("text.upload.image.file")); > form.add(textSelectImage); > > //upload > uploadField = new FileUploadField("picture", new PropertyModel(userProfile, > "picture")); > form.add(uploadField); > > //submit button > Button submitButton = new Button("submit", new > ResourceModel("button.upload")); > > form.add(submitButton); > > //add form to page > add(form); > } > > } > > Thanks for any assistance. > > > cheers, > Steve > > > > > > > On 6 Nov 2008, at 11:34, James Carman wrote: > > Can you share your code that builds up the component hierarchy? At > least the relevant parts? We'll need to see what kind of model the > form has and stuff like that. > > On Thu, Nov 6, 2008 at 5:58 AM, Steve Swinsburg > <[EMAIL PROTECTED]> wrote: > > Nope, the form works fine, it just never reaches the line: > > System.out.println("2 - upload not null"); > > Or do you mean HTML validation errors? Thats fine as well: > > <wicket:panel> > > <form wicket:id="form" class="profileForm"> > > <p wicket:id="textSelectImage" class="small">Select an image</p> > > <p><input type="file" wicket:id="picture"/></p> > > <p><input type="submit" wicket:id="submit" value="Upload" /></p> > > </form> > > </wicket:panel> > > This panel is shown by a jQuery slideToggle() after someone clicks on a > > button, but its a normal form submit. Even when the form is always visible, > > ie no Javascript to show it, same thing. > > Any ideas? > > Thanks > > > On 5 Nov 2008, at 18:33, Igor Vaynberg wrote: > > are there validation errors? > > -igor > > On Wed, Nov 5, 2008 at 10:14 AM, Steve Swinsburg > > <[EMAIL PROTECTED]> wrote: > > Hi all, > > I'm having an odd problem in uploading a file where the result of: > > FileUpload upload = uploadField.getFileUpload(); > > is always null. I can't see what I've done wrong. > > Here's part of my onSubmit method which works for textfields, but not > > fileuploads. It's a normal fileupload by the way (so its not an AJAX issue): > > public void onSubmit(){ > > if (uploadField != null) { > > System.out.println("1 - uploadField not null"); > > FileUpload upload = uploadField.getFileUpload(); > > if(upload != null) { > > System.out.println("2 - upload not null"); > > byte[] photoBytes = upload.getBytes(); > > } > > } > > } > > where uploadField is defined in the class like so: > > private FileUploadField uploadField; > > and then added to the form: > > uploadField = new FileUploadField("picture"); > > form.add(uploadField); > > So the form works as expected for textfields but not fileuploads. Can anyone > > spot any issues/give me pointers? The form is multipart encoded. > > > thanks. > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]