3

today i'm having some issues with actionFunction and actionSupport visualforce tag.

This is my example page:

<apex:page controller="TestLookupActionFunctionCtrl">
<apex:form id="myform">
    <apex:pageBlock>

        <!-- Test with ActionSuport - NOT WORKING! -->
        <apex:pageBlockSection title="Section 1">
            <apex:inputField value="{!c.Birthdate}">
                <apex:actionSupport event="onblur" action="{!test}" reRender="out" />
            </apex:inputField>

            <apex:outputPanel id="out" rendered="{!show}">
                <apex:inputField value="{!c.Department}" />
            </apex:outputPanel>
        </apex:pageBlockSection>

        <!-- Test with ActionFunction - NOT WORKING -->
        <apex:actionFunction name="myAction" action="{!test2}" reRender="out2" />
        <apex:pageBlockSection title="Section 2">
            <apex:inputField value="{!c2.Birthdate}" onblur="myAction()" />

            <apex:outputPanel id="out2" rendered="{!show2}">
                <apex:inputField value="{!c2.Department}" />
            </apex:outputPanel>
        </apex:pageBlockSection>

    </apex:pageBlock>
</apex:form>    

As you can see i have two pageBlockSection, each of them with an inputField to insert. I want that when user insert a value, raise the action specified by actionsupport/actionFunction tag.

This is the controller:

public class TestLookupActionFunctionCtrl {

public Contact c {get;set;}
public Contact c2 {get;set;}

public boolean show {get;set;}
public boolean show2 {get;set;}

public TestLookupActionFunctionCtrl() {
    c = new Contact();
    c2 = new Contact();
    show = false;
    show2 = false;
}

public PageReference test() {
    show = true;
    return null;
}

public PageReference test2() {
    show2 = true;
    return null;
}
}

Believe it or not, i'm not able to rerender correctly those two outputPanel :(

Could you help me please? I red on internet and the only thing that i was able to find was that both the actionFunction and actionSupport work correctly with outputPanel and both must be outside the outputPanel that are going to rerender.

Thxs guys ;)

  • Is it possible that i need to rerender the entire form in order to submit values to controller ? – Marco Zeuli May 20 '15 at 11:01
2

When rerendering an outputpanel, you must rerender a container. Wrap your outputpanels in another outputpanel and use the outer panel when rerendering. Here is an example of an action function that may help you achieve what you're trying to accomplish.

******* VISUALFORCE ******

<apex:page controller="TestLookupActionFunctionCtrl">

<script>

  function myFunc(){
    myAction();    
  }

</script>

<apex:form id="myform">
  <apex:actionFunction name="myAction" action="{!test}" reRender="RerenderMe" />
    <apex:pageBlock >
      <apex:pageBlockSection title="Section 1">

        <!-- Change onKeyup to the event you desire. onChange, onBlur, etc.  -->
        <apex:inputField value="{!c.Department}" onKeyup="myFunc()" />

        <!-- You must rerender a container.  We wrap the conditionally rendered outputPanel in another outputPanel.  Then rerender the outer panel. -->
        <apex:outputpanel id="RerenderMe">

        <!-- Inner panel rendered based on boolean in controller -->
        <apex:outputpanel id="out" rendered="{!show}">
          <apex:outputLabel for="output" value="The Output: ">
            <apex:outputfield value="{!c.department}"/>
          </apex:outputlabel>
        </apex:outputpanel>
        </apex:outputpanel>
      </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

********* CONTROLLER **********

public class TestLookupActionFunctionCtrl {

public Contact c {get;set;}

public boolean show {get;set;}

public TestLookupActionFunctionCtrl() {
    c = new Contact();
    show = false;
}

public PageReference test() {
    show = true;
    return null;
}
}

Related post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000986vIAA

  • Thx man your solution works perfect with the example... anyway in my real situation i'm still unable to get it works :( The VF page is quite big, maybe i'm missing something – Marco Zeuli May 20 '15 at 12:50
  • Can you edit your code to reflect the changes you made? There are a few things you can do to shrink your view state. Use Transient variables in your controller, limit your results displayed on the page, and use Javascript Remoting. I've seen a huge difference in speed and view state size when doing this. – Berg May 20 '15 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.