0
votes

I have a overlayPanel when i click in button, that display a painel with an input.

This guy

<p:overlayPanel
    for="btnCancelNFe"
    showCloseIcon="true"
    at="left top"
    my="left bottom"
    appendToBody="true">
    <p:panel
        header="#{nfesBundle.cancellationPanelTitle}"
        rendered="#{nfesCancellationController.btnCancelEnabled}"
        styleClass="onCancelRequest">
        <sm:row>
            <sm:cell
                container="100"
                responsive="100"
                styleClass="floatLabel">
                <p:outputLabel
                    for="justification"
                    value="#{nfesBundle.cancelationInputJustification}" />
                <p:inputTextarea
                    id="justification"
                    maxlength="255"
                    required="true"
                    value="#{nfesCancellationController.justification}" />
            </sm:cell>
        </sm:row>
        <div class="clearfix" />
        <f:facet name="footer">
            <p:commandButton
                id="btnDoNFeCancellation"
                action="#{nfesCancellationController.doCancellation()}"
                process="@parent"
                update="formDialog"
                value="#{nfesBundle.btnDoNFeCancellation}"
                icon="fa fa-check"
                onsuccess="crudController.markAsChanged()" />
        </f:facet>
    </p:panel>
</p:overlayPanel>

But when i try to check any value in my dialog/overlay the value of my model (justification) is always null!

This is my controller with justification property

package eprecise.sgv.server.fiscal.nfes;

import java.io.IOException;
import java.io.Serializable;
import java.util.Optional;

import javax.ejb.ConcurrentAccessTimeoutException;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.net.ssl.SSLHandshakeException;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import eprecise.sgv.server.core.infra.CacheOnRenderResponse;
import eprecise.sgv.server.core.util.FacesMessageUtil;
import eprecise.sgv.server.core.validation.HandleConstraintViolations;
import eprecise.sgv.server.fiscal.nfes.events.NFeCancelSyncUnauthorized;
import eprecise.sgv.server.fiscal.nfes.events.NFeCancellationEvent;
import eprecise.sgv.server.fiscal.nfes.transmission.NFeTransmissionChannel;


@Named
@RequestScoped
@HandleConstraintViolations
@CacheOnRenderResponse
public class NfesCancellationController implements Serializable {

    private static final long serialVersionUID = 1L;

    private @NotNull @Size(min = 15, max = 255) String justification;

    private final NfesController controller;

    private final NFeTransmissionChannel transmissionChannel;

    private final NFesRepository repository;

    public NfesCancellationController() {
        this.controller = null;
        this.transmissionChannel = null;
        this.repository = null;
    }

    @Inject
    public NfesCancellationController(final NfesController controller, final NFeTransmissionChannel transmissionChannel, final NFesRepository repository) {
        this.controller = controller;
        this.transmissionChannel = transmissionChannel;
        this.repository = repository;
    }

    public String getJustification() {
        return this.justification;
    }

    public void setJustification(final String justification) {
        this.justification = justification;
    }

    public void doCancellation() {
        this.controller.setEntity(this.repository.find(this.controller.getEntity()));
        if (this.isBtnCancelEnabled()) {
            try {
                this.controller.getEntity().cancel(this.transmissionChannel, this.justification);
                this.controller.getEntity().getLastEvent().ifPresent(e -> {
                    if (e instanceof NFeCancellationEvent) {
                        FacesMessageUtil.addInfoMessage("Cancelada com sucesso");
                    } else if (e instanceof NFeCancelSyncUnauthorized) {
                        final NFeCancelSyncUnauthorized unauthorized = (NFeCancelSyncUnauthorized) e;
                        FacesMessageUtil.addWarnMessage(String.format("Não cancelada por: %s", unauthorized.getDetails()));
                    } else {
                        FacesMessageUtil.addInfoMessage("Transmissão efetuada, veja mais detalhes no histórico");
                    }
                });
                this.repository.update(this.controller.getEntity());
            } catch (final ConcurrentAccessTimeoutException e) {
                FacesMessageUtil.addWarnMessage("Não foi possível transmitir, tente novamente em alguns instantes");
            } catch (final RuntimeException e) {
                if ((e.getCause() instanceof SSLHandshakeException) || (e.getCause() instanceof IOException)) {
                    FacesMessageUtil.addWarnMessage("Houve um erro de comunicação com a sefaz. Tente novamente em alguns instantes");
                } else {
                    throw e;
                }
            }
        } else {
            FacesMessageUtil.addErrorMessage("Não é possível cancelar a NFe");
        }
    }

    public boolean isBtnCancelEnabled() {
        return this.controller.isInViewMode() && Optional.ofNullable(this.controller.getEntity()).map(BaseNFe::isAllowedToCancel).orElse(false);
    }
}

And this is my view

My view with overlayPanel appearing

I'm using Java 8 with primefaces 7

*note: I try to using the property dinamic = true at overlayPanel, and now i was receiving the value of the backend, but my overlayPanel broke the css

My overlayPanel with css bugs

1

1 Answers

0
votes

Two suggestions to try:

  1. See the answer to this previous question: JSF PrimeFaces overlayPanel submit value
  2. ViewScoped rather than RequestScoped on your bean.