【发布时间】:2015-03-09 12:49:36
【问题描述】:
我在 salesforce 中的自定义 employee__c 对象上定义了自定义验证规则。我使用带有自定义扩展的标准控制器 visualforce 页面向用户显示 UI 以进行数据输入。我的挑战是以易于阅读的方式向用户显示验证规则错误。这是我拥有的部分代码。
视觉力量
<apex:page standardController="Employee__c" extensions="EmployeeExtension" sidebar="false">
<apex:sectionHeader ...
<apex:form id=fr>
<apex:pageMessages id="errMsg"/>
<apex:pageBlock title="Employee Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!mySave}" value="Save" reRender="errMsg"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
....
</apex:form>
</apex:page>
Apex 控制器
public class EmployeeExtension {
....
public PageReference mySave(){
....
try{
upsert empList;
} catch (DMLException ex) {
ApexPages.addMessages(ex);
}
}
}
这显示了页面顶部的错误,这是我想要的方式,但它显示了两次。以下是它在页面顶部显示错误的方式。
- error_message_from_custom_validation_comes_here
- TriggerEmployee:第 0 行异常;第一个错误:FIELD_CUSTOM_VALIDATION_EXCEPTION,error_message_from_custom_validation_comes_here
在我的整个控制器中,我没有任何其他 DML 操作,也没有在其他任何地方使用 ApexPages.addmessage。奇怪的是,如果我删除
ApexPages.addMessages(ex);
在保持 try catch 块不变的同时,我只看到
- error_message_from_custom_validation_comes_here
我想知道为什么即使我没有从控制器发送任何内容,它也会在 vf 页面中显示页面消息。感谢您的所有回复,但我希望看到不涉及 javascript 或 jquery 的解决方案。
【问题讨论】:
标签: salesforce visualforce apex