2013-10-14 75 views
0

当我将我的panel拖入我的'dataTable'中时,所有工作都正常(我的侦听器被调用,我的对象被添加到我的DataBase中),但是我的'dataTable'没有更新,我需要刷新我的页面才能看到它。我的XHTML:为什么我在添加数据后无法刷新数据表?

<h:form id="formDashboard"> 
    <p:layoutUnit id="gridLeft" position="west" size="250" style="position:absolute;"> 
     <p:fieldset style="padding:0;padding-top:5px;"> 
      <f:facet name="legend" id="legendId"> 
       <p:commandButton icon="ui-icon-plus" actionListener="#{myMemosController.prepareCreate}" value="Add Memo" onclick="addMemo.show()" update=":formAdd:commentAddInput, :formAdd:chooseAddPriority" style="width:30px;height:30px;"/> 
      </f:facet> 
      <p:dataGrid id="leftData" var="item" columns="1" value="#{myMemosController.items}" style="border:none;"> 
       <p:panel id="pnl" style="background-color:#{item.priority}}" closable="true"> 
        <p:ajax event="close" listener="#{myMemosController.destroy}"/> 
        <f:facet name="header"> 
         <h:panelGroup> 
          <h:outputText value="#{item.name}" styleClass=""/> 
          <p:commandButton icon="ui-icon-pencil" actionListener="#{myMemosController.prepareEdit}" update=":formEdit:commentEditInput, :formEdit:chooseEditPriority" onclick="editMemo.show();" style="width:19px;height:19px;"/> 
         </h:panelGroup> 
        </f:facet> 
        <h:panelGrid columns="1" style="width:100%"> 
         <h:outputText value="#{item.comments}" styleClass=""/> 
        </h:panelGrid> 
        <f:facet name="footer"> 
         <h:outputText value="#{item.date} at #{item.time}" styleClass="footerStyle"/> 
        </f:facet> 
       </p:panel> 
       <p:draggable for="pnl" helper="clone" handle=".ui-panel-titlebar" stack=".ui-panel" zindex="100"/> 
      </p:dataGrid> 
     </p:fieldset>   
    </p:layoutUnit> 

<p:layoutUnit position="center" style="position:absolute;"> 
<p:fieldset id="selectedMemos" legend="Selected Memos" style="margin-top:20px"> 
<p:outputPanel id="dropArea"> 
    <p:dataTable id="centerData" value="#{dashboardController.items}" var="item"> 
     <p:column style="text-align:center;"> 
      <f:facet name="header"> 
       <h:outputText value="Priority"/> 
      </f:facet> 
      <h:outputText value="#{item.priorityname}"/> 
     </p:column> 
     <p:column style="text-align:center;"> 
      <f:facet name="header"> 
       <h:outputText value="Name"/> 
      </f:facet> 
      <h:outputText value="#{item.name}"/> 
     </p:column> 
     <p:column style="text-align:center;"> 
      <f:facet name="header"> 
       <h:outputText value="Comment"/> 
      </f:facet> 
      <h:outputText value="#{item.comments}"/> 
     </p:column> 
     <p:column style="text-align:center;"> 
      <f:facet name="header"> 
       <h:outputText value="Time"/> 
      </f:facet> 
      <h:outputText value="#{item.time}"/> 
     </p:column> 
     <p:column style="text-align:center;"> 
      <f:facet name="header"> 
       <h:outputText value="Date"/> 
      </f:facet> 
      <h:outputText value="#{item.date}"/> 
     </p:column> 
    </p:dataTable> 
    </p:outputPanel> 
</p:fieldset> 
<p:droppable for="selectedMemos" tolerance="touch" activeStyleClass="ui-state-highlight" > 
    <p:ajax listener="#{myMemosController.onMemoDrop}" process="@this" update="dropArea, leftData"/> 
</p:droppable> 
</p:layoutUnit> 
</h:form> 

我的方法onMemoDrop:

public void onMemoDrop(DragDropEvent ddEvent) 
{ 
    String[] idTokens = ddEvent.getDragId().split(String.valueOf(UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance()))); 
    int rowIndex = Integer.parseInt(idTokens[idTokens.length - 2]); 
    String name = idTokens[idTokens.length - 3]; 

    MyMemos memo = null; 
    if (name.equals("leftData")) 
    { 
    items.setRowIndex(rowIndex); 
    memo = (MyMemos) items.getRowData(); 
    dashboardController.create(1, memo.getName(), memo.getComments(), memo.getDate(), memo.getTime(), memo.getPriority(), memo.getPriorityname()); 
    } 
} 

和创建方法:

public String create(int id, String name, String comment, String date, String time, String priority, String priorityName) 
{ 
    try 
    { 
     System.out.println("I am in Create() method from DashboardController"); 
     current = new Dashboard(id, name, comment, date, time, priority, priorityName); 
     getFacade().create(current); 
       JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/resources/Bundle").getString("DashboardCreated")); 
     return prepareCreate(); 
    } catch (Exception e) { 
     JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/resources/Bundle").getString("PersistenceErrorOccured")); 
    return null; 
    } 
} 

可能是一个建议?

+0

你的bean的范围是什么? –

+0

在SessionScoped中。 – Samolo

+0

但我的方法创建来自另一个控制器,这个问题可以从这里来吗? – Samolo

回答

1

我认为这个代码不工作:

<p:ajax listener="#{myMemosController.onMemoDrop}" process="@this" update="dropArea, leftData"/> 

,因为这个号码:AJAX无法解析 'dropArea'。最终,该组件无法找到并且没有得到更新。

一个解决方案,以指向您的DataTable设置更新为:

update=":#{p:component('centerData')}, :#{p:component('leftData')}" 

也许使用插件瓦尔

+0

我试过你的解决方案,但没有任何改变。我如何用小部件变量更新我的'dataTable'? – Samolo

0

问题是从我管理豆“DashboardController”,当我删除@stateless,并增加了注入像:@ManagedBean(name = "dashboardController")和MyMemosController我补充说:@ManagedProperty("value="#{dashboardController}"")。现在我的dataTable正确更新。

相关问题