Message is not being displayed

Asked

Viewed 244 times

0

Inside my form has a autocomplete, When activating the autocomplete and if the previous field has not been filled I want to send a message stating that the previous field must be filled. I configured but the message is not displayed on the page, someone gives a help please ?

A minha tela

My codes:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Ragrok</title>
    <h:outputStylesheet library="css" name="estilos.css" />
</h:head>
<h:form>
    <p:messages id="messages" showDetail="true" autoUpdate="false" closable="true" globalOnly="false" />
    <p:panel header="Criador de Customs">
        <p:tabView dynamic="true" cache="true">
            <p:tab id="tabs" title="Cópia dos arquivos" titleStyleClass="tab">
                <h:panelGrid columns="3">
                    <p:outputLabel value="Diretório Raiz Origem: " for="diretorioRaizOrigem" />
                    <p:inputText id="diretorioRaizOrigem" value="#{questItemController.questItem.diretorioRaizOrigem}" required="true">
                        <p:ajax event="change" process="@this" immediate="true" />
                    </p:inputText>
                    <p:message for="diretorioRaizOrigem" />
                    <p:outputLabel for="itemOrigem" value="Item Origem" />
                    <p:autoComplete id="itemOrigem" value="#{questItemController.questItem.nomeItemOrigem}"
                        completeMethod="#{questItemController.listarItensDiretorioOrigem}" dropdown="true" var="bean" itemLabel="#{bean}"
                        itemValue="#{bean}" effect="bounce" forceSelection="true" minQueryLength="3">
                        <p:ajax event="itemSelect" listener="#{questItemController.itemChange()}" update="itemDestino" process="@this" />
                    </p:autoComplete>
                    <p:message for="itemOrigem" />
                    <p:outputLabel value="Diretório Raiz de Destino" for="diretorioRaizDestino" />
                    <p:inputText id="diretorioRaizDestino" value="#{questItemController.questItem.diretorioRaizDestino}" />
                    <p:message for="diretorioRaizDestino" />
                    <p:outputLabel value="Item Destino" for="itemDestino" />
                    <p:inputText id="itemDestino" value="#{questItemController.questItem.nomeItemDestino}" />
                    <p:message for="itemDestino" />
                </h:panelGrid>
            </p:tab>
            <p:tab title="Escrita nos arquivos">
            </p:tab>
        </p:tabView>
    </p:panel>
</h:form>
</html>

Controller:

package br.com.ragrok.controller;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import br.com.ragrok.model.QuestItem;
import br.com.ragrok.util.JsfUtils;
import lombok.Getter;
import lombok.Setter;

@ManagedBean
@ViewScoped
public class QuestItemController implements Serializable {

    private static final long serialVersionUID = 1L;

    @Getter
    @Setter
    private QuestItem questItem = new QuestItem();

    @Getter
    @Setter
    private boolean mostrarImagem = false;

    public void itemChange() {
        questItem.setNomeItemDestino(questItem.getNomeItemOrigem());
        mostrarImagem = true;
    }

    public Collection<String> listarItensDiretorioOrigem(String query) {
        if (questItem.getDiretorioRaizOrigem() == null) {
            JsfUtils.addWarnMessage("Atenção você deve selecionar o diretório primeiro!");
        }
        File diretorioOrigem = new File(questItem.getDiretorioRaizOrigem());
        File[] arquivos = diretorioOrigem.listFiles();
        Collection<String> nomes = new ArrayList<String>();
        String nome;
        for (File arquivo : arquivos) {
            nome = arquivo.getName();
            if (nome.toLowerCase().contains(query.toLowerCase())) {
                nomes.add(nome);
            }
        }

        return nomes;
    }

}

Messages:

private static void addMessage(Severity severity, String mensagem) {
        FacesContext context = FacesContext.getCurrentInstance();
        FacesMessage facesMessage = new FacesMessage(severity, mensagem, "");
        context.addMessage(null, facesMessage);
    }

    public static void addWarnMessage(String mensagem){
        addMessage(FacesMessage.SEVERITY_WARN, mensagem);
    }
  • already tried with autoupdate="true" in messages?

  • @Marcusmartins was exactly that. You can answer that I valid.

1 answer

2


Try to put the autoupdate="true" in the messages.

  • Thank you very much, it worked.

Browser other questions tagged

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