You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Franklin Antony <fr...@gmail.com> on 2007/11/12 16:28:11 UTC

Multi-file upload and ListView together

Dear Friends,
   I am having a problem with putting MultiFileUploadField inside a
ListView. I am following the example, but somehow the uploads collection is
not getting populated with the files. However when I directly add the
MultiFileUploadField  on a form everything seems to work. Could someone
please shed some light on this.

Here is some code snippet

            List ls = Arrays.asList(new String[]{"Passport "});
            ListView pl = new ListView("plist",ls)
            { 
                      	
				protected void populateItem(ListItem arg0) {
										
					
					MultiFileUploadField ff=new MultiFileUploadField("file_input",new
PropertyModel(this,"uploads"),3);
					
					fileUploadList.add(ff);
					fileUpload.add(ff);
	            	arg0.add(ff);
	
					
	
					
				}
            	
            	
            };


And the listview is on a form and the collections(uploads) is on the form to
just as in the example. I am sure its something with the component
hierarchy. But not sure how to call the uploads correctly. I think there is
something wrong with the expression.


Thanks,
Franklin
-- 
View this message in context: http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13707621
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Multi-file upload and ListView together

Posted by Franklin Antony <fr...@gmail.com>.
I need to give it a Model that holds a collection so I did something like
this

Model mode = new Model()
{
    Object getObject()
    {
        Collection holder = new ArrayList();
        return holder;
    }

}


Then I do this.

MultiFileUploadField ff=new MultiFileUploadField("file_input",model,3);

Still it gives problems. I still dont know how will I get a handle on all
the files I have added.
Please correct me if I am wrong somewhere


Again this is a MultiFileUploadField in a ListView which is on a From. I
just want to know where should I define my collections. Should be on the
Page or Form or somewhere else.

Thanks,
Franklin.




Johan Compagner wrote:
> 
> you could try with a simpler model? and see if that works? (so just new
> Model())
> 
> On Nov 13, 2007 8:22 AM, Franklin Antony <fr...@gmail.com> wrote:
> 
>>
>> Thanks Igor but it doesnt seem to work still.
>>
>> Just some more hints:
>>
>> I have the listview on a form and the form is on the page.
>> The uploads collection object is on the form.
>> It keeps telling me that there is no such uploads object on the page and
>> so
>> I changed the call from
>>
>> MultiFileUploadField ff=new MultiFileUploadField("file_input",new
>> PropertyModel(this,"uploads"),3);
>>
>> to
>>
>> MultiFileUploadField ff=new MultiFileUploadField("file_input",new
>> PropertyModel(MyForm.this,"uploads"),3);
>>
>> Still doest work.
>>
>>
>> So now i add the collections uploads directly to the page and make call
>> like
>> this
>>
>>
>> MultiFileUploadField ff=new MultiFileUploadField("file_input",new
>> PropertyModel(MyPage.this,"uploads"),3);
>>
>> Now there is some light in this direction. Only the last set of files in
>> the
>> listview go inside the uploads collection.
>>
>>
>> I really wish if someone could shed some light on this. Wicket has been
>> so
>> easy to use up to now. But I am getting confused with how it will handle
>> the
>> model in case of reapeaters. I need all the repeaters to use the same
>> collections object.
>>
>>
>> Thanks for all the help Igor,
>> Franklin
>>
>>
>>
>> igor.vaynberg wrote:
>> >
>> > did you call listview.setreuseitems(true)
>> >
>> > it is usually easier if you provide a quickstart...
>> >
>> > -igor
>> >
>> >
>> > On Nov 12, 2007 7:28 AM, Franklin Antony <fr...@gmail.com>
>> wrote:
>> >>
>> >> Dear Friends,
>> >>    I am having a problem with putting MultiFileUploadField inside a
>> >> ListView. I am following the example, but somehow the uploads
>> collection
>> >> is
>> >> not getting populated with the files. However when I directly add the
>> >> MultiFileUploadField  on a form everything seems to work. Could
>> someone
>> >> please shed some light on this.
>> >>
>> >> Here is some code snippet
>> >>
>> >>             List ls = Arrays.asList(new String[]{"Passport "});
>> >>             ListView pl = new ListView("plist",ls)
>> >>             {
>> >>
>> >>                                 protected void populateItem(ListItem
>> >> arg0) {
>> >>
>> >>
>> >>                                         MultiFileUploadField ff=new
>> >> MultiFileUploadField("file_input",new
>> >> PropertyModel(this,"uploads"),3);
>> >>
>> >>                                         fileUploadList.add(ff);
>> >>                                         fileUpload.add(ff);
>> >>                         arg0.add(ff);
>> >>
>> >>
>> >>
>> >>
>> >>                                 }
>> >>
>> >>
>> >>             };
>> >>
>> >>
>> >> And the listview is on a form and the collections(uploads) is on the
>> form
>> >> to
>> >> just as in the example. I am sure its something with the component
>> >> hierarchy. But not sure how to call the uploads correctly. I think
>> there
>> >> is
>> >> something wrong with the expression.
>> >>
>> >>
>> >> Thanks,
>> >> Franklin
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13707621
>> >> Sent from the Wicket - User mailing list archive at
>> Nabble.com<http://nabble.com/>
>> .
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13720963
>>  Sent from the Wicket - User mailing list archive at
>> Nabble.com<http://nabble.com/>
>> .
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13722270
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Multi-file upload and ListView together

Posted by Johan Compagner <jc...@gmail.com>.
you could try with a simpler model? and see if that works? (so just new
Model())

On Nov 13, 2007 8:22 AM, Franklin Antony <fr...@gmail.com> wrote:

>
> Thanks Igor but it doesnt seem to work still.
>
> Just some more hints:
>
> I have the listview on a form and the form is on the page.
> The uploads collection object is on the form.
> It keeps telling me that there is no such uploads object on the page and
> so
> I changed the call from
>
> MultiFileUploadField ff=new MultiFileUploadField("file_input",new
> PropertyModel(this,"uploads"),3);
>
> to
>
> MultiFileUploadField ff=new MultiFileUploadField("file_input",new
> PropertyModel(MyForm.this,"uploads"),3);
>
> Still doest work.
>
>
> So now i add the collections uploads directly to the page and make call
> like
> this
>
>
> MultiFileUploadField ff=new MultiFileUploadField("file_input",new
> PropertyModel(MyPage.this,"uploads"),3);
>
> Now there is some light in this direction. Only the last set of files in
> the
> listview go inside the uploads collection.
>
>
> I really wish if someone could shed some light on this. Wicket has been so
> easy to use up to now. But I am getting confused with how it will handle
> the
> model in case of reapeaters. I need all the repeaters to use the same
> collections object.
>
>
> Thanks for all the help Igor,
> Franklin
>
>
>
> igor.vaynberg wrote:
> >
> > did you call listview.setreuseitems(true)
> >
> > it is usually easier if you provide a quickstart...
> >
> > -igor
> >
> >
> > On Nov 12, 2007 7:28 AM, Franklin Antony <fr...@gmail.com>
> wrote:
> >>
> >> Dear Friends,
> >>    I am having a problem with putting MultiFileUploadField inside a
> >> ListView. I am following the example, but somehow the uploads
> collection
> >> is
> >> not getting populated with the files. However when I directly add the
> >> MultiFileUploadField  on a form everything seems to work. Could someone
> >> please shed some light on this.
> >>
> >> Here is some code snippet
> >>
> >>             List ls = Arrays.asList(new String[]{"Passport "});
> >>             ListView pl = new ListView("plist",ls)
> >>             {
> >>
> >>                                 protected void populateItem(ListItem
> >> arg0) {
> >>
> >>
> >>                                         MultiFileUploadField ff=new
> >> MultiFileUploadField("file_input",new
> >> PropertyModel(this,"uploads"),3);
> >>
> >>                                         fileUploadList.add(ff);
> >>                                         fileUpload.add(ff);
> >>                         arg0.add(ff);
> >>
> >>
> >>
> >>
> >>                                 }
> >>
> >>
> >>             };
> >>
> >>
> >> And the listview is on a form and the collections(uploads) is on the
> form
> >> to
> >> just as in the example. I am sure its something with the component
> >> hierarchy. But not sure how to call the uploads correctly. I think
> there
> >> is
> >> something wrong with the expression.
> >>
> >>
> >> Thanks,
> >> Franklin
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13707621
> >> Sent from the Wicket - User mailing list archive at Nabble.com<http://nabble.com/>
> .
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13720963
>  Sent from the Wicket - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Multi-file upload and ListView together

Posted by Franklin Antony <fr...@gmail.com>.
Thanks Igor but it doesnt seem to work still.

Just some more hints:

I have the listview on a form and the form is on the page.
The uploads collection object is on the form.
It keeps telling me that there is no such uploads object on the page and so
I changed the call from

MultiFileUploadField ff=new MultiFileUploadField("file_input",new
PropertyModel(this,"uploads"),3);

to

MultiFileUploadField ff=new MultiFileUploadField("file_input",new
PropertyModel(MyForm.this,"uploads"),3);

Still doest work.


So now i add the collections uploads directly to the page and make call like
this 


MultiFileUploadField ff=new MultiFileUploadField("file_input",new
PropertyModel(MyPage.this,"uploads"),3);

Now there is some light in this direction. Only the last set of files in the
listview go inside the uploads collection. 


I really wish if someone could shed some light on this. Wicket has been so
easy to use up to now. But I am getting confused with how it will handle the
model in case of reapeaters. I need all the repeaters to use the same
collections object.


Thanks for all the help Igor,
Franklin



igor.vaynberg wrote:
> 
> did you call listview.setreuseitems(true)
> 
> it is usually easier if you provide a quickstart...
> 
> -igor
> 
> 
> On Nov 12, 2007 7:28 AM, Franklin Antony <fr...@gmail.com> wrote:
>>
>> Dear Friends,
>>    I am having a problem with putting MultiFileUploadField inside a
>> ListView. I am following the example, but somehow the uploads collection
>> is
>> not getting populated with the files. However when I directly add the
>> MultiFileUploadField  on a form everything seems to work. Could someone
>> please shed some light on this.
>>
>> Here is some code snippet
>>
>>             List ls = Arrays.asList(new String[]{"Passport "});
>>             ListView pl = new ListView("plist",ls)
>>             {
>>
>>                                 protected void populateItem(ListItem
>> arg0) {
>>
>>
>>                                         MultiFileUploadField ff=new
>> MultiFileUploadField("file_input",new
>> PropertyModel(this,"uploads"),3);
>>
>>                                         fileUploadList.add(ff);
>>                                         fileUpload.add(ff);
>>                         arg0.add(ff);
>>
>>
>>
>>
>>                                 }
>>
>>
>>             };
>>
>>
>> And the listview is on a form and the collections(uploads) is on the form
>> to
>> just as in the example. I am sure its something with the component
>> hierarchy. But not sure how to call the uploads correctly. I think there
>> is
>> something wrong with the expression.
>>
>>
>> Thanks,
>> Franklin
>> --
>> View this message in context:
>> http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13707621
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13720963
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Multi-file upload and ListView together

Posted by Igor Vaynberg <ig...@gmail.com>.
did you call listview.setreuseitems(true)

it is usually easier if you provide a quickstart...

-igor


On Nov 12, 2007 7:28 AM, Franklin Antony <fr...@gmail.com> wrote:
>
> Dear Friends,
>    I am having a problem with putting MultiFileUploadField inside a
> ListView. I am following the example, but somehow the uploads collection is
> not getting populated with the files. However when I directly add the
> MultiFileUploadField  on a form everything seems to work. Could someone
> please shed some light on this.
>
> Here is some code snippet
>
>             List ls = Arrays.asList(new String[]{"Passport "});
>             ListView pl = new ListView("plist",ls)
>             {
>
>                                 protected void populateItem(ListItem arg0) {
>
>
>                                         MultiFileUploadField ff=new MultiFileUploadField("file_input",new
> PropertyModel(this,"uploads"),3);
>
>                                         fileUploadList.add(ff);
>                                         fileUpload.add(ff);
>                         arg0.add(ff);
>
>
>
>
>                                 }
>
>
>             };
>
>
> And the listview is on a form and the collections(uploads) is on the form to
> just as in the example. I am sure its something with the component
> hierarchy. But not sure how to call the uploads correctly. I think there is
> something wrong with the expression.
>
>
> Thanks,
> Franklin
> --
> View this message in context: http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13707621
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Multi-file upload and ListView together

Posted by Suad AlShamsi <su...@gmail.com>.
Hi Frank,
    The multiFileUpload uses a collection to store the uploaded files. 
If you want to have N number of MultiFileUpload then u need N number of 
collections. So basiclly u need a collection of collection. The first 
one is to represent each multiFileUpload component and the the second is 
to hold the uploaded files. Have a look at the sample code.

fBeans is a list of fbean, which store the description of the file, the 
number of copies, and the collection where the files will be store.



setModel(new CompoundPropertyModel(fBeans));
           
            ListView view = new ListView("fileViewList", fBeans)
            {

                protected void populateItem(ListItem item) {
                   
                    Fbean f = (Fbean) item.getModelObject();
                    item.add(new Label("desc", f.getDesc()+" : "));
                    item.add(new MultiFileUploadField("fileInput", new 
PropertyModel((Fbean) item.getModelObject(), "uploads"), f.getCopies()));
                }
               
            };

Regards,
Al Shamsi

Franklin Antony wrote:
> Dear All,
>    I am badly in need to implement this. Therefore I am placing the code
> here.... I really didnt want to do this. I have a feeling I am placing the
> collections in the wrong place.
>
>
> import java.io.File;
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Arrays;
> import java.util.Collection;
> import java.util.Date;
> import java.util.Iterator;
> import java.util.List;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.wicket.Application;
> import org.apache.wicket.Component;
> import org.apache.wicket.PageParameters;
> import
> org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.form.TextField;
> import org.apache.wicket.markup.html.form.upload.FileUpload;
> import org.apache.wicket.markup.html.form.upload.FileUploadField;
> import org.apache.wicket.markup.html.form.upload.MultiFileUploadField;
> import org.apache.wicket.markup.html.link.BookmarkablePageLink;
> import org.apache.wicket.markup.html.link.Link;
> import org.apache.wicket.markup.html.link.PopupSettings;
> import org.apache.wicket.markup.html.list.ListItem;
> import org.apache.wicket.markup.html.list.ListView;
> import org.apache.wicket.markup.html.list.PageableListView;
> import org.apache.wicket.markup.html.panel.FeedbackPanel;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.LoadableDetachableModel;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.model.PropertyModel;
> import org.apache.wicket.util.file.Files;
> import org.apache.wicket.util.file.Folder;
> import org.apache.wicket.util.lang.Bytes;
> import org.apache.wicket.util.tester.DummyHomePage;
>
> import com.datelservices.domain.Attachment;
> import com.datelservices.util.upload.dao.PassportDocDAO;
>
> public class FileUploadPage extends WebPage{
> 	
> 	 
>      public  List fileUpload = new ArrayList();
>        
>      
> 	 public  Collection pageUploads = new ArrayList();
> 	 
>      public Collection getPageUploads()
>      {
>      	return pageUploads;
>      }
> 	 
> 	 
> 	 PropertyModel  pmPage ;
> 	
>
>    
>
>     private class FileUploadForm extends Form
>     {
>
>
>         private  Collection formUploads = new ArrayList();
>         PropertyModel  pmForm =new PropertyModel(this,"formUploads");        
>
>         
>         
>         public Collection getFormUploads()
>         {
>         	return formUploads;
>         }
>         
>         
>         public FileUploadForm(String name)
>         {
>             super(name);
>             
>             setMultiPart(true);
>             
>
>             
>             
>             List ls = Arrays.asList(new String[]{"Passport ","Scan ","Many
> More "});
>             //FileListView pl = new FileListView("plist",ls);
>             
>             
>             ListView pl = new ListView("plist",ls) 
>             { 
>             	
> 				protected void populateItem(ListItem arg0) {
> 					
> 					MultiFileUploadField ff=new MultiFileUploadField("file_input",new
> PropertyModel(FileUploadPage.this,"pageUploads"),3);
> 	            	arg0.add(ff);
> 					arg0.add(new Label("lbb",arg0.getModelObjectAsString()));
> 					
> 				}
>             	
>             };
>             
>             pl.setReuseItems(true);
>             add(pl);
>             
>             
>             
>
>
>             // Set maximum size 
>             double maxLimit =
> ((UploadApplication)Application.get()).getConfigProperty().getMaxFileUploadSize();
>             System.out.println("File upload limit is " + maxLimit);
>             setMaxSize(Bytes.kilobytes(maxLimit));
>         }
>
>         /**
>          * @see org.apache.wicket.markup.html.form.Form#onSubmit()
>          */
>         protected void onSubmit() {
>         
> System.out.println("$$$$$$$$$$$uploads1$$$$$$$$$$$$"+getFormUploads().iterator().hasNext());
>         
> //System.out.println("$$$$$$$$$$$uploads2$$$$$$$$$$$$"+((ArrayList)pmPage.getObject()).size());
>         
> //System.out.println("$$$$$$$$$$$uploads2.1$$$$$$$$$$$$"+((ArrayList)FileUploadPage.this.pmPage.getObject()).size());
>         
> //System.out.println("$$$$$$$$$$$uploads3$$$$$$$$$$$$"+((ArrayList)pmForm.getObject()).size());
>         
> System.out.println("$$$$$$$$$$$uploads5$$$$$$$$$$$$"+fileUpload.size());
>         
> System.out.println("$$$$$$$$$$$uploads99$$$$$$$$$$$$"+FileUploadForm.this.formUploads.size());
>         
> System.out.println("$$$$$$$$$$$uploads99$$$$$$$$$$$$"+FileUploadPage.this.pageUploads.size());        	
>         	
>         	
>         	
>         	System.out.println("getting iterator");
>         	 //Iterator it =
> ((ArrayList)FileUploadPage.this.pm.getObject()).iterator();
>         	 Iterator it = fileUpload.iterator();
>         	 
>         	 System.out.println("got iterator");    
>
>          }
>
>
>         	
>         
>
>     }    
>     
>     private int uploadFile(final FileUpload upload , String comments, int
> docTypeCD){
>  
>     	if( !upload.getClientFileName().toLowerCase().endsWith(".gif") ){
>     		FileUploadPage.this.info("Can not upload file : " +
> upload.getClientFileName() +". Only GIF file can be uploaded.");
>     		return -1;
>     	} 
>
>     	// Create a new file
>     	PassportDocDAO passportDAO =
> ((UploadApplication)Application.get()).getPassportDocDAO();
>     	passportDAO.setComments(comments);
>     	passportDAO.setDocDate(new Date());
>     	passportDAO.setDocTypeCD(docTypeCD);
>     	try {
> 			passportDAO.savePassportDataStream(upload.getInputStream(), (int)
> upload.getSize());
> 		} catch (IOException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 			throw new IllegalStateException("Unable to write file");
> 		}
> 		passportDAO.setUserPassportId(1);
> 		passportDAO.setVersion(0);
> 		int docId =
> ((UploadApplication)Application.get()).getIFilePersistService().persistFile(passportDAO);
> 		FileUploadPage.this.info("saved file: " + upload.getClientFileName());
>
> 		return docId;
>     }
>
>
>     /** Log. */
>     private static final Log log = LogFactory.getLog(FileUploadPage.class);
>
>
>     /**
>      * Constructor.
>      * 
>      * @param parameters
>      *            Page parameters
>      */
>     public FileUploadPage(final PageParameters parameters)
>     {
>         Folder uploadFolder = getUploadFolder();
>         
>         // Create feedback panels
>         final FeedbackPanel uploadFeedback = new
> FeedbackPanel("uploadFeedback");
>
>         // Add uploadFeedback to the page itself
>         add(uploadFeedback);
>
> /*        fileListView = new FileListView("fileList", new
> LoadableDetachableModel()
>         {
>             protected Object load()
>             {
>                 return Arrays.asList(getUploadFolder().listFiles());
>             }
>         });
>         add(fileListView);*/
>         
>         // Add upload form with ajax progress bar
>         final FileUploadForm ajaxSimpleUploadForm = new
> FileUploadForm("ajax-simpleUpload");
>         
>         ajaxSimpleUploadForm.add(new UploadProgressBar("progress",
> ajaxSimpleUploadForm));
>         add(ajaxSimpleUploadForm);
>     }
>     
>     private Folder getUploadFolder()
>     {
>         return ((UploadApplication)Application.get()).getUploadFolder();
>     }    
> }
>
>
> Kindly please advice
> Thanks,
> Franklin.
>
>
>
>
> Franklin Antony wrote:
>   
>> Dear Friends,
>>    I am having a problem with putting MultiFileUploadField inside a
>> ListView. I am following the example, but somehow the uploads collection
>> is not getting populated with the files. However when I directly add the
>> MultiFileUploadField  on a form everything seems to work. Could someone
>> please shed some light on this.
>>
>> Here is some code snippet
>>
>>             List ls = Arrays.asList(new String[]{"Passport "});
>>             ListView pl = new ListView("plist",ls)
>>             { 
>>                       	
>> 				protected void populateItem(ListItem arg0) {
>> 										
>> 					
>> 					MultiFileUploadField ff=new MultiFileUploadField("file_input",new
>> PropertyModel(this,"uploads"),3);
>> 					
>> 					fileUploadList.add(ff);
>> 					fileUpload.add(ff);
>> 	            	arg0.add(ff);
>> 	
>> 					
>> 	
>> 					
>> 				}
>>             	
>>             	
>>             };
>>
>>
>> And the listview is on a form and the collections(uploads) is on the form
>> to just as in the example. I am sure its something with the component
>> hierarchy. But not sure how to call the uploads correctly. I think there
>> is something wrong with the expression.
>>
>>
>> Thanks,
>> Franklin
>>
>>     
>
>   


Re: Multi-file upload and ListView together

Posted by Franklin Antony <fr...@gmail.com>.
Dear All,
   I am badly in need to implement this. Therefore I am placing the code
here.... I really didnt want to do this. I have a feeling I am placing the
collections in the wrong place.


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import
org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.form.upload.MultiFileUploadField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.link.PopupSettings;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.file.Files;
import org.apache.wicket.util.file.Folder;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.tester.DummyHomePage;

import com.datelservices.domain.Attachment;
import com.datelservices.util.upload.dao.PassportDocDAO;

public class FileUploadPage extends WebPage{
	
	 
     public  List fileUpload = new ArrayList();
       
     
	 public  Collection pageUploads = new ArrayList();
	 
     public Collection getPageUploads()
     {
     	return pageUploads;
     }
	 
	 
	 PropertyModel  pmPage ;
	

   

    private class FileUploadForm extends Form
    {


        private  Collection formUploads = new ArrayList();
        PropertyModel  pmForm =new PropertyModel(this,"formUploads");        

        
        
        public Collection getFormUploads()
        {
        	return formUploads;
        }
        
        
        public FileUploadForm(String name)
        {
            super(name);
            
            setMultiPart(true);
            

            
            
            List ls = Arrays.asList(new String[]{"Passport ","Scan ","Many
More "});
            //FileListView pl = new FileListView("plist",ls);
            
            
            ListView pl = new ListView("plist",ls) 
            { 
            	
				protected void populateItem(ListItem arg0) {
					
					MultiFileUploadField ff=new MultiFileUploadField("file_input",new
PropertyModel(FileUploadPage.this,"pageUploads"),3);
	            	arg0.add(ff);
					arg0.add(new Label("lbb",arg0.getModelObjectAsString()));
					
				}
            	
            };
            
            pl.setReuseItems(true);
            add(pl);
            
            
            


            // Set maximum size 
            double maxLimit =
((UploadApplication)Application.get()).getConfigProperty().getMaxFileUploadSize();
            System.out.println("File upload limit is " + maxLimit);
            setMaxSize(Bytes.kilobytes(maxLimit));
        }

        /**
         * @see org.apache.wicket.markup.html.form.Form#onSubmit()
         */
        protected void onSubmit() {
        
System.out.println("$$$$$$$$$$$uploads1$$$$$$$$$$$$"+getFormUploads().iterator().hasNext());
        
//System.out.println("$$$$$$$$$$$uploads2$$$$$$$$$$$$"+((ArrayList)pmPage.getObject()).size());
        
//System.out.println("$$$$$$$$$$$uploads2.1$$$$$$$$$$$$"+((ArrayList)FileUploadPage.this.pmPage.getObject()).size());
        
//System.out.println("$$$$$$$$$$$uploads3$$$$$$$$$$$$"+((ArrayList)pmForm.getObject()).size());
        
System.out.println("$$$$$$$$$$$uploads5$$$$$$$$$$$$"+fileUpload.size());
        
System.out.println("$$$$$$$$$$$uploads99$$$$$$$$$$$$"+FileUploadForm.this.formUploads.size());
        
System.out.println("$$$$$$$$$$$uploads99$$$$$$$$$$$$"+FileUploadPage.this.pageUploads.size());        	
        	
        	
        	
        	System.out.println("getting iterator");
        	 //Iterator it =
((ArrayList)FileUploadPage.this.pm.getObject()).iterator();
        	 Iterator it = fileUpload.iterator();
        	 
        	 System.out.println("got iterator");    

         }


        	
        

    }    
    
    private int uploadFile(final FileUpload upload , String comments, int
docTypeCD){
 
    	if( !upload.getClientFileName().toLowerCase().endsWith(".gif") ){
    		FileUploadPage.this.info("Can not upload file : " +
upload.getClientFileName() +". Only GIF file can be uploaded.");
    		return -1;
    	} 

    	// Create a new file
    	PassportDocDAO passportDAO =
((UploadApplication)Application.get()).getPassportDocDAO();
    	passportDAO.setComments(comments);
    	passportDAO.setDocDate(new Date());
    	passportDAO.setDocTypeCD(docTypeCD);
    	try {
			passportDAO.savePassportDataStream(upload.getInputStream(), (int)
upload.getSize());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new IllegalStateException("Unable to write file");
		}
		passportDAO.setUserPassportId(1);
		passportDAO.setVersion(0);
		int docId =
((UploadApplication)Application.get()).getIFilePersistService().persistFile(passportDAO);
		FileUploadPage.this.info("saved file: " + upload.getClientFileName());

		return docId;
    }


    /** Log. */
    private static final Log log = LogFactory.getLog(FileUploadPage.class);


    /**
     * Constructor.
     * 
     * @param parameters
     *            Page parameters
     */
    public FileUploadPage(final PageParameters parameters)
    {
        Folder uploadFolder = getUploadFolder();
        
        // Create feedback panels
        final FeedbackPanel uploadFeedback = new
FeedbackPanel("uploadFeedback");

        // Add uploadFeedback to the page itself
        add(uploadFeedback);

/*        fileListView = new FileListView("fileList", new
LoadableDetachableModel()
        {
            protected Object load()
            {
                return Arrays.asList(getUploadFolder().listFiles());
            }
        });
        add(fileListView);*/
        
        // Add upload form with ajax progress bar
        final FileUploadForm ajaxSimpleUploadForm = new
FileUploadForm("ajax-simpleUpload");
        
        ajaxSimpleUploadForm.add(new UploadProgressBar("progress",
ajaxSimpleUploadForm));
        add(ajaxSimpleUploadForm);
    }
    
    private Folder getUploadFolder()
    {
        return ((UploadApplication)Application.get()).getUploadFolder();
    }    
}


Kindly please advice
Thanks,
Franklin.




Franklin Antony wrote:
> 
> Dear Friends,
>    I am having a problem with putting MultiFileUploadField inside a
> ListView. I am following the example, but somehow the uploads collection
> is not getting populated with the files. However when I directly add the
> MultiFileUploadField  on a form everything seems to work. Could someone
> please shed some light on this.
> 
> Here is some code snippet
> 
>             List ls = Arrays.asList(new String[]{"Passport "});
>             ListView pl = new ListView("plist",ls)
>             { 
>                       	
> 				protected void populateItem(ListItem arg0) {
> 										
> 					
> 					MultiFileUploadField ff=new MultiFileUploadField("file_input",new
> PropertyModel(this,"uploads"),3);
> 					
> 					fileUploadList.add(ff);
> 					fileUpload.add(ff);
> 	            	arg0.add(ff);
> 	
> 					
> 	
> 					
> 				}
>             	
>             	
>             };
> 
> 
> And the listview is on a form and the collections(uploads) is on the form
> to just as in the example. I am sure its something with the component
> hierarchy. But not sure how to call the uploads correctly. I think there
> is something wrong with the expression.
> 
> 
> Thanks,
> Franklin
> 

-- 
View this message in context: http://www.nabble.com/Multi-file-upload-and-ListView-together-tf4791788.html#a13722948
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org