As described in XML UI, Nexaweb Platform stores the state of the UI in an XML document. Depending upon the configuration of a Nexaweb-enabled application, Nexaweb platform may maintain a copy of the UI document on both the server and the client; however the client-side copy of the UI document always controls the UI. In addition other application data may be stored in other XML documents.
These XML documents, both the UI document and application-specific documents, can be modified declaritively through the use of XUpdate along with XPath.
XUpdate - A language for modifying XML documents declaratively. This can be used to modify any existing application documents.
Xpath - A language for addressing parts of an XML document. It is used as part of the XUpdate syntax.
This topic contains the following sections:
- XUpdate and XPath overview
- Creating an XUpdate page
- Using more XUpdate commands
- Updating an XML document using Shortcut Syntax
Note: A document as referred to in this topic means an xml document object stored in the memory unless otherwise noted.
XUpdate and XPath overview
XUpdate is an XML language for updating/modifying XML documents. The following example of an XUpdate page demonstrates how to create a button on the UI document:
...
language | html/xml |
---|---|
linenumbers | true |
- XUpdate と XPath の概要
- XUpdate ページの作成
- その他の XUpdate コマンドの使用
- ショートカット シンタックスを使用した XML ドキュメントの更新
XUpdate と XPath の概要
Code Block |
---|
<xu:modifications document="nxml" version="1.0" |
...
xmlns:xu="http://nexaweb.com/xupdate">
|
...
<xu:append select="/nxml/rootPane">
|
...
<button text="a new button"/>
|
...
</xu:append>
</xu:modifications> |
...
Nexaweb Platform 4.0
...
...
XUpdate
...
...
...
"/nxml/rootPane"
...
...
...
...
- child is an example of an axis, which specifies the tree relationship between the nodes selected by the location step and the context node,
- nxml and/or rootPane is an example of a node test, which specifies the node type and expanded-name of the nodes selected by the location step, and
- [1] is a sample of predicates, which use arbitrary expressions to further refine the set of nodes selected by the location step.
...
- child は軸の例で、場所のステップによって選択されたノードとコンテキスト ノード間のツリー関係を指定します。
- nxml と rootPane はノード テストの例で、ノードの種類と、場所のステップによって選択されたノードの拡張名を指定します。
- [1] は述語の例で、任意の式を使用して、場所のステップによって選択されたノードのセットをさらに絞り込みます。
...
You can create an XUpdate page as a static file, or as a page that server pages or servlets dynamically generate. Each XUpdate page is a well-formed XML document that contains one or more <xu:modifications> elements. If the page contains more than one <xu:modifications> elements, you must wrap those elements in a single <nxml> root node to make the page well-formed. As shown in the above example:
...
...
XUpdate ページの作成
XUpdate ページは、静的ファイル、またはサーバーページまたはサーブレットが動的に生成するページとして作成できます。各 XUpdate ページは、1 つ以上の <xu:modifications> 要素を含む、整形式の XML ドキュメントです。複数の <xu:modifications> 要素がページに含まれている場合は、1 つの <nxml> ルートノードにこれらの要素をラップして、整形式のページにする必要があります。次に、上の例で使用されているアイテムについて説明します。
- document - 操作が実行されるドキュメントの名前を指定します。
- xmlns:xu - specifies the namespace for the XUpdate instructions. It must be XUpdate 命令の名前空間を指定します。http://www.nexaweb.com/xupdate. を参照してください。
- select - specifies an XPath expression that evaluates to a set of Elements, Attribute or Text objects. XUpdate statements with the exception of <create-document> require a select statement.
Sample 1: Using a jsp page to generate XUpdate statements for use as an event handler.
...
- 要素、属性、またはテキスト オブジェクトのセットに対して評価する XPath 式を指定します。<create-document> 以外の XUpdate 文には select 文が必要です。
...
appendButton.jsp
...
ファイルの全体は次のようになります。
Code Block |
---|
...
<% String newButtonName = "myNewButton"; %>
<xu:modifications document="nxml" version="1.0" |
...
xmlns:xu="http://nexaweb.com/xupdate"> |
...
|
...
<xu:append select="/nxml/rootPane"> |
...
<button text="<%=newButtonName%>"/>
|
...
</xu:append>
</xu:modifications> |
...
サンプル 2:
...
...
Code Block |
---|
...
...
<xu:modifications document="nexaweb" version="1.0" xmlns:xu="http://nexaweb.com/xupdate"> |
...
|
...
<!-- |
...
create-document |
...
コマンドは最初のコマンドでなければなりません。 --> |
...
<xu:create-document> |
...
|
...
<nexaweb> |
...
|
...
<name>Nexaweb</name> |
...
<address>Cambridge</address> |
...
</nexaweb> |
...
|
...
</xu:create-document>
|
...
<xu:append select="/nexaweb">
|
...
<phone>617-577-8100</phone> |
...
|
...
</xu:append>
</xu:modifications> |
...
サンプル
3: MCO...
...
Code Block |
---|
...
ClientSession session = getSession(); Document document = session.getDocumentRegistry().findDocument("nexaweb"); Element element = document.getRootElement(); |
...
XUpdate を使用した初期 UI ページの作成
- 最初の XUpdate 文で、<rootPane> 要素を "/nxml" nodesノードに追加する必要があります。
- Subsequent XUpdate statements can append to 後続の XUpdate 文では、'/nxml/rootPane' node or its children
...
- ノードまたはその子に追加できます。
...
Using XUpdate commands
XUpdate can improve your productivity in developing Nexaweb-enabled applications by allowing you to use XML documents rather than writing/compiling java code. It provides many flexible commands. This section provides a sampling of XUpdate commands along with some sample code. See the XUpdate schema reference for more information on the exact syntax and details. insert-after The following example shows the use of the insert-after command. Related commands include: insert-before, instert-at.
...
language | html/xml |
---|---|
linenumbers | true |
...
また、XUpdate に依存せずに、ShortcutSyntax (以下に詳述) を使用して、初期 UI の記述を作成することもできます。ShortcutSyntax は、同じページで XUpdate と共に使用することができます。ただし、この方法を使用する場合には、ShortcutSyntax のセクションで説明する特別な注意が必要です。一般的にはこの 2 つを一緒に使用せず、可能な場合には XUpdate だけ、または ShortcutSyntax だけを使用して初期ページを宣言することをお勧めします。
XUpdate コマンドの使用
XUpdate を使用すると、Java コードを記述またはコンパイルしないで、XML ドキュメントを使用できるため、Nexaweb に対応したアプリケーションを開発する場合に生産性が向上します。また、柔軟性のあるコマンドを数多く使用できます。ここでは、XUpdate コマンドのサンプルとそのコード例を示します。正確なシンタックスと詳細については、XUpdate スキーマのリファレンスを参照してください。
insert-after
次の例は、insert-after コマンドの使用方法を示します。関連するコマンドには、insert-before、instert-at などがあります。
Code Block |
---|
<xu:insert-after select="/nxml/rootPane/window[1]/panel[1]">
<panel/>
</xu:insert-after> |
...
append
...
language | html/xml |
---|---|
linenumbers | true |
Code Block |
---|
<xu:append select="/nxml/rootPane/window[1]">
|
...
<panel/>
</xu:append> |
...
set-attribute
...
language | html/xml |
---|---|
linenumbers | true |
Code Block |
---|
<xu:set-attribute select="/nxml/rootPane/window[1]/panel[1]> |
...
|
...
<xu:attribute name="myattr" value="myvalue" />
</xu:set-attribute> |
...
replace-children
...
language | html/xml |
---|---|
linenumbers | true |
...
Code Block |
---|
<xu:replace-children select="/nxml/rootPane/window[1]">
<panel/>
<panel/>
<label text="mylabel"/>
</xu:replace-children> |
...
remove-element
...
Code Block | ||||
---|---|---|---|---|
| ||||
<xu:remove-element select="/nxml/rootPane/window[1]/panel[1]"/> |
<xu:remove-element
...
...
variable, value-of
...
language | html/xml |
---|---|
linenumbers | true |
Code Block |
---|
<xu:variable name="myvar" select="/nxml/rootPane/window[1]/panel[1]" clone="true"/>
<xu:append select="/nxml/rootPane/window[1]">
|
...
<xu:value-of name="myvar"/>
</xu:append> |
clone The following example shows the use of the clone command.
...
language | html/xml |
---|---|
linenumbers | true |
clone
<xu:clone
...
...
...
Updating an XML document using the Shortcut Syntax
The Shortcut Syntax allows you to:
- Declare the initial UI for your application without relying on XUpdate statements
- Display windows and dialogs in the <rootPane> without XUpdate
The Shortcut Syntax essentially provides a shorthand notation for using an XUpdate statement that appends to the <rootPane> tag. A page uses shortcut syntax notation if all of the following apply:
- The page has NXML tags not wrapped in XUpdate
- The page is not being included by an <include> tag
- The page is the first page of the application, or the page has a <window>, <dialog> or <messageDialog> as the root element (and is not a wrapping "nxml" tag)
The Nexaweb platform uses the following rules when it processes a page in shortcut notation:
- If the page does not have a <rootPane> tag and the UI document does not yet include a rootPane, Nexaweb creates the rootPane tag and adds it to the UI document under the root <nxml> tag. Nexaweb then adds the contents of the page to this newly created <rootPane>. This is the only scernario under which Nexaweb automatically creates <rootPane>.
- If the page does have a <rootPane> tag, Nexaweb automatically appends that tag to the root <nxml> tag of the application. However, if the UI document already has a <rootPane> this will produce two root panes and lead to an error in the application.
Nexaweb considers any page with NXML not wrapped in XUpdate or included by an <include> tag to be shortcut syntax. The following example presents some different ways of declaring the initial UI using the shortcut notation. index.nxml - the start page
...
language | html/xml |
---|---|
linenumbers | true |
...
ショートカットシンタックスの特徴は次のとおりです。
- XUpdate 文に依存することなく、アプリケーションの初期 UI を宣言する
- XUpdate を使用せずに、ウィンドウとダイアログを <rootPane> に表示する
- XUpdate でラップされていない NXML タグが対象ページにある
- 対象ページが <include> タグでインクルードされていない
- 対象ページがアプリケーションの最初のページであるか、<window>、<dialog>、または <messageDialog> をルート要素として持つ (また、ラップされる "nxml" タグではない)
- <rootPane> タグがページになく、rootPane が UI ドキュメントでインクルードされていない場合は、rootPane タグが作成され、ルートの <nxml> タグの下にある UI ドキュメントに追加されます。次に、ページのコンテンツが、新たに作成された <rootPane> に追加されます。この処理は、Nexaweb で <rootPane> が自動的に作成される場合にのみ行われます。
- <rootPane> タグがページにない場合は、このタグがアプリケーションのルートの <nxml> タグに自動的に追加されます。ただし、<rootPane> が既に UI ドキュメントにある場合は、ルート ペインが 2 つ作成されるため、アプリケーションでエラーが発生します。
Code Block |
---|
<!-- rootPane をルートの "nxml" タグに追加します。 --> <rootPane> <label text="hello world"/> <button text="click for hello world window" onCommand="window.nxml"/> </rootPane> |
...
Code Block |
---|
...
language | html/xml |
---|---|
linenumbers | true |
<-- |
...
|
...
rootPane |
...
を自動的に作成して |
...
"nxml" |
...
タグに追加し、ラベルとボタンをそのルートペインの下に配置します。 --> <nxml> |
...
|
...
<label text="hello world"/>
|
...
<button text="click for hello world window" onCommand="window.xml"/>
</nxml> |
...
または
Code Block |
---|
...
language | html/xml |
---|---|
linenumbers | true |
<!-- |
...
|
...
rootPane |
...
を自動的に作成して "nxml" |
...
タグに追加し、その下にボタンを配置します。 --> <!-- |
...
起動ページのこのシンタックスでは、要素を |
...
1 つだけ持つことができます。 --> <button text="click for hello world window" onCommand="window.xml"/> |
window.xml
Code Block |
---|
...
language | html/xml |
---|---|
linenumbers | true |
<!-- |
...
これらのタグを直接インクルードすると、起動ページ以外のページにウィンドウ、ダイアログ、メッセージダイアログのみを挿入できます。 --> <window caption="hello world window"/> |
...
または
Code Block |
---|
...
...
<nxml>
|
...
<!-- |
...
これらのタグを直接インクルードすると、起動ページ以外のページにウィンドウ、ダイアログ、メッセージダイアログのみを挿入できます。 --> <window caption="hello world window"/> </nxml> |