autocomplete paste multiple elements

1

I have a component of primefaces p:autocomplete my question is if it is possible to paste several elements at the same time.

The component:

<p:autoComplete dropdown="true" id="instalacion" maxResults="100" 
    value="#{principalView.cochesSeleccionados}" 
    completeMethod="#{principalView.completeText}"
    forceSelection="true" multiple="true" 
    emptyMessage="Ningun dato coincide">

</p:autoComplete>

The bean:

@ManagedBean(name="principalView")
@ViewScoped
public class PrincipalView {
    List<String> results;
    List<String> cochesSeleccionados;

    @PostConstruct
    public void init() {
        results = new ArrayList<String>();
        results.add("BMW");
        results.add("AUDI");
        results.add("SEAT");
    }

    public List<String> completeText(String query) {
        return results;
    }
    // gettter and setter
    public List<String> getCochesSeleccionados() {
        return cochesSeleccionados;
    }

    public void setCochesSeleccionados(List<String> cochesSeleccionados) {
        this.cochesSeleccionados = cochesSeleccionados;
    }
}

My intention is to copy the elements from a site:

  

BMW SEAT   and when you paste it in the selected component.

    
asked by nachfren 24.10.2018 в 18:00
source

2 answers

0

In the end I got it by putting a button that opens a modal with a inputTextArea where we will paste the list of elements to paste.

<p:autoComplete dropdown="true" id="autocomplete_coches" maxResults="100" 
    value="#{principalView.cochesSeleccionados}" 
    completeMethod="#{principalView.completeText}"
    forceSelection="true" multiple="true" 
    emptyMessage="Ningun dato coincide">
</p:autoComplete>

<p:commandButton value=" " icon="fa fa-plus" type="button" onclick="PF('dlg4').show();" style="height: 31.19;width:30px;"/>
<p:dialog header="Coches" widgetVar="dlg4" minHeight="40">
    <p:inputTextarea  rows="10" cols="50" autoResize="false" value="#{principalView.textArea}"/>
    <p:commandButton value="Añadir" actionListener="#{principalView.multipleElemento()}" update="autocomplete_coches" oncomplete="PF('dlg4').hide();"></p:commandButton>
    <p:commandButton value="Cancelar" onclick="PF('dlg4').hide();"></p:commandButton>
</p:dialog>

The Java part:

    private String textArea;

    public void multipleElemento() {
        String[] lista =textArea.split("\n");//El usuario pega los diferentes elementos con un salto de linea.

        for(String coche : lista) {

            if(cochesSeleccionados == null) {
                cochesSeleccionados = new ArrayList<String>());
            }
            if(coche != null && coche.size()==1)
                cochesSeleccionados.add(coche);
        }
        textArea="";
    }

Obviously now if we paste any element in the inputTextarea it will put it as if it existed.

    
answered by 23.12.2018 / 13:05
source
0

Hi, I have not seen much of the subject. but I hope I can help you .. check the PrimeFaces page

link

There is a practical multiselect example that I think you are looking for

I hope it's your help

    
answered by 29.10.2018 в 16:01