0

当我将我panel的拖入我的“dataTable”时,一切正常(我的监听器被调用,我的对象被添加到我的数据库中)但我的“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;
   }
}

可能是一个建议?

4

2 回答 2

1

我认为这段代码不起作用:

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

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

指向您数据表的一种解决方案是将更新设置为:

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

或者也许使用小部件变量

于 2013-10-14T14:01:30.663 回答
0

问题出在我的托管 bean“DashboardController”上,当我删除@stateless并添加了一个注入,例如:@ManagedBean(name = "dashboardController")并且在 MyMemosController 中我添加了:@ManagedProperty("value="#{dashboardController}"")。现在我的数据表已正确更新。

于 2013-10-15T12:45:33.013 回答