You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Medha Kamat <Me...@lombardrisk.com> on 2007/06/15 11:59:45 UTC

how to instantiate a FormFile Object

I have a form that uploads a file.Form uses FormFile object for
uploading of the file.Uploading works just fine.Problem i am having is
while wrtitng automated test.
I the test i am seting a form using setActionForm.Now as i mentioned in
this form i want to set a FormFile object and that's where i am
struggling
 
HolidayFeedUploadForm holidayFeedForm = new HolidayFeedUploadForm();
DiskFileItem fileItem = new
DiskFileItem("uploadFile","application/vnd.ms-excel,text/xml",true,
"myfileName",1200, null); 
CommonsMultipartRequestHandler mp = new
CommonsMultipartRequestHandler();
CommonsMultipartRequestHandler.CommonsFormFile dd =  mp.new
CommonsFormFile(fileItem);
setActionForm(holidayFeedForm);    

It compalins about visiblity of CommonsMultipartRequestHandler.
CommonsFormFile.I know that CommonsFormFile is an inner class and
package access is private.All i want to do is create a new FormFile
object and set it on the form.How would i achieve that? 
 
 
Regards
Medha 
 
 
 

Re: how to instantiate a FormFile Object

Posted by jiucenglou <li...@hotmail.com>.
you can use Reflection to instantiate it

code may be like this:
============
Class parentClass =
Class.forName("org.apache.struts.upload.CommonsMultipartRequestHandler");
Class childClass = parentClass .getDeclaredClasses()[0];
Constructor c = childClass .getConstructors()[0]; 
c.setAccessible(true);
			
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1000*1000*10);
factory.setRepository(new File("fileTempFolder"));
FileItem fileItem = factory.createItem("uploadfile", "application/pdf",
true, "hehe");
FormFile file = (FormFile)c.newInstance(new Object[] {fileItem});
c.setAccessible(false); 

============
-- 
View this message in context: http://www.nabble.com/how-to-instantiate-a--FormFile-Object-tf3926868.html#a11198967
Sent from the Struts - Dev mailing list archive at Nabble.com.


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


Re: how to instantiate a FormFile Object

Posted by jiucenglou <li...@hotmail.com>.
you can use Reflection to instantiate it
-- 
View this message in context: http://www.nabble.com/how-to-instantiate-a--FormFile-Object-tf3926868.html#a11198967
Sent from the Struts - Dev mailing list archive at Nabble.com.


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