我无法使用facesMessage
显示面部消息Bean代码:
if(condition){
FacesContext fc=FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Rounding Rule Saved","R Saved"));
}
查看代码:
<p:messages autoUpdate="true" showDetail="true" globalOnly="true" id="msgId"/>
但我没有收到消息,我做错了什么?
编辑:
我的项目流程是:
查看代码(rouning_rule_master.xhtml):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<ui:composition template="/pages/webEx_Template.xhtml">
<ui:define name="content">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rounding Rule Master</title>
<link rel="stylesheet" type="text/css" href="../css/rounding_rule_master.css" />
</h:head>
<h:body>
<div class="wrapper">
<div class="page_wrapper">
<div class="page_heading border_bottom">Rounding Rule Master</div>
<div class="form_div">
<h:form id="roundingMasterFormId" >
<p:messages autoUpdate="true" showDetail="true" globalOnly="true" id="MESSAGEID"/>
<div class="form_detail">
<div class="float_right">
<h:commandButton id="creataeBtn" action="#{roundingBean.createRoundingRule}" value="Create Rounding Rule" class="createRelation" >
<p:ajax onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
</h:commandButton>
</div>
<div class="clear"></div>
<div style="margin:10px 0;">
<table id="roundingMasterTableId" width="100%" cellspacing="1" cellpadding="0" border="0" class="role_detail_section">
<thead>
<tr>
<th>Rounding Rule Id</th>
<th>Rounding Rule Name</th>
<th>Rounding Mode</th>
<th>Rounding Constant</th>
<th class="action">Action</th>
</tr>
</thead>
<tbody>
<c:forEach items="#{roundingBean.roundingRuleList}" var="var" >
<tr>
<h:inputHidden value="#{var.roundingRuleId}" />
<td><h:outputText value="#{var.roundingRuleId}" /></td>
<td><h:outputText value="#{var.roundingRuleName}" /></td>
<td><h:outputText value="#{var.roundingMode.roundingModeName}" /></td>
<td><h:outputText value="#{var.roundingIncrement}" /></td>
<td>
<p:commandLink value="Edit" styleClass="edit_icon" action="#{roundingBean.editRoundingRule (var,true)}" immediate="true" process="@this" onstart="statusDialog.show();" onsuccess="statusDialog.hide();">
</p:commandLink>
<p:commandLink id="deleteId" styleClass="remove_icon" action="#{roundingBean.deleteRoundingRule(var.roundingRuleId)}" immediate="true" update="@form" process="@this" oncomplete="addCSS()" onstart="statusDialog.show();" onsuccess="statusDialog.hide();">
<p:confirm header="Confirmation" message="Are you sure want to delete rounding rule ?" icon="ui-icon-alert" />Delete
</p:commandLink>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
<p:confirmDialog styleClass="confirm" global="true" showEffect="fade" draggable="false" closable="false" resizable="false" width="400">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes"/>
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no"/>
</p:confirmDialog>
<p:dialog styleClass="confirm" modal="true" widgetVar="statusDialog" header="Loading..."
draggable="false" closable="false" resizable="false" width="100"
height="50">
<div align="center">
<p:graphicImage value="../images/loading.gif" width="50"
height="50" />
</div>
</p:dialog>
</h:form>
</div>
</div>
</div>
</h:body>
</ui:define>
</ui:composition>
</html>
答案 0 :(得分:0)
我不确定你的情况。但是,如果在生成消息后重定向,则它们会在重定向过程中丢失。您需要确保在页面流中面部配置中没有重定向 - 或任何其他方法。