コントロールイベントの発生時に実行されるスクリプトとシンプルアクションを指定します。
<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>
各部分の説明を以下に示します。設計モードでは、コントロールまたはページにフォーカスを移動して、[イベント] タブをクリックします。 イベントはプロパティとして扱われ、[プロパティ] の下の [すべてのプロパティ] に表示されます。 ただし、[すべてのプロパティ] からイベントの作成や変更を行うことはお勧めしません。
<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>
<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>
<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>
<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>