apex:messages
現在のページのすべてのコンポーネントに生成されたすべてのメッセージです。<apex:message> または <apex:messages> コンポーネントがページに含まれていない場合、ほとんどの警告およびエラーメッセージはデバッグログにのみ表示されます。
このコンポーネントでは、「html-」プレフィックスを使用した HTML パススルー属性がサポートされています。パススルー属性は、生成された <ul> タグに適用されます (各メッセージはリスト項目に含まれています)。
例
1<!-- For this example to render properly, you must associate the Visualforce page
2with a valid account record in the URL.
3For example, if 001D000000IRt53 is the account ID, the resulting URL should be:
4https://Salesforce_instance/apex/myPage?id=001D000000IRt53
5See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
6
7
8<!-- Page: -->
9<apex:page controller="MyController" tabStyle="Account">
10 <apex:messages />
11 <apex:form >
12 <apex:pageBlock title="Hello {!$User.FirstName}!">
13 This is your new page for the {!name} controller. <br/>
14 You are viewing the {!account.name} account.
15
16 <p>Number of Locations: <apex:inputField value="{!account.NumberofLocations__c}"
17 id="Location_validation"/>
18 (Enter an alphabetic character here, then click save to see what happens.) </p>
19
20 <p>Number of Employees: <apex:inputField value="{!account.NumberOfEmployees}"
21 id="Employee_validation"/>
22 (Enter an alphabetic character here, then click save to see what happens.) </p>
23 <p />
24 <apex:commandButton action="{!save}" value="Save"/>
25 <p />
26 </apex:pageBlock>
27 </apex:form>
28</apex:page>
29
30/*** Controller ***/
31public class MyController {
32 Account account;
33
34 public PageReference save() {
35 try{
36 update account;
37 }
38 catch(DmlException ex){
39 ApexPages.addMessages(ex);
40 }
41 return null;
42 }
43
44 public String getName() {
45 return 'MyController';
46 }
47
48 public Account getAccount() {
49 if(account == null)
50 account = [select id, name, numberofemployees, numberoflocations__c from Account
51 where id = :ApexPages.currentPage().getParameters().get('id')];
52 return account;
53
54 }
55}属性
| 属性名 | 属性型 | 説明 | 必須かどうか | API バージョン | 通用範囲 |
|---|---|---|---|---|---|
| dir | String | 生成された HTML コンポーネントの読み取り方向。可能な値には「RTL」 (右から左) または「LTR」 (左から右) などがあります。 | 10.0 | グローバル | |
| globalOnly | Boolean | クライアント ID に関連付けられていないメッセージのみを表示するかどうかを指定する boolean 値。指定されていない場合、この値はデフォルトの false に設定されます。 | 10.0 | グローバル | |
| id | String | ページの他のコンポーネントがメッセージコンポーネントを参照できるようにする識別子。 | 10.0 | グローバル | |
| lang | String | 「en」または「en-US」など、生成された HTML 出力の基本言語。この属性についての詳細は、W3C 仕様を参照してください。 | 10.0 | グローバル | |
| layout | String | エラーメッセージの表示に使用されるレイアウトの種別。この属性に可能な値には、「list」または「table」などがあります。指定されていない場合、この値はデフォルトの「list」に設定されます。 | 10.0 | グローバル | |
| rendered | Boolean | コンポーネントをページに表示するかどうかを指定する boolean 値。指定されていない場合、この値はデフォルトの true に設定されます。 | 10.0 | グローバル | |
| style | String | メッセージの表示に使用されるスタイル。主に、インライン CSS スタイルを追加するために使用されます。 | 10.0 | グローバル | |
| styleClass | String | メッセージの表示に使用されるスタイルクラス。主に、外部 CSS スタイルシートを使用するときに適用される CSS スタイルを指定するために使用されます。 | 10.0 | グローバル | |
| title | String | ユーザがコンポーネントにマウスポインタを重ねたときにツールチップとして表示されるテキスト。 | 10.0 | グローバル |