0

我有一个没有的数据表。的记录可用。

我正在使用 actionPollar 并且我的操作是 updateList 以获取最新列表以在给定时间间隔内显示在我的视图中,并使用以下代码

<apex:actionPoller action="{!updateList}" reRender="thePageBlock" interval="5"/>

现在,我正在使用下面的代码更新任何行。

<apex:commandButton action="{!quicksave}" value="Save" id="saveButton" reRender="thePageBlock"/>

但是,它没有改变。并且不更新记录。

如果我删除 actionPollar 的代码并从控制器中删除方法 updateList ..它会更新数据..但是,在放置之后,它就不起作用了。

谁能告诉我该怎么做?

谢谢

4

1 回答 1

1

有趣的是,它始终保留您的 DataSet 的相同副本,该副本每 5 秒刷新一次并显示,这意味着您的 ViewState 也每 5 秒刷新一次,在我看来,您可能会提交上次收到的相同值,但不包含任何改变,我会走两条路线之一:

  1. 在编辑模式或进行更改时停止轮询器也阻止编辑记录,这样其他人就无法覆盖您的更改。
  2. 将 viewState 拆分为两个单独的 ViewState,一个用于加载记录,第二个用于编辑选定的记录,当保存第一个 ViewState 时,将使用对第二个 ViewState 所做的最后更改进行刷新,您可以通过使用来完成此操作多种形式和同步机制。

使用选项(1)的建议解决方案,轮询器保持活动状态,不会干扰记录,选择时仍然缺少记录的锁定机制

视觉力量页面

<apex:page controller="MultipleActionRegionsCtrl">

<!-- SINGLE FORM -->

<apex:form >

<apex:pageBlock title="Master Detail Record Selection/Edition">

<!-- MASTER LIST -->
<apex:pageBlockSection title="Available Records">
<apex:actionRegion >

<!-- TABLE-->
<apex:outputPanel id="recordsPanel">
<apex:PageBlockTable value="{!cList}" var="c">
<apex:column value="{!c.FirstName}"/> 
<apex:column value="{!c.LastName}"/> 
<apex:actionSupport event="onRowClick" action="{!editSelectedRecord}" rerender="recDetail" status="dataUpdateStatus">
<apex:param name="cid" value="{!c.Id}" />
</apex:actionSupport>
</apex:PageBlockTable>
</apex:outputPanel>          
<apex:actionStatus id="dataRefreshStatus">
<apex:facet name="start">Refreshing...</apex:facet>
<apex:facet name="stop">Data Loaded</apex:facet>
</apex:actionStatus>

<!-- RELOAD TABLE-->
<apex:actionPoller action="{!reloadContacts}" reRender="recordsPanel" interval="5" status="dataRefreshStatus"/>

</apex:actionRegion>
</apex:pageBlockSection>

<!-- DETAIL -->
<apex:pageBlockSection title="Record Details" id="recDetail" columns="2">
<apex:actionRegion rendered="{!IF(editableRecord=null,false,true)}">
<table>
<tr>
<td colSpan="2">
&nbsp;
<apex:actionStatus id="dataUpdateStatus" >
<apex:facet name="start">Loading...</apex:facet>
<apex:facet name="stop"> </apex:facet>
</apex:actionStatus>
</td>
</tr>
<tr>
<td>First Name </td>
<td><apex:inputField value="{!editableRecord.FirstName}"/></td>
</tr>
<tr>
<td>Last Name </td>
<td><apex:inputField value="{!editableRecord.LastName}"/></td>
</tr>                 
<tr>
<td><apex:commandButton action="{!saveRecord}" value="Save" reRender="recordsPanel,recDetail"/></td>
</tr>
</table>
</apex:actionRegion>    
</apex:pageBlockSection>

</apex:pageBlock>     

</apex:form>

</apex:page>

控制器

public class MultipleActionRegionsCtrl {

public Map<ID, Contact> cMap {get;set;}
public Contact editableRecord {get;set;}

// Using lazy load for test purposes
public List<Contact> cList {
get{
if(cMap == null){
cMap = new Map<ID, Contact>([SELECT Id, FirstName, LastName From Contact limit 10]);
}
return cMap.values();
}
}

public MultipleActionRegionsCtrl(){ }

public PageReference reloadContacts(){
if(cMap!=null && !cMap.isEmpty()){
Set<Id> myIds = cMap.keySet();
// reload same records loaded at the start
cMap = new Map<ID, Contact>([SELECT Id, FirstName, LastName From Contact WHERE Id IN :myIds]); 
}
return null;
}

public PageReference editSelectedRecord() {
String cID = ApexPages.currentPage().getParameters().get('cid');
if(cMap!=null && !cMap.isEmpty() && cMap.containsKey(cID)){
editableRecord = cMap.get(cID);
}
return null;
}

public PageReference saveRecord(){
update editableRecord;
editableRecord = null; // so we don't save two times same record
return reloadContacts(); //instantly update current list do not wait for poller
}

}
于 2013-08-26T16:31:53.313 回答