一旦条件满足,我需要你的助手在页面加载时显示primefaces消息。在我描述的情况下,我需要在页面加载并且标志等于“Y”时显示primefaces消息。使用当前代码,一旦标志等于“Y”,则不显示任何内容。这是jsf页面代码:
<h:form id="form">
<div id="msg">
<p:messages id="messages" showDetail="true" autoUpdate="true" closable="false">
<p:effect type="pulsate" event="load" delay="500"/>
</p:messages>
</div>
</h:form>
这是java代码:
@PostConstruct
public void init() throws SQLException {
String error_Flag = "";
String error_Message = "Failed";
//select statement
//error flag
try {
//select statement
//return error flag from SQL statement
if (error_Flag.equals("Y")) {
FacesContext.getCurrentInstance().addMessage(null, new
FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, ""));
RequestContext context5 = RequestContext.getCurrentInstance();
context5.update("form:messages"); // I tried :form:messages but failed
}
} catch (Exception e) {
e.printStackTrace();
}
}