Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a solution myself. Actually two. The first one uses the deprecated method <a href="https://vaadin.com/api/com/vaadin/server/Page.html#open%28com.vaadin.server.Resource,%20java.lang.String,%20boolean%29" rel="noreferrer">Page.open()</a></p> <pre><code>public class DownloadComponent extends CustomComponent implements ValueChangeListener { private ComboBox cb = new ComboBox(); public DownloadComponent() { cb.addValueChangeListener(this); cb.setNewItemsAllowed(true); cb.setImmediate(true); cb.setNullSelectionAllowed(false); setCompositionRoot(cb); } @Override public void valueChange(ValueChangeEvent event) { String val = (String) event.getProperty().getValue(); FileResource res = new FileResource(new File(val)); Page.getCurrent().open(res, null, false); } } </code></pre> <p>The javadoc <a href="https://vaadin.com/api/com/vaadin/ui/LegacyWindow.html#open%28com.vaadin.server.Resource,%20java.lang.String%29" rel="noreferrer">here</a> mentions some memory and security problems as reason for marking it deprecated</p> <hr> <p>In the second I try to go around this deprecated method by registering the resource in the DownloadComponent. I'd be glad if a vaadin expert comments this solution.</p> <pre><code>public class DownloadComponent extends CustomComponent implements ValueChangeListener { private ComboBox cb = new ComboBox(); private static final String MYKEY = "download"; public DownloadComponent() { cb.addValueChangeListener(this); cb.setNewItemsAllowed(true); cb.setImmediate(true); cb.setNullSelectionAllowed(false); setCompositionRoot(cb); } @Override public void valueChange(ValueChangeEvent event) { String val = (String) event.getProperty().getValue(); FileResource res = new FileResource(new File(val)); setResource(MYKEY, res); ResourceReference rr = ResourceReference.create(res, this, MYKEY); Page.getCurrent().open(rr.getURL(), null); } } </code></pre> <p>Note: I do not really allow the user to open all my files on the server and you should <strong>not</strong> do that either. It is just for demonstration.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload