2013-11-15 2 views
2

다음 코드는 행 (commandButton) 또는 행 (commandLink)을 추가 할 수있는 테이블에 대한 것입니다. 두 버튼 모두 작동하며 해당 bean 메소드를 호출합니다. 그러나 추가 버튼의 각 클릭에 대해 즉시 하나의 행을 추가하는 표가 업데이트되고 제거 버튼의 경우 행을 제거하기 위해 두 번 클릭해야합니다. 행이 처음으로 제거되지는 않지만 bean 메소드가 호출되고 있습니다. 어떻게해야합니까? 감사!Primeface commandLink는 두 번 클릭 한 후에 만 ​​데이터를 업데이트합니다.

<h:form id="form"> 
     <table> 
      <tr> 
       <td> 
        <h:panelGrid columns="2" width="100%"> 
         <p:dataTable id="univertitiesTable" value="#{universityBean.universityList}" var="university" 
          editable="true" editMode="cell" style="align:center;" > 

          <p:column headerText="Name" style="width:80px" > 
           <p:inputText value="#{university.name}" style="width:25px;" id="nameField" label="name" /> 
          </p:column> 

          <p:column headerText="" style="width:20px; "> 
           <p:commandLink actionListener="#{universityBean.deleteUniversity}" update="univertitiesTable" id="removeButton" ajax="true"> 
            <h:graphicImage value="/resources/icones/delete.gif" /> 
            <f:setPropertyActionListener value="#{university}" 
             target="#{universityBean.university}" /> 
           </p:commandLink> 
          </p:column> 
         </p:dataTable> 

         <p:commandButton value="+" update="univertitiesTable" id="addButton" ajax="true" 
          actionListener="#{universityBean.addUniversity}" 
          styleClass="ui-priority-primary" /> 

        </h:panelGrid>     
       </td> 
      </tr> 
      <tr> 
       <td colspan="2" align="center"> 
        <h:commandButton id="save" value="Save" 
         action="#{universityBean.save}" binding="#{save}" /> 
       </td> 
      </tr> 
     </table>  
    </h:form> 
+0

있는 명령에서'아약스 = TRUE '를 제거하는 시도하고 많은 올바른 감사 년대'commandButton' – SRy

답변

5

당신은 action 대신 actionListener 사용해야합니다. 업데이트가 작업이 완료되면 완료되므로 아무런 작업도 지정하지 않으면 즉시 업데이트가 수행됩니다. 따라서 뷰는 다른 업데이트를 수행 할 때 행이 삭제되었음을 인식합니다. 링크를 다시 클릭하면 완료됩니다.
Btw ajax="true"은 어쨌든 속성의 기본값입니다.
즉 :

<p:commandLink action="#{universityBean.deleteUniversity}" update="univertitiesTable" id="removeButton"> 
    <h:graphicImage value="/resources/icones/delete.gif" /> 
    <f:setPropertyActionListener value="#{university}" 
    target="#{universityBean.university}" /> 
</p:commandLink> 
+0

에 this''과정 = @를 추가합니다. 나는 이것을 알아낼 수 있었지만 추가 버튼이 액션 리스너와 제대로 작동하고 있었는데 왜 삭제 버튼과 같은 동작을하지 않는지 이해할 수 없습니다. – qxlab

+0

나는 똑같은 문제가 있지만이 해결책이 내 경우에 도움이되지 못하는 이유를 모르겠다. (jsf 2.2). –

+0

다른 이유가있을 수 있으므로 해당 문제에 관한 다른 SO 질문을 확인하거나 다른 질문을 올리고 세부 정보를 제공하십시오. – user1983983

관련 문제