JSF有条件地在一行中呈现错误
我希望在此表的单独一行中呈现错误。但是,当我使用ui:repeat时,绑定不起作用,因为它将所有行设置为相同的值JSF有条件地在一行中呈现错误,jsf,jsf-2,primefaces,jsf-2.2,Jsf,Jsf 2,Primefaces,Jsf 2.2,我希望在此表的单独一行中呈现错误。但是,当我使用ui:repeat时,绑定不起作用,因为它将所有行设置为相同的值 <ui:repeat id="quest" value="#{questions}" var="question"> <tr> <td class="col-md-2"> <p:selectOneRadio id="questi
<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>
函数clearEmptyRows(){
$(“.error行”)。每个(函数(索引){
如果($(this).text().trim()=''){
$(this.css(“显示”、“无”);
}否则{
$(this.css(“显示”、“表行”);
}
});
}
$(文档).ready(函数(){
clearEmptyRows();
});
您必须指定具体的id
,该id根据迭代索引是唯一的。您可以使用像
这样的迭代组件来实现同样的效果,而不是使用一个杂散的
来手动生成
。或者在这种情况下使用c:foreach
(但是看看它是否没有副作用)