<p:datatable> con <p:autocomplete>

<p:datatable> con <p:autocomplete>

Datatable con autocomplete y botón agregar fila

Columnas editables

Habilitar la propiedad editable="true" editMode="cell" del datatable

Controlamos el evento cellEdit , en las columnas usamos

<p:cellEditor>  
   <p:ajax event="cellEdit" listener="#{actividadesimpuestosSearchController.onCellEdit}" update=":form:growl" />

Agregar el autocomplete

 <p:column>
    <f:facet name="header">
          <h:outputText value="#{msg.idnivel6}"/>
    </f:facet>

                                    <p:cellEditor>  
                                        <f:facet name="output">
                                            <h:outputText value="#{item.idnivel6.idnivel6}"/>
                                        </f:facet>  
                                        <f:facet name="input">
                      <p:autoComplete  scrollHeight="250"   dropdown="true"  size="45"  
                        value="#{item.idnivel6}"  
                       completeMethod="#{actividadesimpuestosSearchController.completeNivel6}"  
                                 var="p"  
                                itemLabel="#{p.idnivel6}" 
                                itemValue="#{p}" converter="nivel6Converter" forceSelection="true"> 

                        <p:ajax event="itemSelect" 
         listener="#{actividadesimpuestosSearchController.handleSelectNivel6(event,item.idnivel6)}" 
           update=":form,:form:growl" />  
                            <f:facet name="itemtip">
                              <h:panelGrid columns="2" cellpadding="5">
                                         <p:outputLabel value="#{msg.nombre}"/>

                                          <p:outputLabel value="#{p.nombre}" />
                                     <p:outputLabel value="#{msg.valor}"/>
                                        <p:outputLabel value="#{p.valor}" />
                                        <p:outputLabel value="#{msg.desde}"/>
                                        <p:outputLabel value="#{p.minimo} #{msg.a} #{p.maximo}" />
                                        <p:outputLabel value="#{msg.nivel5}"/>

                                       <p:outputLabel value="#{p.idnivel5.nombre}" />
                             </h:panelGrid>
                           </f:facet>
                      </p:autoComplete> 
                   </f:facet>  
           </p:cellEditor>  

  </p:column>

Una columna editable para el valor

 <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.valor}"/>
                                    </f:facet>
                                    <p:cellEditor>  
                                        <f:facet name="output">
                                            <h:outputText value="#{item.valor}" />
                                        </f:facet>  
                                        <f:facet name="input">
                                            <p:inputText  value="#{item.valor}"  style="width:96%" title="#{item.idnivel6.minimo} #{app['info.a']} #{item.idnivel6.maximo}"/>
                                       </f:facet>  
                                    </p:cellEditor>  

                                </p:column>

En el SearchController.java implementar el metodo onCellEdit

 @Override
    public void onCellEdit(CellEditEvent event) {
        try {

            selected = actividadesimpuestosList.get(event.getRowIndex());
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
            if (addnew) {
                actividadesimpuestosList.get(event.getRowIndex()).setValor(selected.getIdnivel6().getValor());
            }
            if (!validarValores(selected)) {
                actividadesimpuestosList.get(event.getRowIndex()).setValor(selected.getIdnivel6().getValor());
            }
            addnew = false;

        } catch (Exception e) {
            JSFUtil.addErrorMessage("onCellEdit()" + e.getLocalizedMessage());
        }

    }

Usaremos un botón para agregar las filas nuevas al datatable

Agregar un botón y el método addFila()

 <f:facet name="header">

           <p:commandButton id="addfila" style="float:right" icon="ui-icon-circle-plus"
                                                     update=":form:datatableActividadesimpuestos,:form:growl" 
                                                     title="#{app['boton.addfila']}"                                                   
                                                   action="#{actividadesimpuestosSearchController.addFila()}"
                                                     />

     <p:commandButton icon="ui-icon-disk"                                                  actionListener="#{actividadesimpuestosSearchController.save()}" 
                           update=":form:growl,:form:datatableActividadesimpuestos" />

   <p:commandButton id="button_print"                                                title="#{app['boton.print']}"                                                                                 action="#{actividadesimpuestosSearchController.imprimir()}"
                                     icon="ui-icon-print" ajax="false" />

                                </f:facet>

En el SearchController

 public String addFila() {
        try {
            addnew = true;
            Actividadesimpuestos actividadesimpuestos1 = new Actividadesimpuestos();
            actividadesimpuestos1.setActivo("si");
            actividadesimpuestos1.setIdnivel6(new Nivel6());
            actividadesimpuestos1.setFecha(JSFUtil.getFechaActual());
            actividadesimpuestos1.setUsername(loginBean.getUsuarios());
            actividadesimpuestos1.setValor(0.0);
            actividadesimpuestos1.setIdactividadesimpuestos(0);
            actividadesimpuestos1.setIdactividades(actividadesimpuestos.getIdactividades());

            actividadesimpuestosList.add(actividadesimpuestos1);
        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }

        return "";
    }

CÓDIGO COMPLETO actividadesimpuestos.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:b="http://bootsfaces.net/ui"
      xmlns:javscaz="http://xmlns.jcp.org/jsf/composite/javscaz">

    <body>

        <ui:composition template="./../../template.xhtml">

           <ui:define name="content">
                <f:view>
                    <h:form id="form" prependId="false" rendered="#{menuBeans.actividades.consultar}">
                        <p:growl  id="growl" />

                        <b:panel id="panel" look="primary" title="#{form['actividades.records']}">

                            <h:panelGrid columns="2" cellpadding="5">

                                <p:outputLabel value="#{msg.tipo}" for="tipo" />
                                <p:selectOneMenu id="tipo"
                                                 value="#{actividadesController.actividades.tipo}"

                                                 requiredMessage="#{msg.tipo} #{app['info.notnull']}">
        <f:selectItem itemLabel="#{app['selectonemenu.select']}" itemValue="#{null}"/>
                                  <f:selectItem itemLabel="#{app['tipo.vehiculos']}" itemValue="vehiculos" />
                                    <f:selectItem itemLabel="#{app['tipo.remolques']}" itemValue="remolques" />
                                    <f:selectItem itemLabel="#{app['tipo.comercios']}" itemValue="comercios" />
                                    <f:selectItem itemLabel="#{app['tipo.bicicletas']}" itemValue="bicicletas" />
                                    <f:selectItem itemLabel="#{app['tipo.bovedas']}" itemValue="bovedas" />
                                    <f:selectItem itemLabel="#{app['tipo.contribuyentes']}" itemValue="contribuyentes" />
                                    <f:selectItem itemLabel="#{app['tipo.tesoreroauxiliar']}" itemValue="tesoreroauxiliar" />
                                    <p:ajax process="tipo" event="change"
                                            update=":form:actividad,:form:growl,:form:datatableActividadesimpuestos"
                                            listener="#{actividadesSearchController.changeItemsTipo(actividadesController.actividades.tipo)}"/>
                                </p:selectOneMenu>

                                <p:outputLabel value="#{msg.actividad}" for="actividad" />
                                <p:selectOneMenu id="actividad" 
                                                 converter="actividadesConverter"
                                                 value="#{actividadesimpuestosSearchController.actividadesimpuestos.idactividades}"
                                                 >
                                    <!-- TODO: update below reference to list of available items-->
                                    <f:selectItem itemLabel="#{app['selectonemenu.select']}" itemValue="#{null}"/>
                                    <f:selectItems value="#{actividadesSearchController.actividadesPorTipoList}"
                                                   var="actividadesItem"
                                                   itemValue="#{actividadesItem}"
                                                   itemLabel="#{actividadesItem.actividad}"/>

                                    <p:ajax process="actividad" event="change"
                                            update=":form:datatableActividadesimpuestos,:form:growl"

                                            listener="#{actividadesimpuestosSearchController.changeSelectOneMenuActividad()}"/>
                                </p:selectOneMenu>




                            </h:panelGrid>

                    <p:dataTable id="datatableActividadesimpuestos"

                                         value="#{actividadesimpuestosSearchController.actividadesimpuestosList}" 

                                         var="item"
                                         paginator="false"
                                         rowKey="#{item.idactividadesimpuestos}"
                                         selectionMode="single"
                                         selection="#{actividadesimpuestosSearchController.selected}"
                                         filteredValue="#{actividadesimpuestosSearchController.filtered}" 
                                         editable="true" editMode="cell"
                                               scrollable="true" scrollHeight="300"
                                         >

                <p:ajax event="cellEdit" listener="#{actividadesimpuestosSearchController.onCellEdit}" 
                update=":form:growl" />

                        <f:facet name="header">

                           <p:commandButton id="addfila" style="float:right" icon="ui-icon-circle-plus"                                                   update=":form:datatableActividadesimpuestos,:form:growl" 
                             title="#{app['boton.addfila']}"                                                                                                        action="#{actividadesimpuestosSearchController.addFila()}"                                                     />

                           <p:commandButton icon="ui-icon-disk"
                               actionListener="#{actividadesimpuestosSearchController.save()}" 
                               update=":form:growl,:form:datatableActividadesimpuestos" />

                             <p:commandButton id="button_print"
                               title="#{app['boton.print']}"                                 
                               action="#{actividadesimpuestosSearchController.imprimir()}"
                               icon="ui-icon-print" ajax="false" />
                       </f:facet>


                <p:column>
                       <f:facet name="header">
                          <h:outputText value="#{msg.idnivel6}"/>
                       </f:facet>
                       <p:cellEditor>  
                        <f:facet name="output">
                          <h:outputText value="#{item.idnivel6.idnivel6}"/>
                       </f:facet>  
                       <f:facet name="input">
                       <p:autoComplete  scrollHeight="250"  
                          dropdown="true"  size="45"    value="#{item.idnivel6}"  
                          completeMethod="#{actividadesimpuestosSearchController.completeNivel6}"  
                          var="p"  
                          itemLabel="#{p.idnivel6}" 
                          itemValue="#{p}" converter="nivel6Converter" forceSelection="true"> 

             <p:ajax event="itemSelect" 
             listener="#{actividadesimpuestosSearchController.handleSelectNivel6(event,item.idnivel6)}" 
             update=":form,:form:growl" />  
                       <f:facet name="itemtip">
                           <h:panelGrid columns="2" cellpadding="5">
                              <p:outputLabel value="#{msg.nombre}"/>                                                      <p:outputLabel value="#{p.nombre}" />
                              <p:outputLabel value="#{msg.valor}"/>
                              <p:outputLabel value="#{p.valor}" />
                              <p:outputLabel value="#{msg.desde}"/>
                              <p:outputLabel value="#{p.minimo} #{msg.a} #{p.maximo}" />
                              <p:outputLabel value="#{msg.nivel5}"/>
                              <p:outputLabel value="#{p.idnivel5.nombre}" />
                            </h:panelGrid>
                         </f:facet>
                 </p:autoComplete> 
           </f:facet>  
      </p:cellEditor>  

               </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.nombre}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.idnivel6.nombre}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.valor}"/>
                                    </f:facet>
                                    <p:cellEditor>  
                                        <f:facet name="output">
                                            <h:outputText value="#{item.valor}" />
                                        </f:facet>  
                                        <f:facet name="input">
                          <p:inputText  value="#{item.valor}"  style="width:96%" 
                          title="#{item.idnivel6.minimo} #{app['info.a']} #{item.idnivel6.maximo}"/>

                                        </f:facet>  
                                    </p:cellEditor>  

                                </p:column>

                                   <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{msg.rango}"/>
                                    </f:facet>
                                <h:outputText value="( #{item.idnivel6.minimo} a #{item.idnivel6.maximo} )"/>
                                </p:column>
                                <p:column>

                              <p:commandButton icon="ui-icon-trash"
                                 actionListener="#{actividadesimpuestosSearchController.delete(item)}" 
                                    update=":form:growl,:form:datatableActividadesimpuestos" >

                                        <p:confirm header="#{app['dialog.delete']}" 
                                        message="#{app['info.doyouwantdelete']}" icon="ui-icon-alert" />
                                    </p:commandButton>
                                </p:column>


                            </p:dataTable>


                            <javscaz:procesar/>
                        </b:panel>

                     <p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
                            <p:commandButton value="#{app['boton.yes']}" type="button"
                             styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                           <p:commandButton value="#{app['boton.no']}" type="button" 
                           styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                        </p:confirmDialog>

                    </h:form>
                    <h:form rendered="#{!menuBeans.actividades.consultar}">


                        <b:panel look="danger" title="#{app['title.accesodenegado']}">


                           <h:panelGrid columns="2" cellpadding="5">
                               <p:commandButton class="btn btn-success" action="#{loginBean.irLogin}"
                                                value="#{app['boton.return']}" ajax="false"/>
                            </h:panelGrid>
                        </b:panel>


                    </h:form>

                </f:view>
            </ui:define>

        </ui:composition>

    </body>
</html>

CODIGO COMPLETO ActividadesimpuestosSearchController.java

Agregar atributo private Boolean addnew = false; agregar el método addFila()

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javscaz.brigem.search;

import com.javscaz.brigem.Actividadesimpuestos;
import com.javscaz.brigem.Nivel6;
import com.javscaz.brigem.ejb.ActividadesimpuestosFacade;
import com.javscaz.brigem.ejb.Nivel6Facade;
import com.javscaz.brigem.generales.GestorImpresion;
import com.javscaz.brigem.generales.JSFUtil;
import com.javscaz.brigem.generales.LoginBean;
import com.javscaz.brigem.generales.ResourcesFiles;
import com.javscaz.brigem.interfaces.ISearchController;
import com.javscaz.brigem.reportes.ActividadesimpuestosReporte;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.event.CellEditEvent;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author avbravo
 */
@Named
@ViewScoped
public class ActividadesimpuestosSearchController implements Serializable, ISearchController {

    @Inject
    ActividadesimpuestosFacade actividadesimpuestosFacade;
    @Inject
    ResourcesFiles rf;

    Actividadesimpuestos actividadesimpuestos = new Actividadesimpuestos();
    Actividadesimpuestos selected = new Actividadesimpuestos();
    private List<Actividadesimpuestos> filtered;
    List<Actividadesimpuestos> actividadesimpuestosList = new ArrayList<>();

    private List<Actividadesimpuestos> items, itemsEntity, itemsCollection;

    @Inject
    GestorImpresion gestorImpresion;
    @Inject
    LoginBean loginBean;

    Boolean encontrado = false;

    Nivel6 nivel6 = new Nivel6();
    @Inject
    Nivel6Facade nivel6Facade;
    private Boolean addnew = false;
    private  String tipo;

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }


//se usa para saber si el usuario dio clic en el boton add para agregar registros a la fila

    public Boolean getAddnew() {
        return addnew;
    }

    public void setAddnew(Boolean addnew) {
        this.addnew = addnew;
    }

    public Boolean getEncontrado() {
        return encontrado;
    }

    public void setEncontrado(Boolean encontrado) {
        this.encontrado = encontrado;
    }

    //
    public Actividadesimpuestos getActividadesimpuestos() {
        return actividadesimpuestos;
    }

    public void setActividadesimpuestos(Actividadesimpuestos actividadesimpuestos) {
        this.actividadesimpuestos = actividadesimpuestos;
    }

    public Actividadesimpuestos getSelected() {
        return selected;
    }

    public void setSelected(Actividadesimpuestos selected) {
        this.selected = selected;
    }

    public List<Actividadesimpuestos> getFiltered() {
        return filtered;
    }

    public void setFiltered(List<Actividadesimpuestos> filtered) {
        this.filtered = filtered;
    }

    public List<Actividadesimpuestos> getActividadesimpuestosList() {
        return actividadesimpuestosList;
    }

    public void setActividadesimpuestosList(List<Actividadesimpuestos> actividadesimpuestosList) {
        this.actividadesimpuestosList = actividadesimpuestosList;
    }

    public ActividadesimpuestosSearchController() {
        actividadesimpuestosList = new ArrayList<>();
    }

    @PostConstruct
    public void init() {
        addnew = false;

    }

    @Override
    public String clear() {
        actividadesimpuestosList = new ArrayList<>();
        return null;
    }

    @Override
    public void iniciar() {
        actividadesimpuestosList = actividadesimpuestosFacade.getActividadesimpuestosList();
    }

    @Override
    public void iniciar(String value) {
//        actividadesimpuestosList  = actividadesimpuestosFacade.findByActivo(value);
    }

    @Override
    public String showAll() {
        try {
            actividadesimpuestosList = actividadesimpuestosFacade.findAll();

        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }
        return "";
    }

    @Override
    public List<Actividadesimpuestos> getItems() {
        try {
            if (items == null) {
                items = actividadesimpuestosFacade.findAll();

            }
        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }
        return items;
    }

    @Override
    public String changeItems() {
        try {
            items = actividadesimpuestosFacade.findAll();

        } catch (Exception e) {
            JSFUtil.addErrorMessage("changeItems() " + e.getLocalizedMessage());
        }
        return "";
    }

    @Override
    public List<Actividadesimpuestos> getItemsCollection() {
        try {
//            itemsCollection = new ArrayList(actividadesimpuestos. getNivel2Collection());

        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }
        return itemsCollection;
    }

    @Override
    public String changeItemsInverso() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String imprimirTodos() {
        try {

            String ruta = "/resources/reportes/actividadesimpuestos/actividadesimpuestostodos.jasper";
            HashMap parameters = new HashMap();
            parameters.put("P_MUNICIPIO", loginBean.getUsuarios().getIdmunicipio().getMunicipio());
            List<Actividadesimpuestos> listai = actividadesimpuestosFacade.findAll();
            if (listai.isEmpty()) {
                JSFUtil.addWarningMessage(rf.getMensajeArb("info.nohayregistros"));

                return "";
            }
            List<ActividadesimpuestosReporte> list = new ArrayList<>();
            listai.stream().map((a) -> {
                ActividadesimpuestosReporte ar = new ActividadesimpuestosReporte();
                ar.setActividad(a.getIdactividades().getActividad());
                ar.setIdnivel6(a.getIdnivel6().getIdnivel6());
                ar.setNombrenivel6(a.getIdnivel6().getNombre());
                ar.setValor(a.getValor());
                ar.setTipo(a.getIdactividades().getTipo());
                ar.setIdactividades(a.getIdactividades().getIdactividades());
                return ar;
            }).forEach((ar) -> {
                list.add(ar);
            });

           list.sort((p1, p2) -> p1.getTipo().compareTo(p2.getTipo()));
            gestorImpresion.imprimir(list, ruta, parameters);

        } catch (Exception ex) {
            JSFUtil.addErrorMessage("imprimir() " + ex.getLocalizedMessage());
        }
        return null;
    }
    public String imprimirTodosFiltrados(List<Actividadesimpuestos> listai) {
        try {

            String ruta = "/resources/reportes/actividadesimpuestos/actividadesimpuestostodos.jasper";
            HashMap parameters = new HashMap();
            parameters.put("P_MUNICIPIO", loginBean.getUsuarios().getIdmunicipio().getMunicipio());

            if (listai.isEmpty()) {
                JSFUtil.addWarningMessage(rf.getMensajeArb("info.nohayregistros"));

                return "";
            }
            List<ActividadesimpuestosReporte> list = new ArrayList<>();
            listai.stream().map((a) -> {
                ActividadesimpuestosReporte ar = new ActividadesimpuestosReporte();
                ar.setActividad(a.getIdactividades().getActividad());
                ar.setIdnivel6(a.getIdnivel6().getIdnivel6());
                ar.setNombrenivel6(a.getIdnivel6().getNombre());
                ar.setValor(a.getValor());
                ar.setTipo(a.getIdactividades().getTipo());
                ar.setIdactividades(a.getIdactividades().getIdactividades());
                return ar;
            }).forEach((ar) -> {
                list.add(ar);
            });

           list.sort((p1, p2) -> p1.getIdactividades().compareTo(p2.getIdactividades()));
            gestorImpresion.imprimir(list, ruta, parameters);

        } catch (Exception ex) {
            JSFUtil.addErrorMessage("imprimir() " + ex.getLocalizedMessage());
        }
        return null;
    }




    public String imprimir() {
        try {

            if (actividadesimpuestosList.isEmpty()) {
                JSFUtil.addWarningMessage(rf.getMensajeArb("info.nohayregistros"));

                return "";
            }
            List<ActividadesimpuestosReporte> list = new ArrayList<>();
            actividadesimpuestosList.stream().map((a) -> {
                ActividadesimpuestosReporte ar = new ActividadesimpuestosReporte();
                ar.setActividad(a.getIdactividades().getActividad());
                ar.setIdnivel6(a.getIdnivel6().getIdnivel6());
                ar.setNombrenivel6(a.getIdnivel6().getNombre());
                ar.setValor(a.getValor());
                ar.setTipo(a.getIdactividades().getTipo());

                ar.setIdactividades(a.getIdactividades().getIdactividades());
                return ar;
            }).forEach((ar) -> {
                list.add(ar);
            });
            String ruta = "/resources/reportes/actividadesimpuestos/actividadesimpuestos.jasper";
            HashMap parameters = new HashMap();
            parameters.put("P_MUNICIPIO", "MUNICIPIO DE " + loginBean.getUsuarios().getIdmunicipio().getMunicipio());
            parameters.put("P_TIPO", actividadesimpuestos.getIdactividades().getTipo().toUpperCase());
            gestorImpresion.imprimir(list, ruta, parameters);

        } catch (Exception ex) {
            JSFUtil.addErrorMessage("imprimir() " + ex.getLocalizedMessage());
        }
        return null;
    }

    @Override
    public List getItemsEntity() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    // @Override
    @Override
    public String listar() {
        showAll();
        imprimirTodos();
        return null;
    }

    /*
    lista los registros por el tipo seleccionado
    */
    public String listarTipo() {
        try {

            actividadesimpuestosList = actividadesimpuestosFacade.findAll();

            if(actividadesimpuestosList.isEmpty()){
                System.out.println("no hay registros");
                 JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("warning.nohayregistros"));
                return " ";
            }

            List<Actividadesimpuestos> list = new ArrayList<>();


            actividadesimpuestosList.stream().filter((ai) -> (ai.getIdactividades().getTipo().equals(tipo))).forEach((ai) -> {
                list.add(ai);
            });

            if(list.isEmpty()){
                 JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("warning.nohayregistros"));

                return " ";
            }
              imprimirTodosFiltrados(list);
        } catch (Exception e) {
            JSFUtil.addErrorMessage("listarTipo() " +e.getLocalizedMessage());

        }


        return null;
    }
    @Override
    public String delete() {
        try {
            actividadesimpuestosFacade.remove(selected);
            actividadesimpuestosList.remove(selected);
        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }
        return null;
    }

    @Override
    public void onCellEdit(CellEditEvent event) {
        try {

            selected = actividadesimpuestosList.get(event.getRowIndex());
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
            if (addnew) {
                actividadesimpuestosList.get(event.getRowIndex()).setValor(selected.getIdnivel6().getValor());
            }
            if (!validarValores(selected)) {
                actividadesimpuestosList.get(event.getRowIndex()).setValor(selected.getIdnivel6().getValor());
            }
            addnew = false;

        } catch (Exception e) {
            JSFUtil.addErrorMessage("onCellEdit()" + e.getLocalizedMessage());
        }

    }

    /**
     * guarda los registros
     */
    public void save() {
        try {
            if (actividadesimpuestos.getIdactividades().getTipo() == null) {
                JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("warning.seleccionetipo"));

                return;
            }
            if (actividadesimpuestos.getIdactividades() == null) {
                JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("warning.actividades"));

                return;
            }

            // editar o insertar
            Integer contadornull = 0;
            contadornull = actividadesimpuestosList.stream().filter((a) -> (a.getIdnivel6().getIdnivel6() == null)).map((_item) -> 1).reduce(contadornull, Integer::sum);

            if (actividadesimpuestosList.isEmpty() || contadornull > 0) {
                JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("warning.nohayregistros"));

                return;
            }

            actividadesimpuestosList.stream().forEach((a) -> {
                if (!validarValores(a)) {

                }
                if (a.getIdnivel6().getIdnivel6() == null) {

                } else if (actividadesimpuestosFacade.findByIdactividadesNivelActivo(a.getIdactividades(), a.getIdnivel6(), "si").isEmpty()) {
                    actividadesimpuestosFacade.create(a);
                } else {
                    actividadesimpuestosFacade.edit(a);
                }

            });

            JSFUtil.addSuccessMessage(rf.getMensajeArb("info.save"));

        } catch (Exception e) {
            JSFUtil.addErrorMessage("save()" + e.getLocalizedMessage());
        }

    }


    public Boolean validarValores(Actividadesimpuestos ai) {
        try {
            if (ai.getValor() < 0) {
                JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("info.valornegativo"));

                return false;
            }

            if (ai.getValor() > ai.getIdnivel6().getMaximo()) {
                JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("info.valormayormaximo") + " " + ai.getIdnivel6().getMaximo());
                return false;
            }
            if (ai.getValor() < ai.getIdnivel6().getMinimo()) {
                JSFUtil.warningDialog(rf.getMensajeArb("info.message"), rf.getMensajeArb("info.valormenorminimo") + " " + ai.getIdnivel6().getMinimo());

                return false;
            }

        } catch (Exception e) {
            JSFUtil.addErrorMessage("validarValores()" + e.getLocalizedMessage());
        }
        return true;
    }

    @Override
    public void handleSelect(SelectEvent event) {
        try {
            actividadesimpuestosList.removeAll(actividadesimpuestosList);
            actividadesimpuestosList.add(selected);

        } catch (Exception ex) {
            JSFUtil.addErrorMessage("handleSelect() " + ex.getLocalizedMessage());

        }

    }

    @Override
    public String delete(Object t) {
        try {
            actividadesimpuestos = (Actividadesimpuestos) t;

            actividadesimpuestosList.remove(actividadesimpuestos);

            actividadesimpuestosFacade.remove(actividadesimpuestos);
        } catch (Exception ex) {
            JSFUtil.addErrorMessage("delete() " + ex.getLocalizedMessage());
        }

        return null;
    }

    public String changeSelectOneMenuActividad() {
        try {
            actividadesimpuestosList.removeAll(actividadesimpuestosList);
            if (actividadesimpuestos.getIdactividades() == null) {
                setEncontrado(false);
                return null;
            }

            buscarIdactividades();

            setEncontrado(true);
        } catch (Exception e) {
            JSFUtil.addErrorMessage("saveImpuestos()" + e.getLocalizedMessage());
        }
        return null;
    }

    public String buscarIdactividades() {
        try {

            actividadesimpuestosList = actividadesimpuestosFacade.findByIdactividades(actividadesimpuestos.getIdactividades());

        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }

        return "";
    }




    public String addFila() {
        try {
            addnew = true;
            Actividadesimpuestos actividadesimpuestos1 = new Actividadesimpuestos();
            actividadesimpuestos1.setActivo("si");
            actividadesimpuestos1.setIdnivel6(new Nivel6());
            actividadesimpuestos1.setFecha(JSFUtil.getFechaActual());
            actividadesimpuestos1.setUsername(loginBean.getUsuarios());
            actividadesimpuestos1.setValor(0.0);
            actividadesimpuestos1.setIdactividadesimpuestos(0);
            actividadesimpuestos1.setIdactividades(actividadesimpuestos.getIdactividades());

            actividadesimpuestosList.add(actividadesimpuestos1);

        } catch (Exception e) {
            JSFUtil.addErrorMessage(e.getLocalizedMessage());
        }

        return "";
    }

    public void handleSelectNivel6(SelectEvent event, Nivel6 nivel6) {
        try {
            this.nivel6 = nivel6;
        } catch (Exception ex) {
            JSFUtil.addErrorMessage("handleSelectNivel6() " + ex.getLocalizedMessage());

        }

    }

    public List<Nivel6> completeNivel6(String query) {
        List<Nivel6> suggestions = new ArrayList<>();
        try {

            query = query.trim();

            List<Nivel6> list = nivel6Facade.findByIdNivel6Like(query.toLowerCase());
            if (!list.isEmpty()) {
                actividadesimpuestosList.stream().forEach((ai) -> {
                    list.remove(ai.getIdnivel6());
                });
            }
//               actividadesimpuestosList.stream().forEach((ai) -> {
//                   list.stream().filter((n) -> (ai.getIdnivel6().getIdnivel6().equals(n.getIdnivel6()))).forEach((n) -> {
//                       list.remove(n);
//                      
//                   });
//                }); 
//           }
            list.stream().forEach((p) -> {

                suggestions.add(p);
            });
        } catch (Exception e) {
            JSFUtil.addErrorMessage("complete() " + e.getLocalizedMessage());
        }
        return suggestions;
    }
}

Last updated