datatable中的行未在salesforce中更新

里沙卜·沙(Rishabh Shah)

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

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

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

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

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

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

如果我删除actionPollar的代码并从控制器..it中删除方法updateList,它会更新数据..但是,将其放置后,它将无法正常工作。

谁能告诉我该怎么做?

谢谢

马吉尔

有趣的是,它始终保留您的DataSet的相同副本,该副本每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
}

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章