首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Faces通知不起作用

Faces通知不起作用
EN

Stack Overflow用户
提问于 2014-08-03 15:17:26
回答 1查看 613关注 0票数 0

我在面孔消息上遇到了一个奇怪的问题。

有时,在执行某些方法后,<p:growl>, <p:messages>会正确显示通知。但是有一些特定的JSF页面不会显示任何通知。

例如:

代码语言:javascript
运行
复制
public String create() {
    try {
        getFacade().create(current);
        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("NotaCreated"));
        return prepareCreate();
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        return null;
    }
}

该方法在

代码语言:javascript
运行
复制
<h:commandLink action="#{notaController.create}" value="#{bundle.CreateNotaSaveLink}"/>

并且它不显示通知。但是对于其他实体以及对于其他操作,消息被正确地显示。在其他函数中也会发生这种情况,我需要反馈,但它没有像预期的那样显示出来。

我一直在搜索和阅读this post,并尝试了一些建议的解决方案,包括在commandButtons和commandLinks中设置ajax=false属性,或者使用发布的脚本,但这些都对我无效,所以我提出这个问题,希望有人能帮助我。

我必须配置一些东西才能让它正常工作吗?我需要在明天之前把它修好,我不知道还能做什么。

更新:

以下是JsfUtil方法:

代码语言:javascript
运行
复制
public static void addSuccessMessage(String msg) {
    FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
    FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg);
}
public static void addErrorMessage(Exception ex, String defaultMsg) {
    String msg = ex.getLocalizedMessage();
    if (msg != null && msg.length() > 0) {
        addErrorMessage(msg);
    } else {
        addErrorMessage(defaultMsg);
    }
}

这是Create.xhtml

代码语言:javascript
运行
复制
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
    <ui:define name="title">
        <h:outputText value="#{bundle.CreateNotaTitle}"></h:outputText>
    </ui:define>
    <ui:define name="body">
        <h:panelGroup id="messagePanel" layout="block">
            <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
        </h:panelGroup>
        <h:form>
            <h:panelGrid columns="2">

                <h:outputLabel value="#{bundle.CreateNotaLabel_fecha}" for="fecha" />
                <p:calendar value="#{notaController.selected.fecha}" id="fecha"/>
                <h:outputLabel value="#{bundle.CreateNotaLabel_observaciones}" for="observaciones" />
                <p:inputTextarea rows="4" cols="30" id="observaciones" value="#{notaController.selected.observaciones}" title="#{bundle.CreateNotaTitle_observaciones}" />
                <h:outputLabel value="#{bundle.CreateNotaLabel_tipoNota}" for="tipoNota" />
                <p:selectOneMenu id="tipoNota" value="#{notaController.selected.tipoNota}" required="true" requiredMessage="#{bundle.CreateNotaRequiredMessage_tipoNota}">
                    <f:selectItem itemLabel="---"/>
                    <f:selectItem itemValue="debito" itemLabel="Débito"/>
                    <f:selectItem itemValue="credito" itemLabel="Crédito"/>
                </p:selectOneMenu>
                <h:outputLabel value="#{bundle.CreateNotaLabel_monto}" for="monto" />
                <p:inputText id="monto" value="#{notaController.selected.monto}" title="#{bundle.CreateNotaTitle_monto}" required="true" requiredMessage="#{bundle.CreateNotaRequiredMessage_monto}"/>
                <h:outputLabel value="#{bundle.CreateNotaLabel_factura}" for="factura" />
                <p:selectOneMenu id="factura" converter="#{facturaController.convertidor}" value="#{notaController.selected.factura}" filter="true" filterMatchMode="startsWith" required="true" requiredMessage="#{bundle.CreateNotaRequiredMessage_factura}">
                    <f:selectItem itemLabel="---"/>
                    <f:selectItems value="#{facturaController.facturas}" var="factura" itemValue="#{factura}" itemLabel="#{factura.idFactura}" />
                </p:selectOneMenu>

            </h:panelGrid>
            <br />
            <h:commandLink action="#{notaController.create}" value="#{bundle.CreateNotaSaveLink}">
                <f:setPropertyActionListener value="#{cargaController.crearCargaDefault(sesionMB.usuario)}"
                                             target="#{notaController.selected.carga}"/>
            </h:commandLink>
            <br />
            <br />
            <h:commandLink action="#{notaController.prepareList}" value="#{bundle.CreateNotaShowAllLink}" immediate="true"/>
            <br />
            <br />
            <h:link outcome="/inicio" value="#{bundle.CreateNotaIndexLink}"/>
        </h:form>
    </ui:define>
</ui:composition>

EN

回答 1

Stack Overflow用户

发布于 2014-08-04 21:36:32

我也有同样的问题。面孔消息没有呈现它正在丢失。我试过这段代码,它起作用了。

代码语言:javascript
运行
复制
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().getFlash().setKeepMessages(true);
context.addMessage("successInfo", facesMsg);

我希望它能起作用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25102511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档