質問

I have one data table where no. of records are available.

I am using actionPollar and my action is updateList to get the latest list to display on my view on given time interval with below code

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

Now, I am updating any row using below code.

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

but, it does not change. and does not update the record.

if i remove code of actionPollar and remove method updateList from controller ..it updates the data..but, after putting it, it does not work.

Can anyone tell how Can I do that ?

Thanks

役に立ちましたか?

解決

Interesting, so it is always keeping same copy of your DataSet, which is been refreshed every 5 seconds and displayed, that means your ViewState is been refreshed also every 5 seconds, it looks to me you might be submitting same values last received not containing any changes, I'll go one of two routes:

  1. Stop the poller when edit mode or making changes also blocking the record for editing so no one else could overwrite your changes.
  2. Split the viewState into two separate ViewStates, one is going to load records, second one is going to be used for editing selected record, when saved first ViewState is going to be refreshed with last changes made on second ViewState, you can accomplish this by using multiple forms and a syncing mechanism.

Proposed solution for using option (1), the poller stays active it is not interfering with the record, still missing a lock mechanism for the record when selected

VisualForce Page

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

Controller

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
}

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top