我正在尝试在现有的大型SEAM项目中向用户添加信息消息。我已将<h:messages/>
添加到.xhtml页面,这些是我在名为AbstractChartController
的类的代码中的尝试,但是当操作后页面刷新时,会显示非FacesMessages,任何人都知道我接下来可以尝试什么?
if (axis.getAxisType() == AxisType.LOGARITHMIC && axis.getLowestValue() <= 0d){
//Non of this code works:
//Attempt 1
FacesMessages facesMessages = FacesMessages.instance();
facesMessages.add(FacesMessage.SEVERITY_INFO, "Note: Data contains values below or equal to zero so cannot be plotted on a logarithmic axis.");
//Attempt 2
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage("Test2");
context.addMessage(null, message);
//Attempt 3
org.jboss.seam.faces.FacesContext myContext = (org.jboss.seam.faces.FacesContext) Component.getInstance("FacesContext");
if (myContext != null) { //Why is this null in debug?
myContext.getContext().addMessage("Test3", message);
}
//Attempt 4:
//StatusMessages.instance()
//.add(StatusMessage.Severity.INFO, "Test4");
// (Compile time error above that it can't find StatusMessages class to import)
System.out.println("FacesMessage added");
...
编辑:“添加了Faces消息”正在我的eclipse控制台中显示,因此代码正在运行
我认为这个类由于某种原因无法访问FacesContext?我是在正确的轨道上吗?
答案 0 :(得分:1)
StatusMessages statusMessages = Component.getInstance("statusMessages");
statusMessages.add(Severity.ERROR,"Note: Data contains values below or equal to zero so cannot be plotted on a logarithmic axis.");