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
rsoesemannrsoesemann 

apex:actionFunction seems not to rerender

In my component I use actionfunction and rerender

<apex:component controller="MultiSelectBoxController">
	...	
	<apex:panelGrid columns="4">
		...
		<apex:actionFunction name="moveDown" action="{!moveDown}" reRender="selectedRight"/> 
		
		...
	
	    <apex:selectList id="selectedRight" required="false" value="{!selectedRight}" multiselect="true" size="20" style="width:250px">
	        <apex:selectOptions value="{!rightOptions}"/> 
	    </apex:selectList>
	
	    <apex:panelGroup layout="block" style="text-align: center; padding:10px;">
	        Up<br/>
	        <a href="javascript&colon;moveUp();" style="text-decoration:none">
	            <img src="/s.gif" alt="Move Up" class="upArrowIcon" title="Move Up"/>
	        </a><br/>
	        ...
	    </apex:panelGroup>
	</apex:panelGrid>

</apex:component>

By debuging I am sure that my action method is called correctly

 

public class MultiSelectBoxController {

	...
	
	public PageReference moveDown() {
		// For each selected item right
		for(Integer r=0; r<selectedRight.size(); r++) {
			
			// Iterate over right list
			for(Integer pos=rightOptions.size()-2; pos >=0; pos--) {
				// When select item is found 
				if(rightOptions[pos].getValue() == selectedRight[r]) {
					// Save item above
					SelectOption tmp = rightOptions[pos+1];
					// Switch options with item above
					rightOptions[pos+1] = rightOptions[pos];
					rightOptions[pos] = tmp;
				}
			}
		} 
		return null; 
	}
}

 Even in Firebug I can see the AJAX POST request coming from the rerender. But on the page nothing happens although the rightOptions have changed...

 

After an hour of trial and error I hand this over to someone whos smarter than me....

 

Robert

MattLacey.ax1065MattLacey.ax1065

The rerenender attribute isn't case sensitive is it? Noticed you have a capital in there.

 

Other than that, at first glance all looks to be correct! Maybe try wrapping the select list in an outputpanel, and rerender the panel instead.

rsoesemannrsoesemann

I renamed the attribute, the ids I even wrapped both apex:selectLists in output panels.

 

But nothing changed anything.

 

Is there a way to make a rerender visible? I tried to add a Message to the page at the end of the action method but it was not displayed.

 

Feels like trial and error in the darkness....

 

Robert

rsoesemannrsoesemann

There seems to be something wrong with the whole page. I just added the pagination from the Apex-Lang project whicht itself uses actionSupport and rerender and the same happens,

 

-  Methods are called

- HTTP Ajax Requests happen

- Nothing changes inside the page.

 

 

???

MattLacey.ax1065MattLacey.ax1065

Do you see any errors in the debug log in Firebug if you use that? You might need to paste the whole page in or something, though before doing that I'd suggest stripping the page back to a few bare essentials using comments then slowly put things back until it breaks, that way you can narrow down the problem area.

rsoesemannrsoesemann

Hy Matt,

 

can my problem haveb something to do with this bug reported here?

http://frombelvideres4thfloor.blogspot.com/2011/03/bug-with-custom-component-rerender.html

 

Sound really like my case.. Custom component rerenders part of itself.

 

But my dev org is on Winter '12?!

 

&%$§%&!

 

R.

rsoesemannrsoesemann

I move all my custom components code to the page and merged the custom components controller code with my page controller.

 

Now everything works.

 

The problem is: I need to habe all this inside a reusable component.

 

Robert

santolsantol

The main issue with ActionFunctions and custom components is that the ActionFunctions are implemented through javascript, leading to conflicts (i.e. the first component on the page calling the ActionFunctions of the second, since the javscript exists in two places on the page).

 

The way around this is to prepend some sort of unique identifier to the name attribute, and call the right one. I often accomplish this with an 'id' apex:attribute on the component:

 

<apex:component controller="MultiSelectBoxController">
    <apex:attribute name="id" type="String" default=""   description="Unique id" />

    <script>
        function stuff(){
            {!id}moveDown();
        }
    </script>
	...	
	<apex:panelGrid columns="4">
		...
		<apex:actionFunction name="{!id}moveDown" action="{!moveDown}" reRender="selectedRight"/> 
		
		...
	
	</apex:panelGrid>

</apex:component>

 

Now, when you use the component on your page, give them unique id's:

 

<c:MultiSelectBox id="1" />
<c:MultiSelectBox id="2" />
<c:MultiSelectBox id="3" />

 

...and they will call their own ActionFunctions. If you'd like to use the ActionFunctions from the outer page, just remember to call the right one ('1moveDown()', '2moveDown()', etc.).

 

Hope this helps, even though it's after the fact by a long while.

 

-Luke

GuyClairboisGuyClairbois

I was struggling with the same problem and the solution for me was to place the <apex:actionFunction> BELOW the components that need rerendering. So e.g. 

 

<apex:component controller="MultiSelectBoxController">
	...	
	<apex:panelGrid columns="4">
	
	    <apex:selectList id="selectedRight" required="false" value="{!selectedRight}" multiselect="true" size="20" style="width:250px">
	        <apex:selectOptions value="{!rightOptions}"/> 
	    </apex:selectList>
	
	    <apex:panelGroup layout="block" style="text-align: center; padding:10px;">
	        Up<br/>
	        <a href="javascript&colon;moveUp();" style="text-decoration:none">
	            <img src="/s.gif" alt="Move Up" class="upArrowIcon" title="Move Up"/>
	        </a><br/>
	        ...
	    </apex:panelGroup>
	</apex:panelGrid>

	<apex:actionFunction name="moveDown" action="{!moveDown}" reRender="selectedRight"/> 

</apex:component>

 

When the function is created earlier on, it doesn't seem to have the correct reference to the element that needs to be rerendered.