How to set multiple upload button in a PopupButton?

I know there are only UploadField exist by which contains a upload button, and PopupButton only accept actions as option list.

I didn’t find any way to get the upload action.

How can I get the goal?

Hi!

In CUBA Platform there is a FileMultiUploadField, you can read more about it in documentation. But you are right, PopupButton only accept actions and you cannot open upload dialog from an action. In your case, you can try to use Vaadin PopupButton directly and set its content as MultiUploadField, for example:


import com.haulmont.cuba.gui.components.AbstractWindow;
import com.haulmont.cuba.gui.components.FileMultiUploadField;
import com.haulmont.cuba.gui.components.VBoxLayout;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.web.gui.components.WebComponentsHelper;

import javax.inject.Inject;
import java.util.Map;

public class DemoScreen extends AbstractWindow {

    @Inject
    private VBoxLayout popupBox;

    @Inject
    private ComponentsFactory componentsFactory;


    @Override
    public void init(Map<String, Object> params) {
        FileMultiUploadField multiUploadField = componentsFactory.createComponent(FileMultiUploadField.class);

        com.vaadin.ui.Layout layout = (com.vaadin.ui.Layout) WebComponentsHelper.unwrap(popupBox);

        org.vaadin.hene.popupbutton.PopupButton vaadinPopupButton =
                new org.vaadin.hene.popupbutton.PopupButton("Popup");
        layout.addComponent(vaadinPopupButton);

        vaadinPopupButton.setContent(WebComponentsHelper.unwrap(multiUploadField));
    }
}

Regards,

Gleb

Hi @gorelov, I tried this but I get NullPointerException on the VBoxLayout.

Then I tried popupBox = componentsFactory.createComponent(VBoxLayout.class);, but the popup button doesn’t show. Can you help? Thanks.

HI,

Could you share a comple code sample that repreduces the problem? For now it’s hard to say that’s broken.

Regards,
Gleb

Hi @gorelov,

Exactly as the code above, and in the xml file I only have a blank layout tag.

If you create a component programmatically, then you need to add it to the layout, for instance:

popupBox = componentsFactory.createComponent(VBoxLayout.class);
add(popupBox)

In the code sample above popupBox is added in the XML file. That’s why it can be injected and not null.

Can you also please include the xml file? I can’t add the popupBox, VBoxLayout is not permitted. Maybe I am using a different xsd file?

It was something like this:

<layout>
   <vbox id="popupBox"/>
</layout>

Gotcha so it’s vbox, thanks I’ll try it later.