You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ben Janes <be...@se.bluewave.com> on 2003/12/17 10:28:02 UTC

BUG!!! FormFile

Hi


Further to my other mail I have tracked the source of my problem here....
org.apache.commons.beanutils.PropertyUtils#setSimpleProperty

The problem is that when you submit a form, with a file element and the user has left the file
elemet blank, it crashes.... The altered code below from line 1773 in PropertyUtils gives the
following output just before the error

descriptor.getWriteMethod():1:public void
com.meganexus.networking.struts.form.ChangeContactForm.setPhoto(org.apache.struts.upload.FormFile)
descriptor.getWriteMethod():2:public void
com.meganexus.networking.struts.form.ChangeContactForm.setPhoto(org.apache.struts.upload.FormFile)
params:interface org.apache.struts.upload.FormFile,value.getClass():class java.lang.String

So as you can see, the program expects a FormFile parameter, but gets a String....  Major error I
think


        // Retrieve the property setter method for the specified property
        PropertyDescriptor descriptor =
                getPropertyDescriptor(bean, name);
        if (descriptor == null) {
            throw new NoSuchMethodException("Unknown property '" +
                    name + "'");
        }
        System.out.println("descriptor.getWriteMethod():1:"+descriptor.getWriteMethod().toString());
        Method writeMethod = getWriteMethod(descriptor);
        System.out.println("descriptor.getWriteMethod():2:"+descriptor.getWriteMethod().toString());

        if (writeMethod == null) {
            throw new NoSuchMethodException("Property '" + name +
                    "' has no setter method");
        }
        System.out.print("params:");
        Class [] cls=writeMethod.getParameterTypes();
        for (int i=0;i<cls.length;i++) {
            System.out.print(cls[i].toString()+",");
        }
        System.out.println();
        // Call the property setter method
        Object values[] = new Object[1];
        values[0] = value;
        System.out.println("value.getClass():"+value.getClass());
        writeMethod.invoke(bean, values);
}

struts-user@jakarta.apache.org
Benjamin A. Janes
------------------------------------
BLUEWAVE SVERIGE

M. +46 (0)40-631 1068
F. +46 (0)40 -631 10 50
F. +46 (0)46-540 03 50
Drottninggatan 18,
S-211 49 Malmö,
Sweden



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: BUG!!! FormFile

Posted by Andrew Hill <an...@gridnode.com>.
Did you remember to make it a multipart form???
(And use input type="file" in the page?)


-----Original Message-----
From: Ben Janes [mailto:bej@se.bluewave.com]
Sent: Wednesday, 17 December 2003 17:28
To: struts-user@jakarta.apache.org
Subject: BUG!!! FormFile


Hi


Further to my other mail I have tracked the source of my problem here....
org.apache.commons.beanutils.PropertyUtils#setSimpleProperty

The problem is that when you submit a form, with a file element and the user
has left the file
elemet blank, it crashes.... The altered code below from line 1773 in
PropertyUtils gives the
following output just before the error

descriptor.getWriteMethod():1:public void
com.meganexus.networking.struts.form.ChangeContactForm.setPhoto(org.apache.s
truts.upload.FormFile)
descriptor.getWriteMethod():2:public void
com.meganexus.networking.struts.form.ChangeContactForm.setPhoto(org.apache.s
truts.upload.FormFile)
params:interface org.apache.struts.upload.FormFile,value.getClass():class
java.lang.String

So as you can see, the program expects a FormFile parameter, but gets a
String....  Major error I
think


        // Retrieve the property setter method for the specified property
        PropertyDescriptor descriptor =
                getPropertyDescriptor(bean, name);
        if (descriptor == null) {
            throw new NoSuchMethodException("Unknown property '" +
                    name + "'");
        }

System.out.println("descriptor.getWriteMethod():1:"+descriptor.getWriteMetho
d().toString());
        Method writeMethod = getWriteMethod(descriptor);

System.out.println("descriptor.getWriteMethod():2:"+descriptor.getWriteMetho
d().toString());

        if (writeMethod == null) {
            throw new NoSuchMethodException("Property '" + name +
                    "' has no setter method");
        }
        System.out.print("params:");
        Class [] cls=writeMethod.getParameterTypes();
        for (int i=0;i<cls.length;i++) {
            System.out.print(cls[i].toString()+",");
        }
        System.out.println();
        // Call the property setter method
        Object values[] = new Object[1];
        values[0] = value;
        System.out.println("value.getClass():"+value.getClass());
        writeMethod.invoke(bean, values);
}

struts-user@jakarta.apache.org
Benjamin A. Janes
------------------------------------
BLUEWAVE SVERIGE

M. +46 (0)40-631 1068
F. +46 (0)40 -631 10 50
F. +46 (0)46-540 03 50
Drottninggatan 18,
S-211 49 Malmö,
Sweden



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org