+ Start a Discussion
Anu-SFDCAnu-SFDC 

Error message not showing in page

hi

 

Here is my visualforce page:

 

 

<apex:page standardController="Contact" extensions="CreditTransactions" >
<apex:form >
 <apex:pageBlock title="Payment Methods" >
<apex:pagemessages />
<apex:pageBlockTable value="{!Results}" var="transaction" title="Payment Methods" >
<apex:inputhidden value="{!transaction.tranId}" id="transactid"/>
  <apex:column headerValue="Date Last Used" value="{!transaction.tDate2}"/> 
    <apex:column headerValue="Last 4 digits" value="{!transaction.cardnum}"/> 
    <apex:column headerValue="Expiration Date" value="{!transaction.cardexp}" id="expired"/> 
  <apex:column >
    <apex:commandButton action="{!Vterminal}" value="Virtual Terminal" reRender="hiddenblock">
               <apex:param name="para" value="{!transaction.tranId}" assignTo="{!para}"></apex:param>
               <apex:param name="expired" value="{!transaction.cardexp}" assignTo="{!expired}"></apex:param>                               </apex:commandButton>
    </apex:column>
   
</apex:pageBlockTable>
 <apex:outputPanel id="hiddenblock">
 </apex:outputPanel>
  </apex:pageBlock>
  </apex:form>
 <apex:detail />
</apex:page>
I have added <apex:pageMessages/> to the page. and here is my code when I click the button.
 public PageReference Vterminal() 
    {
            
    System.debug('expired param valueeee'+expired);
    expmonth = Integer.valueOf(expired.substring(0,2));
    expyear = Integer.valueOf(expired.substring(3,7));
    expmonthdate = Date.newInstance(expyear, expmonth,01 );
    System.debug('expired monthdate valueeee'+expmonthdate);
      p=new PageReference('/apex/VirtualTerminal?id='+para);
    if(expmonthdate>System.Today()){
      
        return p;
        }else{
   
       ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR, 'Card Expired');  
         ApexPages.addMessage(errMsg);
        }
        return null;
    }
In the debug logs error message is displaying but in the visual force page it is not showing.
Please help.

 

Best Answer chosen by Admin (Salesforce Developers) 
Sonali BhardwajSonali Bhardwaj

try

 

 

<apex:page standardController="Contact" extensions="forumTest" >
<apex:outputPanel id="hiddenblock">
<apex:pagemessages />
</apex:outputPanel>

<apex:form >
<apex:pageBlock title="Payment Methods" >

<apex:pageBlockTable value="{!Results}" var="transaction" title="Payment Methods" >
<apex:inputhidden value="{!transaction.tranId}" id="transactid"/>
<apex:column headerValue="Date Last Used" value="{!transaction.tDate2}"/>
<apex:column headerValue="Last 4 digits" value="{!transaction.cardnum}"/>
<apex:column headerValue="Expiration Date" value="{!transaction.cardexp}" id="expired"/>
<apex:column >
<apex:commandButton action="{!Vterminal}" value="Virtual Terminal" reRender="hiddenblock">
<apex:param name="para" value="{!transaction.tranId}" assignTo="{!para}"></apex:param>
<apex:param name="expired" value="{!transaction.cardexp}" assignTo="{!expired}"></apex:param> </apex:commandButton>
</apex:column>

</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
<apex:detail />
</apex:page>

 

 

 

All Answers

kiranmutturukiranmutturu

 

else{
 ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR, 'Card Expired');  
         ApexPages.addMessage(errMsg);
return null;
}
try like this.....

 

Sonali BhardwajSonali Bhardwaj

try

 

 

<apex:page standardController="Contact" extensions="forumTest" >
<apex:outputPanel id="hiddenblock">
<apex:pagemessages />
</apex:outputPanel>

<apex:form >
<apex:pageBlock title="Payment Methods" >

<apex:pageBlockTable value="{!Results}" var="transaction" title="Payment Methods" >
<apex:inputhidden value="{!transaction.tranId}" id="transactid"/>
<apex:column headerValue="Date Last Used" value="{!transaction.tDate2}"/>
<apex:column headerValue="Last 4 digits" value="{!transaction.cardnum}"/>
<apex:column headerValue="Expiration Date" value="{!transaction.cardexp}" id="expired"/>
<apex:column >
<apex:commandButton action="{!Vterminal}" value="Virtual Terminal" reRender="hiddenblock">
<apex:param name="para" value="{!transaction.tranId}" assignTo="{!para}"></apex:param>
<apex:param name="expired" value="{!transaction.cardexp}" assignTo="{!expired}"></apex:param> </apex:commandButton>
</apex:column>

</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
<apex:detail />
</apex:page>

 

 

 

This was selected as the best answer
gazazellogazazello

Thanks, Sonali! That worked for me!