我想在这个表的单独一行中呈现错误。但是,当我使用ui:repeat时,绑定不起作用,因为它将所有行设置为相同的值。
<ui:repeat id="quest" value="#{questions}" var="question">
<tr>
<td class="col-md-2">
<p:selectOneRadio id="questionId" value="#{question.response}" binding="#{questionBinding}" validator="#{question.validate}" required="true" requiredMessage="You must answer the question to continue">
<f:selectItem itemLabel="Yes" itemValue="Yes" />
<f:selectItem itemLabel="No" itemValue="No" />
<p:ajax update="error-row" />
</p:selectOneRadio>
</td>
</tr>
<h:panelGroup id="error-row">
<ui:fragment rendered="#{not empty facesContext.getMessageList(questionBinding.clientId)}">
<tr>
<td colspan="2"><p:message for="questionId" id="msgQuestion" /></td>
</tr>
</ui:fragment>
</h:panelGroup>
</ui:repeat>
在ajax更新时调用javascript:
....
<p:ajax update="msgQuestion" oncomplete="clearEmptyRows()" />
....
使用javascript函数:
<script>
function clearEmptyRows() {
$(".error-row").each(function(index) {
if ($(this).text().trim() == '') {
$(this).css("display", "none");
} else {
$(this).css("display", "table-row");
}
});
}
$(document).ready(function() {
clearEmptyRows();
});
</script>