java - BrowserWindowOpener and dynamic url/resource VAADIN -
is there way pass dynamic url new browserwindowopener(dynamicurl) ?
i want implementation like: select file in table , click on button open browser view of file; can open random file parameter browserwindowopener must dynamic.
i know there other way open like: page.getcurrent().open... need disable url bar change browserwindowopener do.
the solution have found might considered hack. if seasoned vaadin developer happens come across post, please let me know if there better way.
in meantime, solution following:
- initialize browserwindowopener externalresource (you can put url in constructor of externalresource) has geturl method overridden return value depends on selection within table
- every time value in table changed, mark browserwindowopener dirty, in order trigger change in shared state
below example:
public class downloadfiletable extends customcomponent { private string currentselectedfile = null; public downloadfiletable() { verticallayout layout = new verticallayout(); setcompositionroot(layout); indexedcontainer container = new indexedcontainer(); container.addcontainerproperty("name", string.class, "default"); container.additem("image1.jpg").getitemproperty("name").setvalue("image1.jpg"); container.additem("text.csv").getitemproperty("name").setvalue("text.csv"); container.additem("document.doc").getitemproperty("name").setvalue("document.doc"); button downloadbutton = new button("download selected file"); final browserwindowopener browserwindowopener = new browserwindowopener(new externalresource("http://google.com") { @override public string geturl() { return currentselectedfile; } }); browserwindowopener.setfeatures("location=0"); browserwindowopener.extend(downloadbutton); table table = new table("files", container); table.setselectable(true); table.setimmediate(true); table.addvaluechangelistener(new property.valuechangelistener() { @override public void valuechange(property.valuechangeevent event) { currentselectedfile = (string) event.getproperty().getvalue(); browserwindowopener.markasdirty(); } }); layout.addcomponent(table); layout.addcomponent(downloadbutton); }
}
the browserwindowopener.setfeatures("location=0"); tells popup window restrict user modifying address bar.
Comments
Post a Comment