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
JeffreyStevensJeffreyStevens 

Show ApexPages.Message in embedded visualforce page

Does <apex:pageMessages /> work the same with the VF page is embedded in a standard page?

I've added (inside the form tag)...

<apex:pageMessages />

then from the controller extn - I'm doing a 
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'ERROR message.'));

But I never see the message.  I've verified that the code is executing for the ApexPages.add...

 
Best Answer chosen by JeffreyStevens
JeffreyStevensJeffreyStevens
Wow - I finally got this working. 

I had my pageReference method that was referenced in the commandLink return a void instead of a pageReference. Then I also took the rerender= "" away from the commandLink tag. 

Started working.

Not sure why though. 

All Answers

Pramodh KumarPramodh Kumar
Could you please post your vfpage and apex class.
Abhishek BansalAbhishek Bansal
Hi,

Please be sure to rerender the form properly, only after that the page message will appear.
If you can post your VF page than it would be easy to help you out.

Thanks,
Abhishek
JeffreyStevensJeffreyStevens
Thanks.
Well - you can't do a rerender on the form - as it's an EMBEDDED Vf page. So, in the controller - you do a pageReference.  I bet that you can't use the <apex:pageMessages/> tag in this case.  It'd be good if somebody could confirm that.

Here's some of the code...
 
<apex:page standardController="Contract" extensions="Ext_ContractServices" docType="html-5.0" showheader="false" sidebar="false" cache="false">
 
	
	<script>
		function setFocus() {
			document.getElementById('{!$Component.theform.inputitem}').focus();
		}
	</script>
	
	<apex:form id="theform"> 
		<apex:pageMessages /> 
	    <div id="servicesTableDiv">
	    	<table id="servicesTable" style="border-spacing:2px;">
	    	
	    		<!-- Headers -->
	    		<th style="text-align:left;">Service</th>
	    		<th style="text-align:left;">&nbsp;</th>
	    		<th style="text-align:left;" >Fee</th>
	            
	            <!-- Services from Service Master -->
	            <apex:repeat value="{!lineItems}" var="lineItem"> 
	            	<tr> 
	            		<td>
	            			<apex:outputField value="{!lineItem.service.Service_Display_Name__c}" rendered="{!lineItem.IdNumber.id=null}" />
	            			<apex:outputLink value="/{!lineItem.IdNumber.id}" target="_blank" rendered="{!lineItem.IdNumber.Id!=null}" >
	            				<apex:outputField value="{!lineItem.Service.Service_Display_Name__c}" />
	            			</apex:outputLink>
	            		</td> 
	            		<td>
	            			<apex:inputCheckbox value="{!lineItem.IdNumber.Service_Selected__c}"  rendered="{!lineItem.allowCheckbox}" />
	            			<apex:outputField value="{!lineItem.IdNumber.Service_Selected__c}"  rendered="{!!lineItem.allowCheckbox}" />
	            		</td> 
	            		<td>
	            			<apex:inputField value="{!lineItem.IdNumber.CPA_Fee__c}" style="width:50px;" rendered="{!lineItem.allowInput}" />
	            			<apex:outputField value="{!lineItem.IdNumber.CPA_Fee__c}" style="width:50px;" rendered="{!!lineItem.allowInput}"  />
	            		</td>
	            		
	            	</tr> 
	            </apex:repeat> 
	             
	             
	        </table> 
	    </div> 
	    <div id="buttons">
	    	<apex:commandLink id="btnSave" action="{!processSaveBtn}" value="Save" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;" />
	    </div>
	</apex:form> 

</apex:page>


	/*
		PROCESS SAVE BUTTON
	*/
	public PageReference processSaveBtn() {
		system.debug('processSaveBtn...');
		errors = false;

		for(lineItem lineItem :lineItems) {
			system.debug('lineItem='+lineItem);
			
			// Validations
			if(adminUser) {
				if(lineItem.Service.Name == 'Beverage') {
					if(lineItem.IdNumberBTG100.Rate__c > 1.00) {
						errors = true;
						ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'BTG rates over 1.00 not allowed.'));
						system.debug('Error - BTG rates over 1.00 not allowed.');
					}
				}
			}


....

        PageReference pr = new PageReference('/' + contractId); 
        return pr;
}

 
Jamie 5mithJamie 5mith
This worked for me (on embedded VF page). I know it's been awhile but comes up at top of search so figure i'd post...
 
<apex:pageMessages id="message" />

<apex:commandLink reRender="message"  id="btnSave" action="{!processSaveBtn}" value="Save" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;" />

I added an id="messages" to apex:pageMessages to be able to find in the DOM and reRender="message" so that Messages gets re-rendered when the Action finishes.

So if your Class has this:
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Success!'));
        
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'test!'));

You should now get something like this:
Success!

Hope it helps someone. GLHF
 
JeffreyStevensJeffreyStevens
Thanks for the reply!  Suprising - I am still having this issue.  When I add the Id and reRender= - I don't get the PagesPage message - AND - it re-display's the entire page (standard salesforce page layout, and the embedded VF page) - all within the embedded section. 

Could you share your Consignment inventory code with me please?
JeffreyStevensJeffreyStevens
Wow - I finally got this working. 

I had my pageReference method that was referenced in the commandLink return a void instead of a pageReference. Then I also took the rerender= "" away from the commandLink tag. 

Started working.

Not sure why though. 
This was selected as the best answer