0

I use globalOnly="true" in h:messages to show messages as success or errors during bean methods......

<div class="row">
  <div class="col">
    <h:messages id="mensagens" warnClass="alert alert-danger" infoClass="alert alert-success" errorClass="alert alert-danger" globalOnly="true" />
  </div>        
</div>

and h:message for="" to validate field by field with bean validation

<h:inputText id="nome" styleClass="form-control" value="#{lojaMB.filial.nome}" />
<h:message for="nome" class="text-danger" />

It's works well......

enter image description here

But when I click on the "+" green button the modal opens

enter image description here

This modal use other managed bean and other form with ajax...

<h:commandButton value="Salvar" styleClass="btn btn-secondary" action="#{supermercadoMB.salvar}">
    <f:ajax execute="@form" render=":mensagens :frmNovaFilial:supermercado @form" onevent="hideModal" />
    </h:commandButton>

THE PROBLEM

when I click "Salvar" button the function "hideModal" executes, modal closes and bean validation send a error message by the blank field to parent page h:messages (no h:message ...) ....... but this message doesn't show........ Just shows when I remove globalOnly="true" .....but If I remove globalOnly="true" validations of field by field are show too on h:messages and h:message ......

how resolve this?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Pickles Dog
  • 155
  • 2
  • 11
  • Then don't close the model directly but only if there are NO validation errors. There is a Q/A about this on Stackoverflow but I currently do not have the time to find it for you – Kukeltje Mar 29 '18 at 07:16
  • Possible duplicate of [Keep p:dialog open when a validation error occurs after submit](https://stackoverflow.com/questions/9195756/keep-pdialog-open-when-a-validation-error-occurs-after-submit) – Kukeltje Mar 29 '18 at 07:28
  • In next questions, improve your title. It is to detailed for your functional problem – Kukeltje Mar 29 '18 at 08:48

1 Answers1

0
  • Create a parent element to your message component and after process the button update it
  • In the commandButton process only the nome inputText and the button itself

<h:panelGrid id="grid" columns="1">
    <h:inputText id="nome" styleClass="form-control" value="#{lojaMB.filial.nome}" />
    <h:message for="nome" class="text-danger" />
</h:panelGrid>

<h:commandButton value="Salvar" action="#{supermercadoMB.salvar}">
    <f:ajax execute="@this :nome" render=":grid" onevent="hideModal" />
</h:commandButton>
ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58