2

我正在尝试在现有的大型 SEAM 项目中向用户添加信息消息。我已将 .xhtml 页面添加<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");
    ...

编辑:“添加的面孔消息”显示在我的 Eclipse 控制台中,因此正在运行代码

我在想这个类由于某种原因不能访问 FacesContext?我在正确的轨道上吗?

4

1 回答 1

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.");
于 2012-07-31T22:20:00.253 回答