No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
入力規則とカスタムコントローラ
カスタムコントローラを使用する Visualforce ページにユーザがデータを入力し、そのデータが入力規則エラーになった場合、エラーが Visualforce ページに表示されることがあります。標準コントローラを使用するページと同様に、入力規則エラーの場所が <apex:inputField> コンポーネントに関連付けられた項目の場合、エラーはそこに表示されます。入力規則エラーの場所がページ上部に設定されている場合は、<apex:page> 内の <apex:messages> コンポーネントを使用してエラーを表示します。ただし、ページに情報を取得するには、カスタムコントローラが例外をキャッチする必要があります。
たとえば、次のページがあるとします。
次のようなカスタムコントローラを記述する必要があります。
ユーザがページを保存したときに、入力エラーがトリガされると、標準コントローラの場合と同様に、例外がキャッチされ、ページに表示されます。
1swfobject.registerObject("clippy.codeblock-0", "9");<apex:page controller="MyController" tabStyle="Account">
2 <apex:messages/>
3 <apex:form>
4 <apex:pageBlock title="Hello {!$User.FirstName}!">
5 This is your new page for the {!name} controller. <br/>
6 You are viewing the {!account.name} account.<br/><br/>
7 Change Account Name: <p></p>
8 <apex:inputField value="{!account.name}"/> <p></p>
9 Change Number of Locations:
10 <apex:inputField value="{!account.NumberofLocations__c}" id="Custom_validation"/>
11 <p>(Try entering a non-numeric character here, then hit save.)</p><br/><br/>
12 <apex:commandButton action="{!save}" value="Save New Account Name"/>
13 </apex:pageBlock>
14 </apex:form>
15</apex:page>1swfobject.registerObject("clippy.codeblock-1", "9");public class MyController {
2 Account account;
3
4 public PageReference save() {
5 try{
6 update account;
7 }
8 catch(DmlException ex){
9 ApexPages.addMessages(ex);
10 }
11 return null;
12 }
13
14 public String getName() {
15 return 'MyController';
16 }
17
18 public Account getAccount() {
19 if(account == null)
20 account = [select id, name, numberoflocations__c from Account
21 where id = :ApexPages.currentPage().getParameters().get('id')];
22 return account;
23
24 }
25}