0

我有一個數據表,其中沒有。的記錄可用。從datatable行未在銷售隊伍中更新

我使用actionPollar和我的動作是updateList以獲得最新的清單,下面的代碼

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

,以顯示我對給定的時間間隔視圖現在,我更新使用下面的代碼的任何行。

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

但是,它沒有改變。並且不更新記錄。

如果我刪除actionPollar的代碼,並從控制器中刪除方法updateList ..它更新數據..但是,放在它後,它不起作用。

誰能告訴我該怎麼做?

感謝

回答

1

有趣,所以它始終保持你的數據集,這是被刷新,每5秒顯示的同一個副本,這意味着你的ViewState是被還刷新每5秒鐘,在我看來,你可能被提交最後接收不包含任何變化相同的價值觀,我會去兩條路線之一:

  1. 停止時,編輯模式或更改也阻斷編輯記錄,因此沒有人可以覆蓋您的更改輪詢。
  2. 將viewState拆分爲兩個獨立的ViewState,一個將加載記錄,第二個將用於編輯選定的記錄,當保存第一個ViewState將被第二個ViewState所做的最後更改刷新時,您可以完成這通過使用多種形式和同步機制。

使用選項提出的解決方案(1)中,輪詢器保持激活它不與記錄干擾,選擇

VisualForce頁

<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 
} 

} 
+1

謝謝你的回覆。正如你在第一點提到的那樣:阻止編輯記錄以便其他人不能覆蓋你的改變如何阻止和我已經分開了兩種形式。這是真的嗎? ' --data表和outputfield-- ' ' <頂點:actionPoller行動= 「{!updateList}」 重新呈現= 「thePageBlock(上面給出的數據表的ID)」 間隔=「5 「/> ' –

+0

忘記提及ActionRegion是否存在您正在實施的此類案例,請在此處查找更多詳細信息:http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm 。通過分割表單,您的視圖狀態也會變得分散,這就是我之前使用條件呈現觀察到的行爲,這一切都取決於您的要求,但我強烈建議直接使用單獨的actionRegions來解決方案1。 – magdiel

相關問題