2015-07-02 22 views
0

我想在此表的单独一行中呈现错误。但是,当我使用ui:repeat时,绑定不起作用,因为它将所有行设置为相同的值。在AJAX更新JSF有条件地呈现连续错误

  <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> 
+0

您必须指定具体的'id'将根据迭代指数是唯一的。你可以使用迭代组件''而不是使用流浪的''手动生成''来达到同样的效果。 – Tiny

+0

或在这种情况下使用'c:foreach'(但是看看它是否没有副作用) – Kukeltje

回答

0

调用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>