eventHandler - イベントハンドラ (プロパティ)

コントロールイベントの発生時に実行されるスクリプトとシンプルアクションを指定します。

カテゴリ

イベント

構文

サーバーイベントの場合:
<xp:eventHandler event="eventname" submit="true|false"
	refreshMode="complete|partial|norefresh" refreshId="controlid"
	immediate="true|false"	execMode="partial|full">
	<xp:this.action>
	<!--For a script:-->
		<![CDATA[#{javascript:script}]]> <!--where script is the text of the script-->
	<!--For a simple action:-->
		<xp:simpleactionname attributes>content</xp:simpleactionname>
	<!--For a simple action group:-->
	</xp:this.action>
		<xp:actionGroup condition="#{javascript:script}">
			<xp:simpleactionname attributes>content</xp:simpleactionname>
			...
			<!--Can embed simple action groups-->
		</xp:actionGroup>
	<xp:this.parameters>
		<xp:parameter name="name" value="value"></xp:parameter>
		...
	</xp:this.parameters>
</xp:eventHandler>
クライアントイベントの場合:
<xp:eventHandler event="eventname" submit="false">
	<xp:this.script>
	<!--For a script:-->
		<![CDATA[script]]> <!--where script is the text of the script-->
	<!--For a simple action:-->
		<xp:simpleactionname attributes>content</xp:simpleactionname>
	<!--For a simple action group:-->
		<xp:scriptGroup conditionScript="script">
			<xp:simpleactionname attributes>content</xp:simpleactionname>
			...
			<!--Can embed simple action groups-->
		</xp:scriptGroup>
	</xp:this.script>
</xp:eventHandler>
各部分の説明を以下に示します。

使用法

イベントとは、ボタンのクリックや、編集ボックスからのフォーカスの移動など、ユーザーが 実行できるアクションのことです。 イベントハンドラは、ユーザー (設計者) が、イベントに応答して 実行するアクションです。 イベントハンドラには、サーバースクリプト、クライアントスクリプト、シンプルアクション、シンプルアクショングループがあります。

設計モードでは、コントロールまたはページにフォーカスを移動して、[イベント] タブをクリックします。 イベントはプロパティとして扱われ、[プロパティ] の下の [すべてのプロパティ] に表示されます。 ただし、[すべてのプロパティ] からイベントの作成や変更を行うことはお勧めしません。

このボタンの onclick イベントは、サーバースクリプトを使用して新規文書を作成します。
<xp:button value="Create document" id="button4">
	<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
		<xp:this.action>
			<![CDATA[#{javascript:var doc = database.createDocument();
			doc.replaceItemValue("subject", requestScope.subject);
			doc.save();
			requestScope.subject = null}]]>
		</xp:this.action>
	</xp:eventHandler>
</xp:button>
このボタンの onclick イベントは、サーバーシンプルアクションを使用して、main という名前のページを開きます。
<xp:button id="button5" value="Main page">
	<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
		<xp:this.action>
			<xp:openPage name="/main.xsp" target="newDocument"></xp:openPage>
		</xp:this.action>
	</xp:eventHandler>
</xp:button>
このボタンの onclick イベントは、新規文書を作成した後、シンプルアクショングループを使用して、main という名前のページを開きます。
<xp:button value="Create document" id="button6">
	<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
		<xp:this.action>
			<xp:actionGroup condition="#{javascript:true}">
				<xp:executeScript>
					<xp:this.script><![CDATA[#{javascript:var doc = database.createDocument();
					doc.replaceItemValue("subject", requestScope.subject);
					doc.save();
					requestScope.subject = null}]]>
					</xp:this.script>
				</xp:executeScript>
				<xp:openPage name="/main.xsp" target="newDocument"></xp:openPage>
			</xp:actionGroup>
		</xp:this.action>
	</xp:eventHandler>
</xp:button>
この編集ボックスの onblur イベントは、ユーザーテキストにスペースが含まれている場合に、メッセージを表示します。
<xp:inputText id="inputText2" value="#{requestScope.subject}">
	<xp:eventHandler event="onblur" submit="true" refreshMode="complete">
		<xp:this.script>
		<![CDATA[var e = window.document.getElementById("#{id:inputText2}");
		if(e.value.indexOf(" ") > -1) {
		window.alert("You should not have spaces in this value.")}]]>
		</xp:this.script>
	</xp:eventHandler>
</xp:inputText>