我有一个 xhtml 页面,其代码如下
<table width="100%" cellpadding="2">
<tr>
<td><h:form>
<h:commandButton
action="#{TypeController.addType}"
value="#{msgs.add}" />
</h:form></td>
<td width="25%"></td>
</tr>
</table>
<h:form id="mainTable">
<h:message for="main_content" errorClass="errorClass" />
<p:dataTable id="dt1" width="100%"
value="#{dataTypeListBean.dataTypeBackingBeans}"
var="item" border="2" cellpadding="2"
styleClass="table_style">
<p:column>
.....................
<p style="float: right;">
<h:commandLink
action="#{DictionaryTypeController.delete}"
onclick="return confirm('#{msgs.remove_confirm}');">
<f:setPropertyActionListener
target="#{DictionaryTypeController.selectedType}"
value="#{item}" />
<h:graphicImage
title="#{msgs.delete}"
alt="#{msgs.delete}"
url="/primefaces_resource/images/delete.png" />
</h:commandLink>
</p>
</div>
.....................
我需要捕捉一些错误并向页面显示一条消息,我写了一个代码
public String delete() {
try {
actionFilter.delete(ReferenceDataType.class, selectedType.getTypeId());
} catch (EJBTransactionRolledbackException e) {
FacesContext.getCurrentInstance().addMessage("createForm:main_content",
new FacesMessage(FacesMessage.SEVERITY_ERROR, "error", null));
return null;
}
return LIST;
}
错误被捕获,但页面不显示消息。请帮忙。