AJAX无法更新DataGrid

时间:2013-09-20 10:57:12

标签: java ajax jsf primefaces

这是我的代码:

<p:panel id="compPanelId" header="COMPUTERS" styleClass="compPanel">
<h:form id="availableCompForm">
    <div style="text-align: center; margin-bottom: 8px;">
        <p:commandLink id="addCompBtn" value="Add" actionListener="#{coltsysLab.addComputer(event)}" style="height: 30px; font-size: 13px; margin-left: 10px;" update="availableCompForm"/>
    </div>

    <p:dataGrid id="availableComputers" value="#{coltsysLab.computer}" var="computer" columns="3" emptyMessage="No Computers Added Yet">  
        <p:column>  
            <p:graphicImage id="computer" value="http://localhost:8080/COLTSysResources/resources/images/#{computer.pic}" styleClass="computerImage"/>  
            <p:draggable for="computer" revert="true" scope="#{computer.status}" stack=".computerImage"/>
        </p:column> 

    </p:dataGrid> 

</h:form>
</p:panel>

单击“添加命令”链接后,数据网格不会更新

方法addComputer中的托管bean代码是:

    try (Connection conn = dataSource.getConnection()) { 
         ColtsysDAO coltsysDAO = new ColtsysDAO(conn); 
         coltsysDAO.addComputer(currentComputer, labId); 
     } catch (Exception e) {
         e.printStackTrace(System.err); 
     }

1 个答案:

答案 0 :(得分:0)

所以我设法让它发挥作用。问题是我没有更新计算机列表。我首先清除了列表computers.clear()然后再次重新填充(添加后,它直接添加到数据库中,因此可以清除它)