function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
stunaitestunaite 

Rerender colacteral effect!

Hi There!

 

I have a page wich loads a huge image. I want to enable a commandbutton after image is loaded. 

 

That's my page: 

<apex:page action="{!Initio}" Controller="async">
<apex:form >
	<apex:actionFunction name="enableButton" action="{!enableButton}" rerender="Button1"/>
    <script>
		function imgLoaded(){
		 	enableButton();
		}
	</script>
	<apex:commandButton id="Button1" value="myButton" action="{!doNothing}"  disabled="{!buttonDisabled}"/>
	<apex:repeat value="{!myIntegerSet}" var="myis">
		<apex:outputtext value="{!myis}"/>
	</apex:repeat>  	
  	<img src="http://www.free-pictures-photos.com/vegetable/radish-5di2.jpg" onload="imgLoaded()"/>
</apex:form>
</apex:page>

 

And my controller: 

 

 

public with sharing class async {
	
	public List<Integer> myIntegerSet;
	public Boolean buttonDisabled {get;set;}
	
	public void Initio(){
		buttonDisabled = true;
		myIntegerSet = new List<Integer>();
		myIntegerSet.add(1);
		myIntegerSet.add(2);
		myIntegerSet.add(3);
	}
	
	public void enableButton(){
		buttonDisabled = false;
	}
	
	public List<Integer> getMyIntegerSet(){
		System.debug('It was called');
		return myIntegerSet;
	}
	
	public void doNothing(){}
}

 

 

So, when image is loaded, javascript function imgLoaded is called and it calls method enableButton on controller.

A rerender of commandButton is done.

 

I can't explain why but the method getMyIntengerLst() is called twice as the result of ajax call. I checked that using system log. 

 

System.debug('It was called');

is called once when page is loading and is called twice as the result of Ajax call.

 

 

Someone can help? Yhanks in Advance

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This is published behaviour of Visualforce - from page 203 of the Developer's Guide :

 

--- snip ---

 

 

Methods may evaluate more than once — do not use side-effects
Methods, including methods in a controller, action attributes, and expressions, may be called more than once. Do not
depend on evaluation order or side-effects when creating custom methods in a controller or controller extension.

 

 

--- snip ---

All Answers

bob_buzzardbob_buzzard

This is published behaviour of Visualforce - from page 203 of the Developer's Guide :

 

--- snip ---

 

 

Methods may evaluate more than once — do not use side-effects
Methods, including methods in a controller, action attributes, and expressions, may be called more than once. Do not
depend on evaluation order or side-effects when creating custom methods in a controller or controller extension.

 

 

--- snip ---

This was selected as the best answer
stunaitestunaite

It is very boring.

 

Thanks and Regards.