How do I make a for in a list and change results using javaEE

Asked

Viewed 34 times

0

I have an object called (Bank) that has several accounts, with balance in these accounts I make payments of various expenses. what I want is to get all the expenses paid and to give low in the bank accounts in a single bank movement, but I am not getting, search method:

public List<Banco> bancoRepository() { 
    //carregar lista para lançamento
    return manager.createQuery("from Banco", Banco.class).getResultList();
}

and created this method to download

@Transactional
public Banco baixarPagamentos(Banco banco) {
    banco = bancos.porId(banco.getId());
    for (Banco banco1 : bancos.bancoRepository()) {
        banco.baixarPagamentos(banco1.getSaida());
    }

    return bancos.guardar(banco);
}

But it did not work gave the following error

Hibernate: select next_val as id_val from hibernate_sequence for update hibernate: update hibernate_sequence set next_val= ? Where next_val=? 2017-12-12 09:53:45,850 ERROR [org.hibernate.Internal.Exceptionmapperstandardimpl] HHH000346: Error During Managed flush [Validation failed for classes [com.almasystems.financeiro.model.Banco] During persist time for groups [javax.validation.groups.Default, ] List of Constraint violations:[ Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=name, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{org.hibernate.Validator.constraints.Notblank.message}'} Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=dataSaldoInitial, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{javax.validation.constraints.NotNull.message}'} Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=code, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{org.hibernate.Validator.constraints.Notblank.message}'} Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=company, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{javax.validation.constraints.NotNull.message}'} Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=account, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{org.hibernate.Validator.constraints.Notblank.message}'} Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=agencia, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{org.hibernate.Validator.constraints.Notblank.message}'} Constraintviolationimpl{interpolatedMessage='must be informed', propertyPath=operation, rootBeanClass=class com.almasystems.financeiro.model.Banco, messageTemplate='{org.hibernate.Validator.constraints.Notblank.message}'} ]]

Could someone please give us an idea. If you need more details, just let me know. ha ha but this is the html snippet:

<p:dataTable id="tabelaBancos" paginator="true"
        rowsPerPageTemplate="5,10,15"
        value="#{lancamentoTributoBean.listaBancos}" var="banco"
        paginatorPosition="bottom" paginatorAlwaysVisible="flase"
        style="margin-top: 5px" emptyMessage="" rows="10">

        <p:column headerText="NOME">
            <h:outputText value="#{banco.nome}" />
        </p:column>
        <p:column headerText="SALDO">
            <h:outputText style="float: right;" value="#{banco.saldoInicial}">
                <f:convertNumber type="currency" />
            </h:outputText>
        </p:column>
        <f:facet name="footer">
            <p:commandButton value="Baixar"
                action="#{cadastroBancoBean.baixarPagamentos}"
                update="tabelaBancos" process="tabelaBancos" />
            <h:outputText value="#{lancamentoTributoBean.total}">
                <f:convertNumber type="currency" />
            </h:outputText>
        </f:facet>
    </p:dataTable>`

1 answer

1

I have already found a solution and many thanks to my fellow Members.

I created a class Lowering (with a list of Trial), and a class Trial with two objects(Bench; Baixapabamento) and in the bean I created a server for the list of banks

this.listaBancos = bancos.bancoRepository();

which is loaded every time I update the html page via,

<f:metadata>
    <f:event listener="#{baixarPagamentoBean.inicializar}"
        type="preRenderView" />
</f:metadata>`

I created this

public void adicionarBancos() {
    for (Banco banco : getListaBancos()) {
        item = new ItemPagamento();
        item.setBanco(banco);
        item.setBaixarPagamento(baixarPagamento);
        baixarPagamento.getItens().add(0, item);
    }
}

method to set the values of the list and when I click the download button it executes the list and the method,

public void salvar() {
    this.baixarPagamento = this.baixarPagamentoService.salvar(this.baixarPagamento);
    this.lancamentoBean.salvar();
    FacesUtil.addSuccessMessage("Baixa efetuada com sucesso!");
}

in my bean, make the calculation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.