如何在表单外移动<h:message>?</h:message>

时间:2014-10-15 14:46:33

标签: jsf jsf-2 messages

我有一个表单,我想验证电子邮件是否已存在于数据库中。我使用这段代码:

<h:panelGroup id="messagePanel" layout="block">
  <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:form>
  <h:panelGrid columns="2" class="form">
     <h:outputLabel value="#{bundle.CreateAdUserLabel_email}" for="email" />

     <h:inputText id="email" value="#{adUserController.selected.email}" 
                   title="#{bundle.EditAdUserTitle_email}" >
          <f:validator validatorId="emailVerification" />
          <f:ajax event="keydown" render="m_email" />
     </h:inputText>
     <h:message id="m_email" for="email" />
</h:form>

但我想在#messagePanel中显示错误消息。我试图将#m_email移到顶部,但它无法识别它。

1 个答案:

答案 0 :(得分:1)

将消息面板放在表单中。

<h:form>
 <h:panelGroup id="messagePanel" layout="block">
    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
 </h:panelGroup>
 <h:panelGrid columns="2" class="form">
 <h:outputLabel value="#{bundle.CreateAdUserLabel_email}" for="email" />

 <h:inputText id="email" value="#{adUserController.selected.email}" 
               title="#{bundle.EditAdUserTitle_email}" >
      <f:validator validatorId="emailVerification" />
      <f:ajax event="keydown" render="m_email" />
 </h:inputText>
 <h:message id="m_email" for="email" />
</h:form>