我想通过<h:messages/>
我有以下功能
public String createAccount() throws RollbackFailureException,SQLIntegrityConstraintViolationException,Exception{
String status = "failure";
EntityManager em = null;
try {
logger.log(Level.INFO,"Registering the user");
utx.begin();
em = getEntityManager();
em.persist();
status = "success";
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception re) {
throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}
if (findDetails(details.getId()) != null) {
throw new SQLIntegrityConstraintViolationException("Your Account cannot be setup as the Login Id already exists.Kindly choose a different Login ID", ex);
}
throw ex;
} finally {
if (em != null) {
em.close();
}
如何使用jsf ??
显示错误消息感谢:)
答案 0 :(得分:2)
在支持bean中使用以下内容添加消息:
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
...
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
严重性可以是SEVERITY_WARN
或SEVERITY_INFO
。您可以将clientId作为addMessage
的第一个参数。如果是null
,则该消息是全局消息,并显示在h:messages
。