+ Start a Discussion
ThomasTTThomasTT 

When I call a actionFunction multiple times at once, the controller looses some values

I'm trying to put a commandButton in each row in pageBlockTable. Those buttons call the same function ("Update"), but different parameter. The function updates the status in the row by using the given parameter to determine which row should be updated.

 

Also there is a button "refresh" to reRender the entire pageBlockTable. The statuses are updated by controller, so reRendering should not loose any data (status).

 

Initial status is "new" when you click the "update" button, the status in the row will change to the curren time.

After changing all status from "new" to time, click "refresh". Nothing should change.

 

When you click "Update"s one by one, refresh doesn't change anything.

However, when you click very quickly without waiting the end of each actionFucntion (you can do that because it's asychronous), the refresh loose some values from the page and never come back!!!

 

That's very weird because all values are stored in the controller so that page refresh shouldn't matter.

 

 

 

Is this because Controller is not stateless and the state is controlled (managed) by browser? Is that the reason why some concurrent processes conflict and loose the values?

 

 

And, what could be the workaround? disable buttons in onStart and enable them onStop?

 

Thank you in advance.

 

 

ThomasTT

 

 

[Initial page]

 

Initial page

[Change status from 'new' to the time]
Click

[After refresh, some values are lost !!]

some values are lost

 

 

 [VF page]

<apex:page controller="MultiThreadTestController">
<apex:form >
<apex:pageBlock id="pageBlock">
<apex:commandButton value="refresh" action="{!refresh}" rerender="pageBlock"/>
<apex:pageBlockTable value="{!Items}" var="item">
<apex:column >
<apex:facet name="header">Button</apex:facet>
<apex:commandButton value="Update" action="{!updateStatus}" reRender="status">
<apex:param name="selectedItem" value="{!item.name}" assignTo="{!selectedItem}"/>
</apex:commandButton>
</apex:column>
<apex:column >
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!item.status}" id="status"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 [Controller]

public class MultiThreadTestController {
class Item {
public string name {get; set;}
public string status {get; set;}
public Item(string name, string status){this.name = name; this.status = status;}
}

public Item[] items {set; get;}
public string selectedItem {get; set;}

public MultiThreadTestController (){
items = new List<Item>();
for(integer i=1;i<=5;i++) items.add(new Item(''+i, 'New'));
}

public PageReference refresh() {return null;}

public PageReference updateStatus() {
Item selected = null;
for(Item i : items){if(i.name == selectedItem){selected = i;break;}}
if(selected == null) return null;
selected.status = selectedItem + ' - ' + datetime.now();
// wait for a while
integer a = 0;
for(integer i=0;i<10000;i++) a+=i;
return null;
}
}

 

 

 

 

 

 

 

 

Ron HessRon Hess

Your idea, 

 disable buttons in onStart and enable them onStop?

 

 is a good solution.

 

not sure what could cause the page to never come back.

 

ThomasTTThomasTT

Thank you for your reply.

 

> not sure what could cause the page to never come back.

Sorry, my explanation was  poor.

Page comes back, but some values are lost (and the value never comes back).

 

I'd like to know why some of values are lost. Any idea?

 

Thank you,

 

ThomasTT

Message Edited by ThomasTT on 03-27-2009 04:47 PM