0

I have a Visualforce page, with a pageblocktable that is dependent on some date fields. When the dates change I would like to rerender the table, and then rerender the pageMessages. At the moment, they rerender at the same time, so the error message doesn't disappear if the error is corrected. I would like the messages to rerender once the getRowList() method has run.

Visualforce:

<apex:pageBlockSection title="Select Dates (Optional)" columns="2">
    <apex:input value="{!startDate}" label="Start" id="date1">
        <apex:actionSupport event="onchange" action="{!getSelected}" rerender="timeline,messages"/>
    </apex:input>
    <apex:input value="{!endDate}" label="End" id="date2">
        <apex:actionSupport event="onchange" action="{!getSelected}" rerender="timeline,messages"/>
    </apex:input>
</apex:pageBlockSection>
<apex:pageMessages id="messages"/>
<apex:outputPanel id="timeline">
    <apex:pageBlockSection title="Timeline" rendered="{!rowList.size>0}" columns="1">
        <apex:pageBlockTable value="{!rowList}" var="r" >

Apex Controller:

public List<Row> getRowList(){
    if(startDate > endDate){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Sorry, start date must be before end date.'));
    }
    return new List<Row>{Some instances of wrapper....}
}
  • Isn't the problem that you're adding an ApexPages.Message to the page, but never removing it? When you re-render a section of the page, the pagemessages stays the same. The previous error will always be there. – Nick Cook Dec 21 '15 at 11:35
  • @NickCook If I change the date again after correcting it, this rerenders both elements and therefore removes the pageMessages. – fred Dec 21 '15 at 11:38
  • The pageMessage is removed as soon as the pageBlockTable finishes rerendering, however, the pageMessages need to be rerendered after this happens. – fred Dec 21 '15 at 11:41
4

You could utilize the oncomplete attribute to ensure the order of the reRendering.

e.g.

 // here you are reRendering two elements
<apex:actionSupport event="onchange" action="{!getSelected}" rerender="timeline,messages"/>

Instead, you could split them up so you know one fires before the other

<apex:actionSupport event="onchange" action="{!getSelected}" rerender="timeline" oncomplete="reRenderMessages();"/>

<apex:actionFunction name='reRenderMessages' reRender='messages'/>

I don't believe I've used this approach before, but, based on my understanding, this should meet your requirements.

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.