pagemessages not showing on vfpage when contact lastname not entering

public class contact_fetch_List_method_controller{ public contact consave{get;set;}  public contact_fetch_List_method_controller(){     consave = new contact(); }  public pageReference Save(){     if(consave.lastname == null){         ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'Last name required'));         return null;     }     else{         insert consave;         consave = new contact();     }     return null; } public list<Contact> getCont(){     List<Contact> conList = new List<Contact>();     List<Contact> con = [SELECT Id,firstname, lastname, email ,phone FROM Contact Order by LastModifiedDate DESC];      for(Contact conRecord : con){          conList.add(conRecord);      }     return conList; } } 

page code

<apex:page controller="contact_fetch_List_method_controller">   <apex:form>       <apex:pageBlock id="bgBlock">           <apex:pageMessages/>           <apex:pageBlockSection collapsible="true" columns="2" id="pgSection">               <apex:inputField value="{!consave.firstname}"/>               <apex:inputField value="{!consave.lastname}"/>               <apex:inputField value="{!consave.email}"/>               <apex:inputField value="{!consave.phone}"/>               <apex:commandButton value="Save" action="{!save}" reRender="pbTable,pgSection"/>                     </apex:pageBlockSection>            <apex:pageBlockTable id="pbTable" value="{!Cont}" var="condata">               <apex:column headerValue="FirstName" value="{!condata.firstname}"/>               <apex:column headerValue="LastName" value="{!condata.lastname}"/>               <apex:column headerValue="email" value="{!condata.email}"/>               <apex:column headerValue="Phone" value="{!condata.phone}"/>                     </apex:pageBlockTable>       </apex:pageBlock>     </apex:form> </apex:page> 

Replay

You need to rerender the pagemessage from your save button click event

  1. Define id for pageMessage. i.e. pgMsg
  2. add pgMsg to Save rendered attribute.
    <apex:page controller="contact_fetch_List_method_controller">
     <apex:form >
      <apex:pageBlock id="bgBlock">
          <apex:pageMessages id="pgMsg" />
          <apex:pageBlockSection collapsible="true" columns="2" id="pgSection">
              <apex:inputField value="{!consave.firstname}"/>
              <apex:inputField value="{!consave.lastname}"/>
              <apex:inputField value="{!consave.email}"/>
              <apex:inputField value="{!consave.phone}"/>
              <apex:commandButton value="Save" action="{!save}" reRender="pbTable,pgSection,pgMsg"/>
          </apex:pageBlockSection>
    
          <apex:pageBlockTable id="pbTable" value="{!Cont}" var="condata">
              <apex:column headerValue="FirstName" value="{!condata.firstname}"/>
              <apex:column headerValue="LastName" value="{!condata.lastname}"/>
              <apex:column headerValue="email" value="{!condata.email}"/>
              <apex:column headerValue="Phone" value="{!condata.phone}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
    </apex:form>
    
    
Category: pagemessages Time: 2016-07-30 Views: 4
Tags: pagemessages

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.855 (s). 13 q(s)