我在使用 p:messages 时遇到问题,所以我尝试对每个组件使用 p:message,如下所示:
<div style="position: relative;">
<h:panelGrid id="messages" columns="1">
<p:message for="idTxtFirstName" id="msgFirstName" />
<p:message for="idTxtLastName" id="msgLastName" />
<p:message for="idTxtTitle" id="msgTitle" />
<p:message for="idTxtCompany" id="msgCompany" />
<p:message for="idTxtEmail" id="msgEmail" />
<p:message for="idTxtPhoneNumber" id="msgPhoneNumber" />
<p:message for="idEstNumOfUser" id="msgEstNumOfUser" />
</h:panelGrid>
</div>
即使有任何错误,默认生成的 html 也是:
<table id="betasignup:messages">
<tbody>
<tr>
<td><div id="betasignup:msgFirstName" aria-live="polite"></div></td>
</tr>
<tr>
<td><div id="betasignup:msgLastName" aria-live="polite"></div></td>
</tr>
<tr>
<td><div id="betasignup:msgTitle" aria-live="polite"></div></td>
</tr>
<tr>
<td><div id="betasignup:msgCompany" aria-live="polite"></div></td>
</tr>
<tr>
<td><div id="betasignup:msgEmail" aria-live="polite"></div></td>
</tr>
<tr>
<td><div id="betasignup:msgPhoneNumber" aria-live="polite"></div></td>
</tr>
<tr>
<td><div id="betasignup:msgEstNumOfUser" aria-live="polite"></div></td>
</tr>
</tbody>
</table>
所以我想知道如果只有组件的验证失败(通常不是验证失败),如何呈现消息组件,我的意思是在仅相关组件出现验证错误之前不生成任何 html。