仅显示以下消息:项目阶段[开发]:未处理的消息

时间:2013-10-16 19:32:38

标签: jsf-2 primefaces myfaces

我正在尝试使用<p:messages/>显示简单消息,但只有我得到的是MyFaces开发模式的消息。我会解释一下。

在我的XHTML页面上,我有以下代码来显示我的消息:

<div class="messagePanel">
    <p:messages id="msgCalls" 
                for="msgCalls"
                showDetail="true"
                showSummary="true"
                autoUpdate="true"
                closable="true" />
</div>

在我的豆子上:

@PostConstruct
public void init() {
    try {
        this.linhaCelularId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("linhaCelularId");

        if (this.linhaCelularId == null || this.linhaCelularId.trim().isEmpty()) {
            Messages.addGlobalError(MENSAGEM_GLOBAL, "Nenhum celular especificado para listagem de ligações");
        }
        else {
            this.linhaCelularTitular = getLinhaCelularTitularService().getById(Long.parseLong(this.linhaCelularId));

            if (this.linhaCelularTitular == null) {
                Messages.addGlobalError(MENSAGEM_GLOBAL, "Celular não encontrado!");
            }
            else if (!this.linhaCelularTitular.getResponsavel().getAn8().equals(this.loginMB.getLoggedUser().getAn8())) {
                Messages.addGlobalError(MENSAGEM_GLOBAL, "Você não tem permissão para acessar essa página. Esse erro foi reportado.");
            }
            else {
                this.faturaTitular = getFaturaTitularService().getUltimaFaturaCarregada();
                this.itensFaturaTitular = getFaturaTitularService().getItensFaturaPorCelularFatura(this.linhaCelularTitular, this.faturaTitular);
            }
        }
    }
    catch (ServiceException e) {
        logger.error("Erro ao buscar ultima fatura carregada", e);
        throw new RuntimeException(e);
    }
}

问题是,Faces.addGlobalError()Faces.addError()添加的邮件未由我的<p:messages.../>显示。该消息仅显示在开发模式的未处理消息上。看一下我检查HTML:

<ul id="javax_faces_developmentstage_messages" 
    title="Project Stage[Development]: Unhandled Messages"
    style="color:orange">
    <li>
        <span title="Project Stage[Development]: Unhandled Messages">Você não tem permissão para acessar essa página. Esse erro foi reportado.</span>
    </li>
</ul>

我已经尝试了其他一些方法:

  • 仅将<p:messages/><h:messages>放在XHTML上;
  • 尝试使用Faces.addGlobalError()Faces.addError();
  • 已使用FacesMessage message = new FacesMessage();

以上都不奏效。我不知道还能做什么。目前,我正在使用MyFaces 2.1.12,Primefaces 4.0和Omnifaces 1.5。

1 个答案:

答案 0 :(得分:0)

找到了解决方案。

当我使用GET请求和参数访问我的XHTML时,在对页面上的托管bean进行“某些引用”之前,不会调用@PostConstruct。因此,标记<p:messages />放在第一次引用托管bean之前。调用@PostConstruct时,渲染消息已经太晚了。

解决方案是将preRenderView放在标记<p:messages />之前并指向方法。甚至指向一个空方法。托管bean将在<p:messages />之前构建,并且将呈现所有消息。

以下是nice explanation

关于此主题的@BalusC