有一些未处理的FacesMessages,这意味着并非每个FacesMessage都有机会被渲染 [英] There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered

查看:309
本文介绍了有一些未处理的FacesMessages,这意味着并非每个FacesMessage都有机会被渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF 2.1 + PrimeFaces 3.3页面:

I have a JSF 2.1 + PrimeFaces 3.3 page:

<h:form id="particluar">
  <p:message id="msg" globalOnly="true" display="text"/>

  <h:panelGrid columns="2" id="test">
    <h:panelGrid id="panel2" columns="3">
      <p:inputText id="name1" value="Student.studentID" required="true"/>          
      <p:commandButton value="Check Name" actionListener="#{Student.abc}" process="name1" update="panel2" />
      <p:message id="msg1" for="name1" display="text"/>
    </h:panelGrid>

    <p:inputText id="name2" required="true"/>
    <p:message id="msg2" for="name2" display="text"/>

    <p:inputText id="name3" required="true"/>
    <p:message id="msg3" for="name3" display="text"/>

  </h:panelGrid>
  <p:commandButton value="submit" actionListener="#{Student.xyz}" update="particluar" />
</h:form>

我试图在名称无效时手动添加面孔消息:

I'm trying to manually add faces messages when the name is invalid:

public void xyz() {
  if (name1.equals("primefaces")) {
    FacesContext.getCurrentInstance().addMessage("msg1", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid Name", "Invalid Name"));
  }
  if (name2.equals("primefaces")) {
    FacesContext.getCurrentInstance().addMessage("msg2", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid Name", "Invalid Name"));
  }
  if (name3.equals("primefaces")) {
    FacesContext.getCurrentInstance().addMessage("msg3", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid Name", "Invalid Name"));
  }
}

但是它们没有出现,并且服务器日志继续打印以下警告:

But they do not show up and the server log keeps printing the following warning:

有一些未处理的FacesMessages,这意味着并非每个 FacesMessage有机会被渲染

There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered

如何在页面中显示它们?

How do I show them in the page?

第二个问题,如果我提交的表单中有三个空的输入字段,则在与<p:inputText>关联的每个<p:message>中都会显示必需的输入错误消息".如何在<p:message globalOnly="true">中显示它们?

And, a second question, if I submit the form with three empty input fields, it shows "required input error message" in each <p:message> associated with the <p:inputText>. How do I show them in the <p:message globalOnly="true">?

推荐答案

如何在页面中显示它们?

您需要指定一个有效的客户端ID.客户端ID与组件ID不同.客户端ID是您在JSF生成的HTML输出中看到的任何内容.另外,客户端ID应该是输入组件之一,而不是消息组件.

You need to specify a valid client ID. The client ID is not the same as component ID. The client ID is whatever you see in the JSF-generated HTML output. Also, the client ID should be the one of the input component, not of the message component.

所以,给定

<h:form id="particular">
    <p:inputText id="name1" />
    <p:message id="msg1" for="name1" />
</h:form>

输入组件的客户端ID为particular:name1(在浏览器中右键单击页面,然后执行查看源代码自己查看).因此,该消息应恰好附加在此客户端ID上.

the input component has the client ID particular:name1 (rightclick page in browser and do View Source to see it yourself). So, the message should be attached on exactly this client ID.

context.addMessage("particular:name1", message);


第二个问题是,如果我提交的表单具有三个空的输入字段,则在与<p:inputText>关联的每个<p:message>中都会显示必需的输入错误消息".如何在<p:message globalOnly="true">中显示它们?

And, a second question, if I submit the form with three empty input fields, it shows "required input error message" in each <p:message> associated with the <p:inputText>. How do I show them in the <p:message globalOnly="true">?

<p:message>不是为此的有效组件,您应该使用<p:messages>.

The <p:message> is not the valid component for that, you should use <p:messages>.

<p:messages id="msg" globalOnly="true" display="text"/>

globalOnly="true"属性表示仅显示具有null客户端ID的消息.因此,您应该只添加这样的消息.

The globalOnly="true" attribute means that only messages with a null client ID will be shown. So, you should just add exactly such a message.

context.addMessage(null, message);

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆