I have a page where I need to display an error message for a given field, and I'm using the <apex:message>
tag to display it. This all works fine if the message is rendered on first page load, but the message seems to be lost if the section is rerendered? Has anyone managed to make this work?
Here's the core bit of the VF page:
<!-- sample field that controls rerendering -->
<apex:actionRegion>
<apex:inputField value="{!Account.Industry}">
<apex:actionSupport event="onchange" status="status" rerender="sampleBlock" />
</apex:inputField>
</apex:actionRegion>
<!-- rendered on page load, we can see the error isn't lost -->
<apex:pageBlock title="Rendered always">
<apex:inputField value="{!Account.Name}" id="name_always" />
<apex:message for="name_always" />
</apex:pageBlock>
<apex:pageBlock title="Sometimes rendered" id="sampleBlock">
<apex:variable var="ShouldRender" value="{!NOT(ISBLANK(Account.Industry))}" />
<!-- rendered when an industry is chosen, no error message? -->
<apex:outputPanel rendered="{!ShouldRender}">
<apex:inputField value="{!Account.Name}" id="name" />
<apex:message for="name" />
</apex:outputPanel>
</apex:pageBlock>
Screen grab of the resulting page and highlighted missing error: