How to make partial submission through a dialog called in the datatable?

Asked

Viewed 12 times

0

Hello, I have a datatable of the first faces that shows registered patients. In this datatable, I have a button that leads to a screen to inform the patient’s blood type (blood type and RH factor are class attributes Patient). If this screen to inform the blood type is in another file and I call on the datatable through a buttom with the attribute Outcome, works normally. But I want to leave this screen in a dialog and this I also got. The problem is when I click to save the blood type, I get an error message that I cannot write to the bank because the field name in Patient.java is mandatory:

This is the blood type change screen and RH factor. (Of course I replaced ui:Composition with html when calling in the dialog, so that the page does not use its own template, but rather from the datatable screen).

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://xmlns.jcp.org/jsf/html"
            xmlns:f="http://xmlns.jcp.org/jsf/core"
            xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
            xmlns:p="http://primefaces.org/ui"
            template="/WEB-INF/templates/Layout.xhtml">

<f:metadata>
    <f:viewParam name="paciente" value="#{pacienteBean.paciente}"/>
</f:metadata>

<ui:define name="content"> 

    <h:form id="formPaciente">
        <p:messages closable="true" severity="info,warn,error">
            <p:autoUpdate/> 
        </p:messages>
        <h:panelGrid columns="2" style="margin-left: 20px; margin-bottom: 5px">

            <p:outputLabel for="tipoSanguineo" value="Tipo sanguíneo: " />
            <p:selectOneMenu id="tipoSanguineo" style="width: 50px" value="#{pacienteBean.paciente.tipoSanguineo}">
                <f:selectItem noSelectionOption="true"/>
                <f:selectItem itemLabel="A" itemValue="A"/>
                <f:selectItem itemLabel="B" itemValue="B"/>
                <f:selectItem itemLabel="AB" itemValue="AB"/>
                <f:selectItem itemLabel="O" itemValue="O"/>
            </p:selectOneMenu>

            <p:outputLabel for="fatorRH" value="Fator RH: " />
            <p:selectOneMenu id="fatorRH" style="width: 50px" value="#{pacienteBean.paciente.fatorRH}">
                <f:selectItem noSelectionOption="true"/>
                <f:selectItem itemLabel="+" itemValue="+ (positivo)"/>
                <f:selectItem itemLabel="-" itemValue="- (negativo)"/>
            </p:selectOneMenu>

        </h:panelGrid>
    </h:form>    

    <p:toolbar id="toolbarPaciente" style="margin-top: 10px;">
        <f:facet name="left">
            <p:commandButton id="botaoSalvar" style="font-size: 13px;" value="Salvar"
                             icon="ui-icon ui-icon-disk" action="#{pacienteBean.salvar}">
                <f:ajax execute="@form" render="@form"/>
            </p:commandButton>

            <p:button style="font-size: 13px;" value="Cancelar" id="botaoDeletar"
                      outcome="/paciente/listar-pacientes" icon="fa fa-times">
            </p:button>
        </f:facet>
    </p:toolbar>
  </ui:define>
</ui:composition>

On this button, inside the datatable, I call the previous screen, which I can make the changes I need and save normally.

<p:button id="botaoDados" title="Editar" icon="fa fa-tint" style="font-size: 10px; padding-top: 5px"
                              outcome="/paciente/dados-sangue">
                        <f:param name="paciente" value="#{paciente.id}"/>
                        <p:tooltip for="botaoDados" value="Informar tipo sanguíneo"/>
                    </p:button>

In an attempt to pass this on to a Dialog, the same was true:

<p:dialog widgetVar="sanguePaciente" closable="true" draggable="false" modal="true" header="Tipo sanguíneo/Fator RH" responsive="true" 
              showEffect="fade" resizable="false" width="270" height="110" showHeader="false">
        <ui:include src="dados-sangue.xhtml" />
    </p:dialog>

And on the button, I change the Outcome to:

onclick="PF('sanguePaciente').show()"

However when I click the save button, it returns me this exception:

Caused by: javax.validation.ConstraintViolationException: Validation failed for classes [br.com.projeto.modelo.Paciente] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='O nome deve ser informado', propertyPath=nome, rootBeanClass=class br.com.projeto.modelo.Paciente, messageTemplate='O nome deve ser informado'}
]

I even tried to put this first screen inside the datatable itself, without using include, but it was the same.

No answers

Browser other questions tagged

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