Last active
December 17, 2015 00:11
-
-
Save tyoshikawa1106/5519349 to your computer and use it in GitHub Desktop.
エラー処理の後にポップアップメッセージ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class ErrorPopupController { | |
public Contact contact {get; set;} | |
public String errorMsg {get; set;} | |
public ErrorPopupController() { | |
this.contact = new Contact(); | |
this.errorMsg = 'bat'; | |
} | |
public PageReference doClick() { | |
if (String.isEmpty(this.contact.AccountId) == true) { | |
this.contact.AccountId.addError(this.errorMsg); | |
return null; | |
} | |
return new PageReference('/' + this.contact.AccountId); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="ErrorPopupController" title="ErrorPopupPage" showheader="true" sidebar="false" tabStyle="Contact" id="page"> | |
<apex:form id="form"> | |
<apex:pageBlock > | |
<apex:pageBlockButtons location="bottom"> | |
<apex:commandButton value=" Click!! " title=" Click!! " action="{!doClick}" | |
onComplete="return errorPopup();" reRender="form" /> | |
</apex:pageBlockButtons> | |
<apex:pageBlockSection > | |
<apex:inputField value="{!contact.AccountId}" /> | |
</apex:pageBlockSection> | |
</apex:pageBlock> | |
<script> | |
function errorPopup() { | |
alert('{!JSENCODE(errorMsg)}'); | |
return false; | |
} | |
</script> | |
</apex:form> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment