1

I am trying to break my page into multiple components so it can be reused on several pages. The component is essentially a form and after submission, would like the parent page to rerender a certain outputpanel block. This is the code I used to use:

<apex:actionFunction name="reRenderNewFeedPanel" action="{!afterSaveAttachment}" reRender="NewFeedPanel, FeedListPanel" />

but from within the component, the reRender on "FeedListPanel" doesn't seem to work, because it's not refreshing.

1
  • UPDATE: I thought calling the reRender from the component wasn't working, but after putting in a javascript alert with counter, it looks like it is actually being reRendered. The reason I thought it wasn't working is because the data in the "FeedListPanel" wasn't refreshing with the newest data. Why is it that when I broke out the section into a component, the reRender isn't pulling the latest data?
    – slim
    Commented Oct 21, 2016 at 15:37

2 Answers 2

2

Yes you can rerender an element on the parent from the component. The component just gets merged into the DOM of the parent.

NOTE What you cannot do is update values of the parent controller from the component unless you pass in those vales (i.e. sObject, record, wrapper, etc) as an attribute to the component

To illustrate:

VF Page (Parent)

<apex:page>


<script>
    var x = 0;
</script>

<c:mytestcomponent/>

<apex:outputPanel layout="block" id="parentDiv">
    <script>
        x += 1;
        alert('The value of x is now: ' + x);
    </script>
</apex:outputPanel>


</apex:page>

Component

<apex:component >


    <apex:form >
        <apex:commandButton value="Click Me" rerender="parentDiv"/>
    </apex:form>

</apex:component>

On load you get an alert of '1'. On each click of the button in the component the value of x increments due to the rerender.

If you think something else is happening then change the name of the rerender attribute to something that does not exist and you will see that you get no alert. Thus it is the rerender that is working here

5
  • Thanks Eric, but is there a way to invoke it without a commandButton? Take a look at my actionFunction code. That's where I'd like the reRender to trigger.
    – slim
    Commented Oct 21, 2016 at 14:15
  • @slim actionfunction and command button no difference. Take my example and start adding in your actionfunction little by little verifying it works. When it breaks as you add your stuff you will know why.
    – Eric
    Commented Oct 21, 2016 at 14:17
  • UPDATE: I thought calling the reRender from the component wasn't working, but after putting in a javascript alert with counter, it looks like it is actually being reRendered. The reason I thought it wasn't working is because the data in the "FeedListPanel" wasn't refreshing with the newest data. Why is it that when I broke out the section into a component, the reRender isn't pulling the latest data?
    – slim
    Commented Oct 21, 2016 at 15:37
  • @slim - The controller in the main page is separate from the component. If you want to modify data from the main page you need to pass it to the component via the <apex:attribute> if you do not do that then the main page controller data will not be updated.
    – Eric
    Commented Oct 21, 2016 at 16:02
  • Thanks @Eric. Even if the main page is told to reRender part of its own page? It's just supposed to update the FeedListPanel with the newly posted content. The component I have created was just the posting part of the page, where the user creates a new post. The FeedListPanel is supposed to refresh and have the new post. I know it's reRendering, but the new content isn't shown.
    – slim
    Commented Oct 21, 2016 at 18:38
1

Yes, but not directly. It requires some JavaScript an an extra round-trip to the server. This requires the parent's cooperation.

<!-- parent page -->
<apex:actionFunction name="refreshPage" reRender="NewFeedPanel, FeedListPanel" />

 <!-- component -->
 <apex:actionFunction name="reRenderNewFeedPanel" action="{!afterSafeAttachment}" onComplete="refreshPage()" />
2
  • see below for an example of this working. Only know this for sure because I have made heavy use of it lately to put a page on its own and in a configuration wizard page.
    – Eric
    Commented Oct 19, 2016 at 22:27
  • I tried this method and it's not working. Any idea why it wouldn't work?
    – slim
    Commented Oct 21, 2016 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .