im not familiar with sakai so i cant really help there. like i said, set a breakpoint in getfileupload and see why it returns null. you can also try setting a breakpoint in form.onformsubmitted() and tracing how it is processing multipart.
-igor On Thu, Nov 6, 2008 at 9:28 AM, Steve Swinsburg <[EMAIL PROTECTED]> wrote: > Ok I generated a quickstart and added a form with a FileUploadField, it all > worked. > > This made me think that it was some changes I made in the web.xml file for > the original webapp - I am not running it as a normal webapp, but rather > inside another web framework (Sakai). As such, I needed to make some changes > to the web.xml in order for it to register itself with Sakai. Once I did > this to the quickstart, uploads failed again. > > Can you think of anything I have changed that would be affecting this? There > are other tools for Sakai written in Wicket which have fileuploads working, > and my web.xml is essentially the same. Could there be anything else that is > affecting it? > > The web.xml for the quickstart is this: > > <?xml version="1.0" encoding="ISO-8859-1"?> > <web-app xmlns="http://java.sun.com/xml/ns/j2ee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > version="2.4"> > > <display-name>file-upload</display-name> > > <!-- Sakai request filter --> > <filter> > <filter-name>sakai.request</filter-name> > > <filter-class>org.sakaiproject.util.RequestFilter</filter-class> > </filter> > <filter-mapping> > <filter-name>sakai.request</filter-name> > <servlet-name>file.upload</servlet-name> > <dispatcher>REQUEST</dispatcher> > <dispatcher>FORWARD</dispatcher> > <dispatcher>INCLUDE</dispatcher> > </filter-mapping> > > <!-- > <filter> > <filter-name>sakai.profile2.tool</filter-name> > > <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> > <init-param> > <param-name>applicationClassName</param-name> > > > <param-value>uk.ac.lancs.e_science.profile2.tool.ProfileApplication</param-value> > </init-param> > </filter> > --> > > <!-- > <filter-mapping> > <filter-name>sakai.profile2.tool</filter-name> > <url-pattern>/sakai-profile2-tool/*</url-pattern> > </filter-mapping> > --> > > <!-- Change the 'applicationBean' param value to the name of your > application as > listed under the applicationContext.xml --> > <servlet> > <servlet-name>file.upload</servlet-name> > > <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class> > > <init-param> > <param-name>applicationFactoryClassName</param-name> > > > <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value> > </init-param> > <init-param> > <param-name>applicationBean</param-name> > <param-value>uploadApplication</param-value> > </init-param> > </servlet> > > <!-- Wicket likes to have a url-pattern mapping even though Sakai > doesn't use it. --> > <servlet-mapping> > <servlet-name>file.upload</servlet-name> > <url-pattern>/file-upload/*</url-pattern> > </servlet-mapping> > > <context-param> > <param-name>configuration</param-name> > <param-value>development</param-value> > <!-- <param-value>deployment</param-value> --> > </context-param> > > <!-- Sakai listeners --> > <listener> > > <listener-class>org.sakaiproject.util.ToolListener</listener-class> > </listener> > <listener> > > <listener-class>org.sakaiproject.util.ContextLoaderListener</listener-class> > </listener> > </web-app> > > > and the applicationContext.xml: > > > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" > "http://www.springframework.org/dtd/spring-beans.dtd"> > > <beans> > > <!-- The id of this bean needs to match the param 'applicationBean' > under your web.xml --> > <bean id="uploadApplication" class="com.steve.WicketApplication" /> > > </beans> > > > thanks, > Steve > > > On 6 Nov 2008, at 16:03, Igor Vaynberg wrote: > >> 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] >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
