0
votes

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?

1
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
In next questions, improve your title. It is to detailed for your functional problem - Kukeltje

1 Answers

0
votes
  • 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>