sub window contents mixed up

Hi,

I am opening two sub windows within an application and am doing so by calling a method within a loop.The window contents are streamed as a pdf from the database.When I do an item click to open one window it is opening with the right contents but in case of two or more all the windows contain the same repeated content( of only the last item).

Not sure why is this happening.Any help in the matter is much appreciated.

Thanks,

not sure it helps, but I had something similar, and it turned out to be a mistake of my own : click listener used to open the window refered to always the same data, and thus produced always the same window… It might be clearer if you could post a piece of code :slight_smile:

Thanks for your response.I think its referring to two different streams since when I have the method print it out I have two different pdfs.Here is the code to make things more clear…

private Window getDocument(Item itmDoc){
VerticalLayout loDoc= new VerticalLayout();

	subWindow = new Window("View document");
	subWindow.setHeight("600px");
	subWindow.setWidth("600px");

	Embedded em = new Embedded();


	System.out.println(itmDoc.getItemProperty("Name").getValue());Note:the name is printed correctly for the two records
	bas = (byte[]) itmDoc.getItemProperty("docContent").getValue();
	lgDocid = (Long) itmDoc.getItemProperty("docId").getValue();
	StreamSource streamSource = new StreamResource.StreamSource() {

		public InputStream getStream() {

			return (bas == null) ? null : new ByteArrayInputStream(bas);
		}
	};

	StreamResource resTable = new StreamResource(streamSource, "doc"+lgDocid +".pdf",
			getApplication());

	resTable.getStream().setCacheTime(0);
	resTable.setMIMEType("application/pdf");

	em.setType(Embedded.TYPE_BROWSER);
	em.setSource(resTable);
	em.setSizeFull();

	loDoc.addComponent(em);
	
	
	loDoc.setSizeFull();

	subWindow.setContent(loDoc);
	
	
	try {
		resTable.getStreamSource().getStream().close();
	} catch (IOException e) {
		e.printStackTrace();
	}

return subWindow;
}

And then I call this method within a loop:

btnViewdDoc.addListener(new ClickListener() {

		public void buttonClick(ClickEvent event) {
			arrWin = new Window[lstItemids.size()]

;
ctDoc= 0;
for (Object o : lstItemids) {

				//i am getting the item that is selected from the paged table list
				Item itmViewDoc= tblDocList.getItem(o);
				//calls method to render the doc in new window
				
				arrWin[ctDoc]

= getDocument(itmViewDoc);

				ctDoc++;
				
			}
			for(int i=0;i<ctDoc;i++){
				
				getApplication().getMainWindow().addWindow(arrWin[i]

);
}
lstItemids = new ArrayList();
}
});
btnViewDoc.setImmediate(true);

Hi,

I solved this issue by creating a separate streamsource class and calling it from my program as below:

public class streamDoc implements StreamSource {
private byte bas;
public streamDoc (byte basdoc){
bas = basdoc;
}
public InputStream getStream() {
// TODO Auto-generated method stub
return (bas == null) ? null
: new ByteArrayInputStream(bas);
}

}

and in my program I am calling this class

StreamSource streamdoc = new streamDoc(bas);

This solved the issue and my windows are displaying the correct data

Thanks,