I have a Vf page which shows a list in a apex:repeat tag. All the fields displayed are apex:inputfield. There are 2 fields
- quantity__c
- Change__c
I want to validate, if the quantity has changed then i want the change field should
be filled/mandatory. Can i do this validation at VF level?
Any other way of accomplishing this?
Thanks
Update: Here is code i am using as suggested by LaceySnr. I can see the apex message is thrown in the debug log but its not visible in Vfpage
for (integer i=0;i<List_FinalStdItems.size();i++)
{
system.debug('inside loop to check quantity is changed');
ItemSet.add(List_FinalStdItems[i].id);
system.debug('New quantity'+List_FinalStdItems[i].quantity__c +' old quantity'+MapStdItemsOldMap.get(List_FinalStdItems[i].id).quantity__c);
// system.debug('old quantity'+MapStdItemsOldMap.get(List_FinalStdItems[i].id).quantity__c);
if (MapStdItemsOldMap.get(List_FinalStdItems[i].id).quantity__c!=List_FinalStdItems[i].quantity__c)
{
system.debug('This quantity for item '+List_FinalStdItems[i].Name+ ' has changed');
if(List_FinalStdItems[i].Inventory_Change_Reason__c==null || List_FinalStdItems[i].Inventory_Change_Reason__c=='')
{
system.debug('This quantity for item '+List_FinalStdItems[i].Name+ ' has changed and Reason for change is empty');
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Reason for change not entered for changed Quantity'));
error=true;
}
}
}
01:04:55.541 (541902000)|SYSTEM_METHOD_ENTRY|[151]|ApexPages.addMessage(ApexPages.Message)
01:04:55.541 (541985000)|VF_PAGE_MESSAGE|Reason for change not entered for changed Quantity
01:04:55.542 (542008000)|SYSTEM_METHOD_EXIT|[151]|ApexPages.addMessage(ApexPages.Message)
Edit
<apex:outputpanel id="mess">
<apex:pageMessages />
</apex:outputpanel>
.
.
.
<apex:actionFunction name="save" action="{!Save}" rerender="mess"/>
You could do this through javascript directly, or you could use
<apex:actionSupport>with theonChangeevent to refresh the second field, but to be honest I think the simplest and most robust way would be to just do the validation in the controller before saving a record.Edit
I assume you have an
<apex:pageMessages/>tag in the page, make sure you’re rerendering it — i.e. if you’re not doing a whole page refresh, put the messages tag in an output panel and specify that<apex:outputPanel>in thererenderattribute for your action.Edit II
Is your action definitely returning a
nullPagereference? Otherwise what you have looks correct. Are there any page blocks etc. between your action function and the output panel? If so you may need to drill down through an id hierarchy.