Processing math: 100%

2023年12月31日日曜日

Cozy Web/グリッド内カードのカスタマイズ

モデル駆動開発のエコシステムのキーパーツとして、Webアプリケーション・フレームワークのCozy Webを紹介しています。

前回はWebフロントエンド・フレームワークBootstrapの上でグリッド表示を行いました。

今回はグリッド内に配置されるカードをカスタマイズする方法について説明します。

HelloGrid

前回作成したリソースのグリッド表示を行うHelloGridを使用します。

HelloGridはBootstrap 5を使ってグリッド表示を行います。

Cozy Web/Webライブラリで紹介したWebライブラリ機能を使用してBootstrap 5をサポートするBootstrap5ライブラリを使用しています。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloGridを作成します。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義します。これはHelloResourceと同じ設定です。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しており、Webのリソースproductとなります。

webapp.conf

ホームディレクトリのWEB-INFディレクトリ配下にwebapp.confを配置し、Bootstrap5ライブラリの名前である「bootstrap5」をextend属性に設定します。この設定を行うことで、Bootstrap5ライブラリがWebアプリケーションのベースとして設定されます。

またthemeにbootstrap-gridを設定します。この設定により一覧表示がグリッドで表示されます。

ここまでが前回の設定です。

  1. extend: bootstrap5  
  2. theme: bootstrap-grid  

今回はグリッドの表示方法をカスタマイズします。

このためにwebapp.confに以下のようにrender.card_kind_in_gridを設定します。

render.card_kind_in_gridに"grid"を指定しているので、card__gridという名前のウィジェットがグリッド内のカードの表示に使用されます。

  1. extend: bootstrap5  
  2. theme: bootstrap-grid  
  3. render.card_kind_in_grid: "grid"  

カードの表示内容の設定

グリッド内にカードを表示するときに使用するウィジェットcard_gridを作成します。

以下のJade形式の card__grid.jade 作成し、WEB-INF/widgets配下に配置します。

  1. -@val card: ViewCard  
  2. div.card  
  3.   div.card-header  
  4.     h4.card-title  
  5.       =card.header  

ファイル名card__grid.jadeの「card」はウィジェット種別を表しこの場合はカードを示します。「__」の後のgridはウィジェットの名前を表します。

カードを記述するDIV要素以下をカードの部品として定義しています。部品内ではHTMLの要素を自由に使うことができます。

部品内のHTML要素ではBootstrapで定義されているcard, card-header, card-titleといったクラス属性を指定しているので、Bootstrapによって適切な表示が行われます。

また、カードの表示に必要な情報はViewCardオブジェクトとして渡されてくるので、ここから必要な情報を取り出してウィジェット内のHTML要素に埋め込んでいきます。ここではカードのヘッダ情報をH4要素に入れています。

グリッド表示

それでは、グリッド表示を行います。

Webブラウザ

productリソースに対するアクセスを行います。

  1. http://localhost:8080/web/HelloGrid/product  

webページの表示のために出力されたHTML文書は以下になります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html lang="ja">  
  4.   <head>  
  5.     <meta charset="utf-8"/>  
  6.     <meta content="width=device-width, initial-scale=1" name="viewport"/>  
  7.     <link crossorigin="anonymous" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"/>  
  8.     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css"/>  
  9.     <style>  
  10.       .card a {  
  11.       color: inherit;  
  12.       text-decoration: none;  
  13.       }  
  14.       .card:hover {  
  15.       background-color: #f8f9fa;  
  16.       border-color: #007bff;  
  17.       }  
  18.     </style>  
  19.   </head>  
  20.   <body>  
  21.     <script crossorigin="anonymous" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"/>  
  22.     <nav class="navbar navbar-light bg-primary">  
  23.       <div class="container-fluid">  
  24.         <span class="navbar-brand mb-0 h1">Cozy Web</span>  
  25.       </div>  
  26.     </nav>  
  27.     <nav class="navbar navbar-expand-lg navbar-light bg-light">  
  28.       <div class="container-fluid">  
  29.         <a class="navbar-brand" href="#">Navbar</a>  
  30.         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">  
  31.           <span class="navbar-toggler-icon"/>  
  32.         </button>  
  33.         <div class="collapse navbar-collapse" id="navbarNav">  
  34.           <ul class="navbar-nav">  
  35.             <li class="nav-item">  
  36.               <a class="nav-link active" aria-current="page" href="#">Home</a>  
  37.             </li>  
  38.             <li class="nav-item">  
  39.               <a class="nav-link" href="#">Features</a>  
  40.             </li>  
  41.             <li class="nav-item">  
  42.               <a class="nav-link" href="#">Pricing</a>  
  43.             </li>  
  44.             <li class="nav-item">  
  45.               <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>  
  46.             </li>  
  47.           </ul>  
  48.         </div>  
  49.       </div>  
  50.     </nav>  
  51.     <div class="container">  
  52.       <div class="row">  
  53.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  54.           <div class="card">  
  55.             <div class="card-header">  
  56.               <h4 class="card-title">  
  57.           Apple  
  58.         </h4>  
  59.             </div>  
  60.           </div>  
  61.         </div>  
  62.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  63.           <div class="card">  
  64.             <div class="card-header">  
  65.               <h4 class="card-title">  
  66.           Orange  
  67.         </h4>  
  68.             </div>  
  69.           </div>  
  70.         </div>  
  71.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  72.           <div class="card">  
  73.             <div class="card-header">  
  74.               <h4 class="card-title">  
  75.           Peach  
  76.         </h4>  
  77.             </div>  
  78.           </div>  
  79.         </div>  
  80.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  81.           <div class="card">  
  82.             <div class="card-header">  
  83.               <h4 class="card-title">  
  84.           Berry  
  85.         </h4>  
  86.             </div>  
  87.           </div>  
  88.         </div>  
  89.       </div>  
  90.     </div>  
  91.     <nav class="navbar navbar-light bg-secondary">  
  92.       <span>Cozy Web</span>  
  93.     </nav>  
  94.   </body>  
  95. </html>  

前回のグリッド表示ではカード部分は以下のHTML断片になっていました。

  1. <div class="card">  
  2.   <a href="product/1.html" class="">  
  3.     <img src="assets/img/no-image-icon.png" class="card-img-top"/>  
  4.     <div class="card-header">  
  5.       <h4 class="card-title">Apple</h4>  
  6.     </div>  
  7.   </a>  
  8. </div>  

今回は、以下のHTML断片になっており、グリッド内のカードはcard__grid.jadeで定義したものが使用されています。

  1.   <div class="card">  
  2.     <div class="card-header">  
  3.       <h4 class="card-title">  
  4.   Apple  
  5. </h4>  
  6.     </div>  
  7.   </div>  

まとめ

Cozy Webでリソースの定義をすることで、Webアプリケーションが簡単に作成できることを確認してきました。

今回はBootstrapによるレスポンシブル・デザインによるグリッド表示のカードをカスタマイズする方法について説明しました。

モデルの定義とカスタマイズしたカードの定義以外はほとんどノープログラミングでレスポンシブルなWebアプリケーションの作成ができることを確認することができました。

諸元

Cozy
0.0.16

2023年11月30日木曜日

Cozy Web/グリッド

モデル駆動開発のエコシステムのキーパーツとして、Webアプリケーション・フレームワークのCozy Webを紹介しています。

数回に渡りリソースの一覧表示の方法について見てきました。その一環でグリッドとカードによる一覧表示を取り上げます。グリッドとカードによる覧表表示はHTMLの標準機能では用意されていないので、この機能をサポートしているWebフロントエンド・フレームワークBootstrapを導入し、その上でグリッドとカードによるリソースの一覧表示を行うことにします。

HelloGrid

リソースのグリッド表示を行うHelloGridを作成します。

HelloGridはBootstrap 5を使ってグリッド表示を行います。

Cozy Web/Webライブラリで紹介したWebライブラリ機能を使用してBootstrap 5をサポートするBootstrap5ライブラリを使用します。Cozy Web/Webライブラリで紹介したWebライブラリ機能を使用してBootstrap 5をサポートするBootstrap5ライブラリを使用します。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloGridを作成します。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義します。これは前回まで使用していたHelloResourceと同じ設定です。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しており、Webのリソースproductとなります。

webapp.conf

ホームディレクトリのWEB-INFディレクトリ配下にwebapp.confを配置し、Bootstrap5ライブラリの名前である「bootstrap5」をextend属性に設定します。この設定を行うことで、Bootstrap5ライブラリがWebアプリケーションのベースとして設定されます。

  1. extend: bootstrap5  

一覧表示

CozyのWebライブラリBootstrap5はデフォルトでは、tableタグを使った一覧表示を行います。

Webブラウザ

前回と同様にproductリソースに対するアクセスを行います。

  1. http://localhost:8080/web/HelloGrid/product  

Cozy Web/Webライブラリで説明したとおり、WebライブラリBootstrapでは、ナビゲーションバーやヘッダー、フッターを使用した画面レイアウトになります。Cozy Web/Webライブラリで説明したとおり、WebライブラリBootstrapでは、ナビゲーションバーやヘッダー、フッターを使用した画面レイアウトになります。

画面内のコンテンツの部分にBootstrapによって綺麗にレイアウトされた表が表示されました。

HTML

webページの表示のために出力されたHTMLは以下になります。

tableタグにはBootstrap用のclass属性が設定されているため、Bootstrap標準の綺麗な表が出力されます。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html lang="ja">  
  4.   <head>  
  5.     <meta charset="utf-8"/>  
  6.     <meta content="width=device-width, initial-scale=1" name="viewport"/>  
  7.     <link crossorigin="anonymous" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"/>  
  8.     <style>  
  9.       .card a {  
  10.       color: inherit;  
  11.       text-decoration: none;  
  12.       }  
  13.       .card:hover {  
  14.       background-color: #f8f9fa;  
  15.       border-color: #007bff;  
  16.       }  
  17.     </style>  
  18.   </head>  
  19.   <body>  
  20.     <script crossorigin="anonymous" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"/>  
  21.     <nav class="navbar navbar-light bg-primary">  
  22.       <div class="container-fluid">  
  23.         <span class="navbar-brand mb-0 h1">Cozy Web</span>  
  24.       </div>  
  25.     </nav>  
  26.     <nav class="navbar navbar-expand-lg navbar-light bg-light">  
  27.       <div class="container-fluid">  
  28.         <a class="navbar-brand" href="#">Navbar</a>  
  29.         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">  
  30.           <span class="navbar-toggler-icon"/>  
  31.         </button>  
  32.         <div class="collapse navbar-collapse" id="navbarNav">  
  33.           <ul class="navbar-nav">  
  34.             <li class="nav-item">  
  35.               <a class="nav-link active" aria-current="page" href="#">Home</a>  
  36.             </li>  
  37.             <li class="nav-item">  
  38.               <a class="nav-link" href="#">Features</a>  
  39.             </li>  
  40.             <li class="nav-item">  
  41.               <a class="nav-link" href="#">Pricing</a>  
  42.             </li>  
  43.             <li class="nav-item">  
  44.               <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>  
  45.             </li>  
  46.           </ul>  
  47.         </div>  
  48.       </div>  
  49.     </nav>  
  50.     <div class="table-responsive">  
  51.       <table class="table">  
  52.         <caption class="">product</caption>  
  53.         <thead class="">  
  54.           <tr class="">  
  55.             <th class="" scope="col">Id</th>  
  56.             <th class="" scope="col">Name</th>  
  57.             <th class="" scope="col">Price</th>  
  58.           </tr>  
  59.         </thead>  
  60.         <tbody class="">  
  61.           <tr data-href="product/1.html">  
  62.             <td class="">1</td>  
  63.             <td class="">Apple</td>  
  64.             <td class="">300</td>  
  65.           </tr>  
  66.           <tr data-href="product/2.html">  
  67.             <td class="">2</td>  
  68.             <td class="">Orange</td>  
  69.             <td class="">350</td>  
  70.           </tr>  
  71.           <tr data-href="product/3.html">  
  72.             <td class="">3</td>  
  73.             <td class="">Peach</td>  
  74.             <td class="">400</td>  
  75.           </tr>  
  76.           <tr data-href="product/4.html">  
  77.             <td class="">4</td>  
  78.             <td class="">Berry</td>  
  79.             <td class="">450</td>  
  80.           </tr>  
  81.         </tbody>  
  82.       </table>  
  83.     </div>  
  84.     <nav class="navbar navbar-light bg-secondary">  
  85.       <span>Cozy Web</span>  
  86.     </nav>  
  87.   </body>  
  88. </html>  

グリッド

それでは、グリッド表示を行います。

webapp.conf

Bootstrapアプリケーションの一覧表示のデフォルト設定をwebapp.confに設定することができます。

webapp.confのthemeにテーマbootstrap-gridを設定します。

テーマbootstrap-gridは一覧表示のデフォルト設定をグリッドにしたテーマです。

  1. extend: bootstrap5  
  2. theme: bootstrap-grid  

Webブラウザ

productリソースに対するアクセスを行います。

  1. http://localhost:8080/web/HelloGrid/product  

表示結果は以下になります。

無事Bootstrapのグリッド表示になります。グリッド内にはリソースの内容を記述するカードが表示されています。

デフォルトでは、カード内にはリソースの内容を表す画像どリソースの名前が表示されます。productでは画像の情報は持っていないので、画像なしを示す画像が表示されています。

Bootstrapのグリッドは画面サイズを変えても適切にレイアウトが行われます。先ほどのWebページの横幅を小さく縮めたWebページが以下になります。

HTML

webページの表示のために出力されたHTMLは以下になります。

グリッド内のカードはclass属性にcardが設定されたdevタグで記述されています。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html lang="ja">  
  4.   <head>  
  5.     <meta charset="utf-8"/>  
  6.     <meta content="width=device-width, initial-scale=1" name="viewport"/>  
  7.     <link crossorigin="anonymous" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"/>  
  8.     <style>  
  9.       .card a {  
  10.       color: inherit;  
  11.       text-decoration: none;  
  12.       }  
  13.       .card:hover {  
  14.       background-color: #f8f9fa;  
  15.       border-color: #007bff;  
  16.       }  
  17.     </style>  
  18.   </head>  
  19.   <body>  
  20.     <script crossorigin="anonymous" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"/>  
  21.     <nav class="navbar navbar-light bg-primary">  
  22.       <div class="container-fluid">  
  23.         <span class="navbar-brand mb-0 h1">Cozy Web</span>  
  24.       </div>  
  25.     </nav>  
  26.     <nav class="navbar navbar-expand-lg navbar-light bg-light">  
  27.       <div class="container-fluid">  
  28.         <a class="navbar-brand" href="#">Navbar</a>  
  29.         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">  
  30.           <span class="navbar-toggler-icon"/>  
  31.         </button>  
  32.         <div class="collapse navbar-collapse" id="navbarNav">  
  33.           <ul class="navbar-nav">  
  34.             <li class="nav-item">  
  35.               <a class="nav-link active" aria-current="page" href="#">Home</a>  
  36.             </li>  
  37.             <li class="nav-item">  
  38.               <a class="nav-link" href="#">Features</a>  
  39.             </li>  
  40.             <li class="nav-item">  
  41.               <a class="nav-link" href="#">Pricing</a>  
  42.             </li>  
  43.             <li class="nav-item">  
  44.               <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>  
  45.             </li>  
  46.           </ul>  
  47.         </div>  
  48.       </div>  
  49.     </nav>  
  50.     <div class="container">  
  51.       <div class="row">  
  52.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  53.           <div class="card">  
  54.             <a href="product/1.html" class="">  
  55.               <img src="assets/img/no-image-icon.png" class="card-img-top"/>  
  56.               <div class="card-header">  
  57.                 <h4 class="card-title">Apple</h4>  
  58.               </div>  
  59.             </a>  
  60.           </div>  
  61.         </div>  
  62.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  63.           <div class="card">  
  64.             <a href="product/2.html" class="">  
  65.               <img src="assets/img/no-image-icon.png" class="card-img-top"/>  
  66.               <div class="card-header">  
  67.                 <h4 class="card-title">Orange</h4>  
  68.               </div>  
  69.             </a>  
  70.           </div>  
  71.         </div>  
  72.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  73.           <div class="card">  
  74.             <a href="product/3.html" class="">  
  75.               <img src="assets/img/no-image-icon.png" class="card-img-top"/>  
  76.               <div class="card-header">  
  77.                 <h4 class="card-title">Peach</h4>  
  78.               </div>  
  79.             </a>  
  80.           </div>  
  81.         </div>  
  82.         <div class="col-12 col-sm-6 col-md-3 col-lg-2 col-xl-1">  
  83.           <div class="card">  
  84.             <a href="product/4.html" class="">  
  85.               <img src="assets/img/no-image-icon.png" class="card-img-top"/>  
  86.               <div class="card-header">  
  87.                 <h4 class="card-title">Berry</h4>  
  88.               </div>  
  89.             </a>  
  90.           </div>  
  91.         </div>  
  92.       </div>  
  93.     </div>  
  94.     <nav class="navbar navbar-light bg-secondary">  
  95.       <span>Cozy Web</span>  
  96.     </nav>  
  97.   </body>  
  98. </html>  

まとめ

前回まではCozy Webでリソースの定義をすることで、Webアプリケーションが簡単に作成できることを説明しました。

今回は画面の表示方法のカスタマイズとして、グリッド表示を取り上げました。

テーマの設定のみで一覧表示をtableタグによる表からBootstrapならではのグリッド表示にすることができました。また、グリッド表示はBootstrapの機能により画面サイズに従って適切なレイアウトが行われることが確認できました。

モデルの定義以外はほとんどノープログラミングでWebアプリケーションの作成ができることが分かりました。

次回はグリッド表示のカスタマイズ方法について取り上げる予定です。

諸元

Cozy
0.0.15

2023年10月31日火曜日

Cozy Web上でエンティティのモデル定義によって設定されたリソースの一覧アクセスをノンプログラミングで行う方法についてみています。

前回はリソースの一覧表示の機能機能について説明します。

今回はページング機能について説明します。

HelloResource

リソースの作成・更新処理の題材としてHelloResourceを定義しました。

このHelloResourceを使用して、リソースの一覧表示の方法についてみています。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloResourceが作成されています。これをベースに開発を進めます。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義されています。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しています。

これがWebのリソースproductとなります。

トップページ

トップページとしてホームディレクトリに以下のindex.htmlを配備しています。これは前回と同様です。

  1. <html>  
  2.     <head>  
  3.     <title>HelloResource</title>  
  4.     </head>  
  5.     <body>  
  6.     <ul>  
  7.         <li><a href="product">List</a></li>  
  8.         <li><a href="product/_create_">Create</a></li>  
  9.         <li><a href="product/_update_">Update</a></li>  
  10.         <li><a href="product/_delete_">Delete</a></li>  
  11.     </ul>  
  12.     </body>  
  13. </html>  

一覧表示

まず、前回紹介したパラメタなしの場合です。

以下のようにリソース名を指定してアクセスします。

  1. $ curl http://localhost:8080/web/HelloResource/product  

その結果、以下のページが表示されます。(この結果はxmllintで整形しています。他のHTML出力も同様です。)

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.     <title>product</title>  
  11.   </head>  
  12.   <body>  
  13.     <div>  
  14.       <table class="">  
  15.         <caption class="">product</caption>  
  16.         <thead class="">  
  17.           <tr class="">  
  18.             <th scope="col" class="">Id</th>  
  19.             <th scope="col" class="">Name</th>  
  20.             <th scope="col" class="">Price</th>  
  21.           </tr>  
  22.         </thead>  
  23.         <tbody class="">  
  24.           <tr data-href="product/1.html">  
  25.             <td class="">1</td>  
  26.             <td class="">Apple</td>  
  27.             <td class="">300</td>  
  28.           </tr>  
  29.         </tbody>  
  30.       </table>  
  31.       <table>  
  32.         <tr>  
  33.           <td>Prev</td>  
  34.           <td>  
  35.             <a href="#?query.offset=0&amp;query.page.size=1">1</a>  
  36.           </td>  
  37.           <td>  
  38.             <a href="#?query.offset=1&amp;query.page.size=1">2</a>  
  39.           </td>  
  40.           <td>  
  41.             <a href="#?query.offset=2&amp;query.page.size=1">3</a>  
  42.           </td>  
  43.           <td>  
  44.             <a href="#?query.offset=3&amp;query.page.size=1">4</a>  
  45.           </td>  
  46.           <td>Next</td>  
  47.         </tr>  
  48.       </table>  
  49.     </div>  
  50.   </body>  
  51. </html>  

ページング

次はページング機能を使用してみます。

ページング機能を使用する場合、query.page.sizeパラメタで1ページ数あたりの行数を指定します。

以下のようにリソース名のページを指定して、queyr.page.sizeに「1」を指定して実行してみます。

  1. $ curl "http://localhost:8080/web/HelloResource/product?query.page.size=1"  

この結果、以下のページが表示されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.     <title>product</title>  
  11.   </head>  
  12.   <body>  
  13.     <div>  
  14.       <table class="">  
  15.         <caption class="">product</caption>  
  16.         <thead class="">  
  17.           <tr class="">  
  18.             <th scope="col" class="">Id</th>  
  19.             <th scope="col" class="">Name</th>  
  20.             <th scope="col" class="">Price</th>  
  21.           </tr>  
  22.         </thead>  
  23.         <tbody class="">  
  24.           <tr data-href="product/1.html">  
  25.             <td class="">1</td>  
  26.             <td class="">Apple</td>  
  27.             <td class="">300</td>  
  28.           </tr>  
  29.         </tbody>  
  30.       </table>  
  31.       <table>  
  32.         <tr>  
  33.           <td>Prev</td>  
  34.           <td>  
  35.             <a href="#?query.offset=0&amp;query.page.size=1">1</a>  
  36.           </td>  
  37.           <td>  
  38.             <a href="#?query.offset=1&amp;query.page.size=1">2</a>  
  39.           </td>  
  40.           <td>  
  41.             <a href="#?query.offset=2&amp;query.page.size=1">3</a>  
  42.           </td>  
  43.           <td>  
  44.             <a href="#?query.offset=3&amp;query.page.size=1">4</a>  
  45.           </td>  
  46.           <td>Next</td>  
  47.         </tr>  
  48.       </table>  
  49.     </div>  
  50.   </body>  
  51. </html>  

query.page.sizeに「1」を指定しているので1ページあたり1行表示のページングが行われています。データ表示のテーブルの下部にページング移動用のテーブルが表示されています。全レコード数が4なので、4ページの構成となっています。

まとめ

今回はリソースの一覧表示のページングについて説明しました。

次回はカスタム画面などの機能について説明する予定です。

諸元

Cozy
0.0.15

2023年9月30日土曜日

Cozy Web/一覧表示

Cozy Web上でエンティティのモデル定義によって設定されたリソースの一覧アクセスをノンプログラミングで行う方法についてみていきます。

今回はリソースの一覧表示の機能機能について説明します。

HelloResource

リソースの作成・更新処理の題材としてHelloResourceを定義しました。

今回からこのHelloResourceを使用して、リソースの一覧表示の方法についてみていきます。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloResourceが作成されています。これをベースに開発を進めます。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義されています。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しています。

これがWebのリソースproductとなります。

トップページ

トップページとしてホームディレクトリに以下のindex.htmlを配備しています。

  1. <html>  
  2.     <head>  
  3.     <title>HelloResource</title>  
  4.     </head>  
  5.     <body>  
  6.     <ul>  
  7.         <li><a href="product">List</a></li>  
  8.         <li><a href="product/_create_">Create</a></li>  
  9.         <li><a href="product/_update_">Update</a></li>  
  10.         <li><a href="product/_delete_">Delete</a></li>  
  11.     </ul>  
  12.     </body>  
  13. </html>  

リソース一覧のシナリオ

リソースの作成・更新では入力フォームの入力から始まるシナリオによって、複数の画面によって作成・更新処理を実行しました。

一方、リソース一覧では一覧表示したいリソースの名前と表示方法を指定するパラメタを渡すことで、すぐに表示結果を得ることができます。

実行

それではリソース一覧の表示を行ってみましょう。

一覧表示

まず、パラメタなしの場合です。

以下のようにリソース名を指定してアクセスします。

  1. $ curl http://localhost:8080/web/HelloResource/product  

その結果、以下のページが表示されました。(この結果はxmllintで整形しています。他のHTML出力も同様です。)

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.     <title>product</title>  
  11.   </head>  
  12.   <body>  
  13.     <table class="">  
  14.       <caption class="">product</caption>  
  15.       <thead class="">  
  16.         <tr class="">  
  17.           <th scope="col" class="">Id</th>  
  18.           <th scope="col" class="">Name</th>  
  19.           <th scope="col" class="">Price</th>  
  20.         </tr>  
  21.       </thead>  
  22.       <tbody class="">  
  23.         <tr data-href="product/1.html">  
  24.           <td class="">1</td>  
  25.           <td class="">Apple</td>  
  26.           <td class="">300</td>  
  27.         </tr>  
  28.         <tr data-href="product/2.html">  
  29.           <td class="">2</td>  
  30.           <td class="">Orange</td>  
  31.           <td class="">350</td>  
  32.         </tr>  
  33.         <tr data-href="product/3.html">  
  34.           <td class="">3</td>  
  35.           <td class="">Peach</td>  
  36.           <td class="">400</td>  
  37.         </tr>  
  38.       </tbody>  
  39.     </table>  
  40.   </body>  
  41. </html>  

範囲指定

query.offsetパラメタで開始オフセットを、query.limitパラメタで表示の範囲を指定することができます。

以下の例ではquery.offsetに1、query.limitに1を指定しているので、2番目のレコードから1レコードを表示します。

  1. $ curl "http://localhost:8080/web/HelloResource/product?query.offset=1&query.limit=1"  

実行の結果、以下のようにレコード数1の表が表示されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.     <title>product</title>  
  11.   </head>  
  12.   <body>  
  13.     <table class="">  
  14.       <caption class="">product</caption>  
  15.       <thead class="">  
  16.         <tr class="">  
  17.           <th scope="col" class="">Id</th>  
  18.           <th scope="col" class="">Name</th>  
  19.           <th scope="col" class="">Price</th>  
  20.         </tr>  
  21.       </thead>  
  22.       <tbody class="">  
  23.         <tr data-href="product/2.html">  
  24.           <td class="">2</td>  
  25.           <td class="">Orange</td>  
  26.           <td class="">350</td>  
  27.         </tr>  
  28.       </tbody>  
  29.     </table>  
  30.   </body>  
  31. </html>  

カラム指定

query.columnsパラメタで表示するカラムを指定することができます。

以下の例ではquery.columnsに「name,price」を指定しているのでnameとpriceの2カラムの表を表示します。

  1. $ curl "http://localhost:8080/web/HelloResource/product?query.columns=name,price"  

実行の結果、以下のように2カラムの表が表示されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.     <title>product</title>  
  11.   </head>  
  12.   <body>  
  13.     <table class="">  
  14.       <caption class="">product</caption>  
  15.       <thead class="">  
  16.         <tr class="">  
  17.           <th scope="col" class="">Name</th>  
  18.           <th scope="col" class="">Price</th>  
  19.         </tr>  
  20.       </thead>  
  21.       <tbody class="">  
  22.         <tr data-href="product/1.html">  
  23.           <td class="">Apple</td>  
  24.           <td class="">300</td>  
  25.         </tr>  
  26.         <tr data-href="product/2.html">  
  27.           <td class="">Orange</td>  
  28.           <td class="">350</td>  
  29.         </tr>  
  30.         <tr data-href="product/3.html">  
  31.           <td class="">Peach</td>  
  32.           <td class="">400</td>  
  33.         </tr>  
  34.       </tbody>  
  35.     </table>  
  36.   </body>  
  37. </html>  

まとめ

今回はリソースの一覧表示の基本機能について説明しました。

次回はページングやカスタム画面などの機能について説明する予定です。

諸元

Cozy
0.0.14

2023年8月31日木曜日

Cozy Web/エンティティ削除

Cozy Web上でエンティティのモデル定義をすることで、Web上でのリソースアクセスをノンプログラミングで行う方法についてみています。

ここまでエンティティの作成、更新の方法について説明しました。

モデルを定義するだけで、エンティティの作成・更新画面が自動的に提供されることを確認しました。それぞれの画面ではエンティティ成・更新を入力、確認、表示の3画面を使って行うことができました。また、エンティティの作成・更新画面のカスタム画面を定義することも可能になっています。

今回はエンティティの削除について説明します。

HelloResource

ここまで作成したHelloResourceは、モデルの定義が行われており、エンティティの作成と更新を行うことができます。エンティティの作成では、アプリケーションが定義したビューを使用するようになっています。

今回は削除処理のアプリケーション定義ビューを追加します。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloResourceが作成されています。これをベースに開発を進めます。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義されています。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しています。

これがWebのリソースproductとなります。

トップページ

トップページとしてホームディレクトリに以下のindex.htmlを配備しています。

  1. <html>  
  2.     <head>  
  3.     <title>HelloResource</title>  
  4.     </head>  
  5.     <body>  
  6.     <ul>  
  7.         <li><a href="product">List</a></li>  
  8.         <li><a href="product/_create_">Create</a></li>  
  9.         <li><a href="product/_update_">Update</a></li>  
  10.         <li><a href="product/_delete_">Delete</a></li>  
  11.     </ul>  
  12.     </body>  
  13. </html>  

エンティティ操作シナリオ

エンティティのモデル定義を行うとエンティティ作成シナリオ、更新シナリオに加えて削除シナリオが自動的に作成されます。

エンティティの削除には以下の2種類があります。

  • 更新するエンティティのIDを削除画面から入力
  • 更新するエンティティのIDを削除開始時に指定

実行

それではエンティティの削除を実行してみましょう。まず削除するIDを削除画面から入力する方式です。

エンティティ削除ページ

以下のようにリソース名の後ろに「_delete_」をつけてアクセスします。

  1. $ curl http://localhost:8080/web/HelloResource/product/_delete_  

次のようにエンティティ削除に必要なIDを指定するためのFORMの画面が表示されました。

ビューの定義はしていないので、Cozy Webのデフォルト入力画面が表示されます。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.   </head>  
  11.   <body>  
  12.     <form action="" method="POST">  
  13.       <table class="">  
  14.         <tbody>  
  15.           <tr class="">  
  16.             <th scope="row" class="">Id</th>  
  17.             <td class="">  
  18.               <input type="text" name="id" value=""/>  
  19.             </td>  
  20.           </tr>  
  21.         </tbody>  
  22.       </table>  
  23.       <table>  
  24.         <tr>  
  25.           <td>  
  26.             <input type="submit" name="$submit" value="Input"/>  
  27.           </td>  
  28.           <td>  
  29.             <input type="submit" name="$submit" value="Cancel"/>  
  30.           </td>  
  31.         </tr>  
  32.       </table>  
  33.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;input&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{}}"/>  
  34.     </form>  
  35.   </body>  
  36. </html>  

このページでは以下のボタンが表示されています。

Input
エンティティ削除
Cancel
キャンセル Inputボタンを押下するとエンティティ削除のための次の画面に遷移します。

Cancelボタンを押下するとトップページに戻ります。

削除確認ページ

エンティティ削除ページでInputボタンが押されたので、削除確認画面が表示されます。

  1. <html>  
  2.   <head>  
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  4.     <meta name="keywords" content="TBD"/>  
  5.     <meta name="description" content="TBD"/>  
  6.     <meta name="robots" content="noindex,nofollow"/>  
  7.     <meta name="author" content="TBD"/>  
  8.   </head>  
  9.   <body>  
  10.     <form action="" method="POST">  
  11.       <table class="">  
  12.         <tbody>  
  13.           <tr class="">  
  14.             <th scope="row" class="">Id</th>  
  15.             <td class="">1</td>  
  16.           </tr>  
  17.           <tr class="">  
  18.             <th scope="row" class="">Name</th>  
  19.             <td class="">Apple</td>  
  20.           </tr>  
  21.           <tr class="">  
  22.             <th scope="row" class="">Price</th>  
  23.             <td class="">300</td>  
  24.           </tr>  
  25.         </tbody>  
  26.       </table>  
  27.       <input type="hidden" name="id" value="5"/>  
  28.       <input type="hidden" name="name" value="Banana"/>  
  29.       <input type="hidden" name="price" value="250"/>  
  30.       <table>  
  31.         <tr>  
  32.           <td>  
  33.             <input type="submit" name="$submit" value="Ok"/>  
  34.           </td>  
  35.           <td>  
  36.             <input type="submit" name="$submit" value="Back"/>  
  37.           </td>  
  38.           <td>  
  39.             <input type="submit" name="$submit" value="Cancel"/>  
  40.           </td>  
  41.         </tr>  
  42.       </table>  
  43.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;confirm&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Banana&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;input\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{}}&quot;,&quot;price&quot;:&quot;250&quot;,&quot;id&quot;:&quot;5&quot;,&quot;submit&quot;:&quot;Input&quot;}}"/>  
  44.     </form>  
  45.   </body>  
  46. </html>  

画面に削除予定のエンティティのデータが表示されます。この結果を確認した上で、以下のいずれかのボタンを押下します。

OK
確認OK
Back
入力画面にモデル
Cancel
キャンセル

Okボタンを押下するとエンティティの削除を行い、その結果を表示する画面に遷移します。

結果ページ

削除確認画面でOKボタンが押されたので、エンティティの削除が行われ、削除されたエンティティの情報表示ページに移ります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.   </head>  
  11.   <body>  
  12.     <form action="" method="POST">  
  13.       <table class="">  
  14.         <tbody>  
  15.           <tr class="">  
  16.             <th scope="row" class="">Id</th>  
  17.             <td class="">1</td>  
  18.           </tr>  
  19.           <tr class="">  
  20.             <th scope="row" class="">Name</th>  
  21.             <td class="">Apple</td>  
  22.           </tr>  
  23.           <tr class="">  
  24.             <th scope="row" class="">Price</th>  
  25.             <td class="">100</td>  
  26.           </tr>  
  27.         </tbody>  
  28.       </table>  
  29.       <input type="hidden" name="id" value="1"/>  
  30.       <input type="hidden" name="name" value="Apple"/>  
  31.       <input type="hidden" name="price" value="100"/>  
  32.       <table>  
  33.         <tr>  
  34.           <td>  
  35.             <input type="submit" name="$submit" value="Ok"/>  
  36.           </td>  
  37.         </tr>  
  38.       </table>  
  39.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;show&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Banana&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;confirm\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{\&quot;name\&quot;:\&quot;a\&quot;,\&quot;$scenario\&quot;:\&quot;{\\\&quot;name\\\&quot;:\\\&quot;update-entity\\\&quot;,\\\&quot;state\\\&quot;:\\\&quot;input\\\&quot;,\\\&quot;entity\\\&quot;:\\\&quot;product\\\&quot;,\\\&quot;schema\\\&quot;:{\\\&quot;columns\\\&quot;:[{\\\&quot;name\\\&quot;:\\\&quot;id\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;token\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;},{\\\&quot;name\\\&quot;:\\\&quot;name\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;string\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;},{\\\&quot;name\\\&quot;:\\\&quot;price\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;int\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}]},\\\&quot;data\\\&quot;:{}}\&quot;,\&quot;price\&quot;:\&quot;10\&quot;,\&quot;id\&quot;:\&quot;5\&quot;,\&quot;$submit\&quot;:\&quot;Input\&quot;}}&quot;,&quot;price&quot;:&quot;250&quot;,&quot;id&quot;:&quot;5&quot;,&quot;submit&quot;:&quot;Ok&quot;}}"/>  
  40.     </form>  
  41.   </body>  
  42. </html>  

削除したエンティティのデータが表示されます。この結果を確認した後に、OKボタンを押下するとトップページに戻ります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>HelloResource</title>  
  6.   </head>  
  7.   <body>  
  8.     <ul>  
  9.       <li>  
  10.         <a href="product">List</a>  
  11.       </li>  
  12.       <li>  
  13.         <a href="product/_create_">Create</a>  
  14.       </li>  
  15.       <li>  
  16.         <a href="product/_update_">Update</a>  
  17.       </li>  
  18.       <li>  
  19.         <a href="product/_delete_">Delete</a>  
  20.       </li>  
  21.     </ul>  
  22.   </body>  
  23. </html>  

確認

確認のためにリソースproductの一覧を表示してみましょう。

  1. $ curl http://localhost:8080/web/HelloResource/product  

以下のようにオブジェクトID 1のAppleが削除されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>Product List</title>  
  6.   </head>  
  7.   <body>  
  8.     <table class="">  
  9.       <caption class="">product</caption>  
  10.       <thead class="">  
  11.         <tr class="">  
  12.           <th scope="col" class="">Id</th>  
  13.           <th scope="col" class="">Name</th>  
  14.           <th scope="col" class="">Price</th>  
  15.         </tr>  
  16.       </thead>  
  17.       <tbody class="">  
  18.         <tr data-href="product/2.html">  
  19.           <td class="">2</td>  
  20.           <td class="">Orange</td>  
  21.           <td class="">350</td>  
  22.         </tr>  
  23.         <tr data-href="product/3.html">  
  24.           <td class="">3</td>  
  25.           <td class="">Peach</td>  
  26.           <td class="">400</td>  
  27.         </tr>  
  28.         <tr data-href="product/4.html">  
  29.           <td class="">4</td>  
  30.           <td class="">Banana</td>  
  31.           <td class="">250</td>  
  32.         </tr>  
  33.       </tbody>  
  34.     </table>  
  35.   </body>  
  36. </html>  

実行/ID指定

続けてIDを指定したエンティティの更新を実行してみましょう。

エンティティ更新ページ

IDを指定してリエンティティの更新を行ってみます。IDが1の場合は以下になります。

  1. $ curl http://localhost:8080/web/HelloResource/product/1/_delete_  

削除確認ページ

エンティティ削除ページでInputボタンが押されたので、削除確認画面が表示されます。

  1. <html>  
  2.   <head>  
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  4.     <meta name="keywords" content="TBD"/>  
  5.     <meta name="description" content="TBD"/>  
  6.     <meta name="robots" content="noindex,nofollow"/>  
  7.     <meta name="author" content="TBD"/>  
  8.   </head>  
  9.   <body>  
  10.     <form action="" method="POST">  
  11.       <table class="">  
  12.         <tbody>  
  13.           <tr class="">  
  14.             <th scope="row" class="">Id</th>  
  15.             <td class="">1</td>  
  16.           </tr>  
  17.           <tr class="">  
  18.             <th scope="row" class="">Name</th>  
  19.             <td class="">Apple</td>  
  20.           </tr>  
  21.           <tr class="">  
  22.             <th scope="row" class="">Price</th>  
  23.             <td class="">300</td>  
  24.           </tr>  
  25.         </tbody>  
  26.       </table>  
  27.       <input type="hidden" name="id" value="5"/>  
  28.       <input type="hidden" name="name" value="Banana"/>  
  29.       <input type="hidden" name="price" value="250"/>  
  30.       <table>  
  31.         <tr>  
  32.           <td>  
  33.             <input type="submit" name="$submit" value="Ok"/>  
  34.           </td>  
  35.           <td>  
  36.             <input type="submit" name="$submit" value="Back"/>  
  37.           </td>  
  38.           <td>  
  39.             <input type="submit" name="$submit" value="Cancel"/>  
  40.           </td>  
  41.         </tr>  
  42.       </table>  
  43.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;confirm&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Banana&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;input\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{}}&quot;,&quot;price&quot;:&quot;250&quot;,&quot;id&quot;:&quot;5&quot;,&quot;submit&quot;:&quot;Input&quot;}}"/>  
  44.     </form>  
  45.   </body>  
  46. </html>  

画面に削除予定のエンティティのデータが表示されます。この結果を確認した上で、以下のいずれかのボタンを押下します。

OK
確認OK
Back
入力画面にモデル
Cancel
キャンセル

Okボタンを押下するとエンティティの削除を行い、その結果を表示する画面に遷移します。

結果ページ

削除確認画面でOKボタンが押されたので、エンティティの削除が行われ、削除されたエンティティの情報表示ページに移ります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.   </head>  
  11.   <body>  
  12.     <form action="" method="POST">  
  13.       <table class="">  
  14.         <tbody>  
  15.           <tr class="">  
  16.             <th scope="row" class="">Id</th>  
  17.             <td class="">1</td>  
  18.           </tr>  
  19.           <tr class="">  
  20.             <th scope="row" class="">Name</th>  
  21.             <td class="">Apple</td>  
  22.           </tr>  
  23.           <tr class="">  
  24.             <th scope="row" class="">Price</th>  
  25.             <td class="">100</td>  
  26.           </tr>  
  27.         </tbody>  
  28.       </table>  
  29.       <input type="hidden" name="id" value="1"/>  
  30.       <input type="hidden" name="name" value="Apple"/>  
  31.       <input type="hidden" name="price" value="100"/>  
  32.       <table>  
  33.         <tr>  
  34.           <td>  
  35.             <input type="submit" name="$submit" value="Ok"/>  
  36.           </td>  
  37.         </tr>  
  38.       </table>  
  39.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;show&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Banana&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;confirm\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{\&quot;name\&quot;:\&quot;a\&quot;,\&quot;$scenario\&quot;:\&quot;{\\\&quot;name\\\&quot;:\\\&quot;update-entity\\\&quot;,\\\&quot;state\\\&quot;:\\\&quot;input\\\&quot;,\\\&quot;entity\\\&quot;:\\\&quot;product\\\&quot;,\\\&quot;schema\\\&quot;:{\\\&quot;columns\\\&quot;:[{\\\&quot;name\\\&quot;:\\\&quot;id\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;token\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;},{\\\&quot;name\\\&quot;:\\\&quot;name\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;string\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;},{\\\&quot;name\\\&quot;:\\\&quot;price\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;int\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}]},\\\&quot;data\\\&quot;:{}}\&quot;,\&quot;price\&quot;:\&quot;10\&quot;,\&quot;id\&quot;:\&quot;5\&quot;,\&quot;$submit\&quot;:\&quot;Input\&quot;}}&quot;,&quot;price&quot;:&quot;250&quot;,&quot;id&quot;:&quot;5&quot;,&quot;submit&quot;:&quot;Ok&quot;}}"/>  
  40.     </form>  
  41.   </body>  
  42. </html>  

削除したエンティティのデータが表示されます。この結果を確認した後に、OKボタンを押下するとトップページに戻ります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>HelloResource</title>  
  6.   </head>  
  7.   <body>  
  8.     <ul>  
  9.       <li>  
  10.         <a href="product">List</a>  
  11.       </li>  
  12.       <li>  
  13.         <a href="product/_create_">Create</a>  
  14.       </li>  
  15.       <li>  
  16.         <a href="product/_update_">Update</a>  
  17.       </li>  
  18.       <li>  
  19.         <a href="product/_delete_">Delete</a>  
  20.       </li>  
  21.     </ul>  
  22.   </body>  
  23. </html>  

まとめ

Cozy Webでのエンティティの削除の方法について説明しました。モデルの定義のみでシナリオに沿ったエンティティの更新、作成、削除ができることが分かりました。

次回からエンティティの一覧表示について見ていきます。

諸元

Cozy
0.0.14

2023年7月31日月曜日

Cozy Web/エンティティ更新のカスタム画面

Cozy Web上でエンティティのモデル定義をすることで、Web上でのリソースアクセスをノンプログラミングで行う方法についてみています。

前回はエンティティ更新の方法について説明しました。

モデルを定義するだけで、エンティティの更新画面が自動的に提供されることを確認しました。エンティティ更新を入力、確認、表示の3画面を使って行うことができました。

前回は、画面そのものはCozyが作成したデフォルト画面です。今回はエンティティ更新のカスタム画面を設定する方法について説明します。

HelloResource

ここまで作成したHelloResourceは、モデルの定義が行われており、エンティティの作成と更新を行うことができます。エンティティの作成では、アプリケーションが定義したビューを使用するようになっています。

今回は更新処理のアプリケーション定義ビューを追加します。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloResourceが作成されています。これをベースに開発を進めます。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義されています。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しています。

これがWebのリソースproductとなります。

トップページ

トップページとしてホームディレクトリに以下のindex.htmlを配備しています。

  1. <html>  
  2.     <head>  
  3.     <title>HelloResource</title>  
  4.     </head>  
  5.     <body>  
  6.     <ul>  
  7.         <li><a href="product">List</a></li>  
  8.         <li><a href="product/_create_">Create</a></li>  
  9.         <li><a href="product/_update_">Update</a></li>  
  10.     </ul>  
  11.     </body>  
  12. </html>  

エンティティ操作シナリオ

エンティティのモデル定義を行うとエンティティ作成シナリオが自動的に作成されます。

エンティティの更新には以下の2種類があります。

  • 更新するエンティティのIDを更新画面から入力
  • 更新するエンティティのIDを更新開始時に指定

アプリケーション定義ビュー

エンティティの更新シナリオの3つの処理、入力処理、確認処理、表示処理それぞれのアプリケーションのカスタム画面をみていきます。

入力画面

カスタムの入力画面として以下のupdate__input.htmlをproduct.entityディレクトリに配備します。

  1. <html>  
  2.     <head>  
  3.     <title>Update Product/Input</title>  
  4.     </head>  
  5.     <body>  
  6.     <h1>Update Product/Input</h1>  
  7.     <c:detail />  
  8.     </body>  
  9. </html>  

タグ c:detail の場所に入力処理用の入力フォームが出力されます。

デフォルト画面との変更点はヘッダと画面のタイトル部を追加している点です。ここではシンプルな追加のみにしていますが、必要に応じて画面のデザインを追加していく形になります。

確認画面

カスタムの入力画面として以下のupdate__confirm.htmlをproduct.entityディレクトリに配備します。

  1. <html>  
  2.     <head>  
  3.     <title>Update Product/Confirm</title>  
  4.     </head>  
  5.     <body>  
  6.     <h1>Update Product/Confirm</h1>  
  7.     <c:detail />  
  8.     </body>  
  9. </html>  

タグ c:detail の場所に確認処理用のフォームが出力されます。

入力画面と同様に、変更点はヘッダと画面のタイトル部を追加している点です。

表示画面

カスタムの入力画面として以下のupdate__show.htmlをproduct.entityディレクトリに配備します。

  1. <html>  
  2.     <head>  
  3.     <title>Update Product/Show</title>  
  4.     </head>  
  5.     <body>  
  6.     <h1>Update Product/Show</h1>  
  7.     <c:detail />  
  8.     </body>  
  9. </html>  

タグ c:detail の場所に結果確認処理用のフォームが出力されます。

入力画面や確認画面と同様に、変更点はヘッダと画面のタイトル部を追加している点です。

実行

それではIDを指定したエンティティの更新を実行してみましょう。

エンティティ更新ページ

IDを指定してリエンティティの更新を行ってみます。IDが1の場合は以下になります。

  1. $ curl http://localhost:8080/web/HelloResource/product/1/_update_  

次のようにエンティティ作成に必要なデータを登録するためのFORMの画面が表示されました。

update__input.htmlとして登録した入力ページが表示されました。

画面のタイトルとして、カスタム画面の定義が使用されていることが分かります。

  1. <!DOCTYPE html>  
  2. <html><head>  
  3.     <title>Update Product/Input</title>  
  4.     </head><body>  
  5.     <h1>Update Product/Input</h1>  
  6.     <form action="" method="POST">  
  7.       <table class="">  
  8.       <tbody><tr class=""><th scope="row" class="">Id</th><td class=""><input type="text" name="id" value="1" /></td></tr><tr class=""><th scope="row" class="">Name</th><td class=""><input type="text" name="name" value="Apple" /></td></tr><tr class=""><th scope="row" class="">Price</th><td class=""><input type="text" name="price" value="300" /></td></tr></tbody>  
  9.       </table>  
  10.       <table>  
  11.         <tr><td><input type="submit" name="$submit" value="Input" /></td><td><input type="submit" name="$submit" value="Cancel" /></td></tr>  
  12.       </table>  
  13.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;input&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{},&quot;id&quot;:&quot;1&quot;}" />  
  14.     </form>  
  15.       
  16. </body></html>  

作成の場合と違って、FORMの中にID「1」の情報が動的的に設定されています。

このページでは以下のボタンが表示されています。

Input
データ登録
Cancel
キャンセル

ID 1のデータはAppleですが、値段を100円から150円に変更しましょう。

Inputボタンを押下するとエンティティ更新のための次の画面に遷移します。

Cancelボタンを押下するとトップページに戻ります。

登録データ確認ページ

データ登録画面でInputボタンを押すと、登録データ確認画面が表示されます。

update__confirm.htmlとして登録した入力ページが表示されました。

画面のタイトルとして、カスタム画面の定義が使用されていることが分かります。

  1. <!DOCTYPE html>  
  2. <html><head>  
  3.     <title>Update Product/Confirm</title>  
  4.     </head><body>  
  5.     <h1>Update Product/Confirm</h1>  
  6.     <form action="" method="POST">  
  7.       <table class="">  
  8.       <tbody><tr class=""><th scope="row" class="">Id</th><td class="">1</td></tr><tr class=""><th scope="row" class="">Name</th><td class="">Apple</td></tr><tr class=""><th scope="row" class="">Price</th><td class="">150</td></tr></tbody>  
  9.       </table>  
  10.       <input type="hidden" name="id" value="1" /><input type="hidden" name="name" value="Apple" /><input type="hidden" name="price" value="150" />  
  11.       <table>  
  12.         <tr><td><input type="submit" name="$submit" value="Ok" /></td><td><input type="submit" name="$submit" value="Ok_show" /></td><td><input type="submit" name="$submit" value="Back" /></td><td><input type="submit" name="$submit" value="Cancel" /></td></tr>  
  13.       </table>  
  14.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;confirm&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Apple&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;input\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{},\&quot;id\&quot;:\&quot;1\&quot;}&quot;,&quot;price&quot;:&quot;150&quot;,&quot;id&quot;:&quot;1&quot;,&quot;submit&quot;:&quot;Input&quot;},&quot;id&quot;:&quot;1&quot;}" />  
  15.     </form>  
  16.       
  17. </body></html>  

画面に入力したデータが表示されます。この結果を確認した上で、以下のいずれかのボタンを押下します。

Ok
確認OK
Ok_show
確認OKで結果を表示
Back
入力画面にモデル
Cancel
キャンセル

Ok_showボタンを押下するとエンティティ更新が行われ、更新した情報の表示画面に遷移します。

Okの場合は、エンティティ更新後トップページに遷移します。

結果ページ

更新確認画面でOK_showボタンを押すと、エンティティの更新が行われ、作成されたエンティティの情報表示ページに移ります。

update__show.htmlとして登録した入力ページが表示されました。

画面のタイトルとして、カスタム画面の定義が使用されていることが分かります。

  1. <!DOCTYPE html>  
  2. <html><head>  
  3.     <title>Update Product/Show</title>  
  4.     </head><body>  
  5.     <h1>Update Product/Show</h1>  
  6.     <form action="" method="POST">  
  7.       <table class="">  
  8.       <tbody><tr class=""><th scope="row" class="">Id</th><td class="">1</td></tr><tr class=""><th scope="row" class="">Name</th><td class="">Apple</td></tr><tr class=""><th scope="row" class="">Price</th><td class="">150</td></tr></tbody>  
  9.       </table>  
  10.       <input type="hidden" name="id" value="1" /><input type="hidden" name="name" value="Apple" /><input type="hidden" name="price" value="150" />  
  11.       <table>  
  12.         <tr><td><input type="submit" name="$submit" value="Ok" /></td></tr>  
  13.       </table>  
  14.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;show&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Apple&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;confirm\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{\&quot;name\&quot;:\&quot;Apple\&quot;,\&quot;$scenario\&quot;:\&quot;{\\\&quot;name\\\&quot;:\\\&quot;update-entity\\\&quot;,\\\&quot;state\\\&quot;:\\\&quot;input\\\&quot;,\\\&quot;entity\\\&quot;:\\\&quot;product\\\&quot;,\\\&quot;schema\\\&quot;:{\\\&quot;columns\\\&quot;:[{\\\&quot;name\\\&quot;:\\\&quot;id\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;token\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}, {\\\&quot;name\\\&quot;:\\\&quot;name\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;string\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}, {\\\&quot;name\\\&quot;:\\\&quot;price\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;int\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}]},\\\&quot;data\\\&quot;:{},\\\&quot;id\\\&quot;:\\\&quot;1\\\&quot;}\&quot;,\&quot;price\&quot;:\&quot;150\&quot;,\&quot;id\&quot;:\&quot;1\&quot;,\&quot;$submit\&quot;:\&quot;Input\&quot;},\&quot;id\&quot;:\&quot;1\&quot;}&quot;,&quot;price&quot;:&quot;150&quot;,&quot;id&quot;:&quot;1&quot;,&quot;submit&quot;:&quot;Ok_show&quot;},&quot;id&quot;:&quot;1&quot;}" />  
  15.     </form>  
  16.       
  17. </body></html>  

作成したエンティティのデータが表示されます。この結果を確認した後に、OKボタンを押下するとトップページに戻ります。

確認

確認のためにリソースproductの一覧を表示してみましょう。

  1. $ curl http://localhost:8080/web/HelloResource/product  

以下のようにオブジェクトID 1のAppleの値段が150に変更されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>Product List</title>  
  6.   </head>  
  7.   <body>  
  8.     <table class="">  
  9.       <caption class="">product</caption>  
  10.       <thead class="">  
  11.         <tr class="">  
  12.           <th scope="col" class="">Id</th>  
  13.           <th scope="col" class="">Name</th>  
  14.           <th scope="col" class="">Price</th>  
  15.         </tr>  
  16.       </thead>  
  17.       <tbody class="">  
  18.         <tr data-href="product/1.html">  
  19.           <td class="">1</td>  
  20.           <td class="">Apple</td>  
  21.           <td class="">150</td>  
  22.         </tr>  
  23.         <tr data-href="product/2.html">  
  24.           <td class="">2</td>  
  25.           <td class="">Orange</td>  
  26.           <td class="">350</td>  
  27.         </tr>  
  28.         <tr data-href="product/3.html">  
  29.           <td class="">3</td>  
  30.           <td class="">Peach</td>  
  31.           <td class="">400</td>  
  32.         </tr>  
  33.       </tbody>  
  34.     </table>  
  35.   </body>  
  36. </html>  

まとめ

Cozy Webでのエンティティの作成、削除の方法について説明してきました。モデルの定義のみでシナリオに沿ったエンティティの作成、削除ができることが分かりました。またエンティティの作成、削除画面のカスタマイズも可能です。

次回はエンティティの削除について説明します。

諸元

Cozy
0.0.13

2023年6月30日金曜日

Cozy Web/エンティティ更新(2)

Cozy Web上でエンティティのモデル定義をすることで、Web上でのリソースアクセスをノンプログラミングで行う方法についてみています。

ここまで、エンティティの作成についてみてきました。

前回はエンティティの更新の基本形としてエンティティIDを指定しない形を説明しました。

今回はエンティティIDを指定してエンティティの更新をする方法について説明します。

HelloResource

ここまで作成したHelloResourceは、モデルの定義が行われており、エンティティの作成を行うことができます。エンティティの作成では、アプリケーションが定義したビューを使用するようになっています。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloResourceが作成されています。これをベースに開発を進めます。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義されています。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しています。

これがWebのリソースproductとなります。

トップページ

  1. <html>  
  2.     <head>  
  3.     <title>HelloResource</title>  
  4.     </head>  
  5.     <body>  
  6.     <ul>  
  7.         <li><a href="product">List</a></li>  
  8.         <li><a href="product/_create_">Create</a></li>  
  9.         <li><a href="product/_update_">Update</a></li>  
  10.     </ul>  
  11.     </body>  
  12. </html>  

エンティティ操作シナリオ

エンティティのモデル定義を行うとエンティティ作成シナリオが自動的に作成されます。

エンティティの更新には以下の2種類があります。

  • 更新するエンティティのIDを更新画面から入力
  • 更新するエンティティのIDを更新開始時に指定

前回、前者の更新するエンティティのIDを更新画面から入力のシナリオを確認しました。

今回は後者の更新するエンティティのIDを更新開始時に指定を実行します。

実行

それではIDを指定したエンティティの更新を実行してみましょう。

エンティティ更新ページ

IDを指定してリエンティティの更新を行う場合には、リソース名の後ろに「ID/_update_」をつけてアクセスします。IDが1の場合は以下になります。

  1. $ curl http://localhost:8080/web/HelloResource/product/1/_update_  

次のようにエンティティ作成に必要なデータを登録するためのFORMの画面が表示されました。

まだビューの定義はされていないので、Cozy Webのデフォルト入力画面が表示されます。

  1. <!DOCTYPE html>  
  2. <html><head>  
  3.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  4.   <meta name="keywords" content="TBD" />  
  5.   <meta name="description" content="TBD" />  
  6.   <meta name="robots" content="noindex,nofollow" />  
  7.   <meta name="author" content="TBD" />  
  8.     
  9.     
  10.   </head><body><form action="" method="POST">  
  11.       <table class="">  
  12.       <tbody><tr class=""><th scope="row" class="">Id</th><td class=""><input type="text" name="id" value="1" /></td></tr><tr class=""><th scope="row" class="">Name</th><td class=""><input type="text" name="name" value="Apple" /></td></tr><tr class=""><th scope="row" class="">Price</th><td class=""><input type="text" name="price" value="100" /></td></tr></tbody>  
  13.       </table>  
  14.       <table>  
  15.         <tr><td><input type="submit" name="$submit" value="Input" /></td><td><input type="submit" name="$submit" value="Cancel" /></td></tr>  
  16.       </table>  
  17.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;input&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{},&quot;id&quot;:&quot;1&quot;}" />  
  18.     </form></body></html>  

作成の場合と違って、FORMの中にID「1」の情報が動的的に設定されています。

このページでは以下のボタンが表示されています。

Input
データ登録
Cancel
キャンセル

ID 1のデータはAppleですが、値段を100円から150円に変更しましょう。

Inputボタンを押下するとエンティティ更新のための次の画面に遷移します。

Cancelボタンを押下するとトップページに戻ります。

登録データ確認ページ

データ登録画面でInputボタンを押すと、登録データ確認画面が表示されます。

  1. <!DOCTYPE html>  
  2. <html><head>  
  3.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  4.   <meta name="keywords" content="TBD" />  
  5.   <meta name="description" content="TBD" />  
  6.   <meta name="robots" content="noindex,nofollow" />  
  7.   <meta name="author" content="TBD" />  
  8.     
  9.     
  10.   </head><body><form action="" method="POST">  
  11.       <table class="">  
  12.       <tbody><tr class=""><th scope="row" class="">Id</th><td class="">1</td></tr><tr class=""><th scope="row" class="">Name</th><td class="">Apple</td></tr><tr class=""><th scope="row" class="">Price</th><td class="">150</td></tr></tbody>  
  13.       </table>  
  14.       <input type="hidden" name="id" value="1" /><input type="hidden" name="name" value="Apple" /><input type="hidden" name="price" value="150" />  
  15.       <table>  
  16.         <tr><td><input type="submit" name="$submit" value="Ok" /></td><td><input type="submit" name="$submit" value="Ok_show" /></td><td><input type="submit" name="$submit" value="Back" /></td><td><input type="submit" name="$submit" value="Cancel" /></td></tr>  
  17.       </table>  
  18.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;confirm&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Apple&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;input\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{},\&quot;id\&quot;:\&quot;1\&quot;}&quot;,&quot;price&quot;:&quot;150&quot;,&quot;id&quot;:&quot;1&quot;,&quot;submit&quot;:&quot;Input&quot;},&quot;id&quot;:&quot;1&quot;}" />  
  19.     </form></body></html>  

画面に入力したデータが表示されます。この結果を確認した上で、以下のいずれかのボタンを押下します。

Ok
確認OK
Ok_show
確認OKで結果を表示
Back
入力画面にモデル
Cancel
キャンセル

Ok_showボタンを押下するとエンティティ更新が行われ、更新した情報の表示画面に遷移します。

Okの場合は、エンティティ更新後トップページに遷移します。

結果ページ

更新確認画面でOK_showボタンを押すと、エンティティの更新が行われ、作成されたエンティティの情報表示ページに移ります。

  1. <!DOCTYPE html>  
  2. <html><head>  
  3.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  4.   <meta name="keywords" content="TBD" />  
  5.   <meta name="description" content="TBD" />  
  6.   <meta name="robots" content="noindex,nofollow" />  
  7.   <meta name="author" content="TBD" />  
  8.     
  9.     
  10.   </head><body><form action="" method="POST">  
  11.       <table class="">  
  12.       <tbody><tr class=""><th scope="row" class="">Id</th><td class="">1</td></tr><tr class=""><th scope="row" class="">Name</th><td class="">Apple</td></tr><tr class=""><th scope="row" class="">Price</th><td class="">150</td></tr></tbody>  
  13.       </table>  
  14.       <input type="hidden" name="id" value="1" /><input type="hidden" name="name" value="Apple" /><input type="hidden" name="price" value="150" />  
  15.       <table>  
  16.         <tr><td><input type="submit" name="$submit" value="Ok" /></td></tr>  
  17.       </table>  
  18.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;show&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Apple&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;confirm\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}, {\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{\&quot;name\&quot;:\&quot;Apple\&quot;,\&quot;$scenario\&quot;:\&quot;{\\\&quot;name\\\&quot;:\\\&quot;update-entity\\\&quot;,\\\&quot;state\\\&quot;:\\\&quot;input\\\&quot;,\\\&quot;entity\\\&quot;:\\\&quot;product\\\&quot;,\\\&quot;schema\\\&quot;:{\\\&quot;columns\\\&quot;:[{\\\&quot;name\\\&quot;:\\\&quot;id\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;token\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}, {\\\&quot;name\\\&quot;:\\\&quot;name\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;string\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}, {\\\&quot;name\\\&quot;:\\\&quot;price\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;int\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}]},\\\&quot;data\\\&quot;:{},\\\&quot;id\\\&quot;:\\\&quot;1\\\&quot;}\&quot;,\&quot;price\&quot;:\&quot;150\&quot;,\&quot;id\&quot;:\&quot;1\&quot;,\&quot;$submit\&quot;:\&quot;Input\&quot;},\&quot;id\&quot;:\&quot;1\&quot;}&quot;,&quot;price&quot;:&quot;150&quot;,&quot;id&quot;:&quot;1&quot;,&quot;submit&quot;:&quot;Ok_show&quot;},&quot;id&quot;:&quot;1&quot;}" />  
  19.     </form></body></html>  

作成したエンティティのデータが表示されます。この結果を確認した後に、OKボタンを押下するとトップページに戻ります。

確認

確認のためにリソースproductの一覧を表示してみましょう。

  1. $ curl http://localhost:8080/web/HelloResource/product  

以下のようにオブジェクトID 1のAppleの値段が150に変更されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>Product List</title>  
  6.   </head>  
  7.   <body>  
  8.     <table class="">  
  9.       <caption class="">product</caption>  
  10.       <thead class="">  
  11.         <tr class="">  
  12.           <th scope="col" class="">Id</th>  
  13.           <th scope="col" class="">Name</th>  
  14.           <th scope="col" class="">Price</th>  
  15.         </tr>  
  16.       </thead>  
  17.       <tbody class="">  
  18.         <tr data-href="product/1.html">  
  19.           <td class="">1</td>  
  20.           <td class="">Apple</td>  
  21.           <td class="">150</td>  
  22.         </tr>  
  23.         <tr data-href="product/2.html">  
  24.           <td class="">2</td>  
  25.           <td class="">Orange</td>  
  26.           <td class="">350</td>  
  27.         </tr>  
  28.         <tr data-href="product/3.html">  
  29.           <td class="">3</td>  
  30.           <td class="">Peach</td>  
  31.           <td class="">400</td>  
  32.         </tr>  
  33.       </tbody>  
  34.     </table>  
  35.   </body>  
  36. </html>  

まとめ

今回はエンティティ更新の方法について説明しました。

モデルを定義するだけで、エンティティの更新画面が自動的に提供されることを確認しました。エンティティ更新を入力、確認、表示の3画面を使って行うことができました。

今回は、画面そのものはCozyが作成したデフォルト画面です。次回はエンティティ更新のカスタム画面を設定する方法について説明します。

諸元

Cozy
0.0.13

2023年5月31日水曜日

Cozy Web/エンティティ更新

Cozy Web上でエンティティのモデル定義をすることで、Web上でのリソースアクセスをノンプログラミングで行う方法についてみています。

ここまで、エンティティの作成についてみてきました。

今回はエンティティの更新についてみていきます。

HelloResource

ここまで作成したHelloResourceは、モデルの定義が行われており、エンティティの作成を行うことができます。エンティティの作成では、アプリケーションが定義したビューを使用するようになっています。

準備

cozyを起動するディレクトリのwebappsディレクトリに、アプリケーションのホームディレクトリとなるHelloResourceが作成されています。これをベースに開発を進めます。

モデル

WEB-INF/models/model.orgにアプリケーションで使用するモデルが定義されています。

  1. * entity    
  2. ** product  
  3. *** features    
  4. table=product  
  5. *** attributes    
  6. | Name  | Type   | Multiplicity |  
  7. |-------+--------+--------------|  
  8. | id    | token  |            1 |  
  9. | name  | string |            1 |  
  10. | price | int    |            1 |  

エンティティproductを定義しています。

これがWebのリソースproductとなります。

トップページ

  1. <html>  
  2.     <head>  
  3.     <title>HelloResource</title>  
  4.     </head>  
  5.     <body>  
  6.     <ul>  
  7.         <li><a href="product">List</a></li>  
  8.         <li><a href="product/_create_">Create</a></li>  
  9.         <li><a href="product/_update_">Update</a></li>  
  10.     </ul>  
  11.     </body>  
  12. </html>  

エンティティ操作シナリオ

エンティティのモデル定義を行うとエンティティ作成シナリオが自動的に作成されます。

このエンティティ作成シナリオによって、エンティティの作成オペレーションが可能になったことを前々回、前回に確認しました。

エンティティの更新オペレーションも同様にエンティティ作成シナリオによって可能になります。

エンティティの更新には以下の2種類があります。

  • 更新するエンティティのIDを更新画面から入力
  • 更新するエンティティのIDを更新開始時に指定

今回は前者の更新エンティティIDを更新画面から入力するシナリオを実行します。

実行

それではエンティティの更新を実行してみましょう。

エンティティ更新ページ

以下のようにリソース名の後ろに「_update_」をつけてアクセスします。

  1. $ curl http://localhost:8080/web/HelloResource/product/_update_  

次のようにエンティティ作成に必要なデータを登録するためのFORMの画面が表示されました。

まだビューの定義はされていないので、Cozy Webのデフォルト入力画面が表示されます。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.   </head>  
  11.   <body>  
  12.     <form action="" method="POST">  
  13.       <table class="">  
  14.         <tbody>  
  15.           <tr class="">  
  16.             <th scope="row" class="">Id</th>  
  17.             <td class="">  
  18.               <input type="text" name="id" value=""/>  
  19.             </td>  
  20.           </tr>  
  21.           <tr class="">  
  22.             <th scope="row" class="">Name</th>  
  23.             <td class="">  
  24.               <input type="text" name="name" value=""/>  
  25.             </td>  
  26.           </tr>  
  27.           <tr class="">  
  28.             <th scope="row" class="">Price</th>  
  29.             <td class="">  
  30.               <input type="text" name="price" value=""/>  
  31.             </td>  
  32.           </tr>  
  33.         </tbody>  
  34.       </table>  
  35.       <table>  
  36.         <tr>  
  37.           <td>  
  38.             <input type="submit" name="$submit" value="Input"/>  
  39.           </td>  
  40.           <td>  
  41.             <input type="submit" name="$submit" value="Cancel"/>  
  42.           </td>  
  43.         </tr>  
  44.       </table>  
  45.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;input&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{}}"/>  
  46.     </form>  
  47.   </body>  
  48. </html>  

このページでは以下のボタンが表示されています。

Input
データ登録
Cancel
キャンセル Inputボタンを押下するとエンティティ作成のための次の画面に遷移します。

Cancelボタンを押下するとトップページに戻ります。

登録データ確認ページ

データ登録画面でInputボタンが押されたので、登録データ確認画面が表示されます。

  1. <html>  
  2.   <head>  
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  4.     <meta name="keywords" content="TBD"/>  
  5.     <meta name="description" content="TBD"/>  
  6.     <meta name="robots" content="noindex,nofollow"/>  
  7.     <meta name="author" content="TBD"/>  
  8.   </head>  
  9.   <body>  
  10.     <form action="" method="POST">  
  11.       <table class="">  
  12.         <tbody>  
  13.           <tr class="">  
  14.             <th scope="row" class="">Id</th>  
  15.             <td class="">1</td>  
  16.           </tr>  
  17.           <tr class="">  
  18.             <th scope="row" class="">Name</th>  
  19.             <td class="">Apple</td>  
  20.           </tr>  
  21.           <tr class="">  
  22.             <th scope="row" class="">Price</th>  
  23.             <td class="">300</td>  
  24.           </tr>  
  25.         </tbody>  
  26.       </table>  
  27.       <input type="hidden" name="id" value="5"/>  
  28.       <input type="hidden" name="name" value="Banana"/>  
  29.       <input type="hidden" name="price" value="250"/>  
  30.       <table>  
  31.         <tr>  
  32.           <td>  
  33.             <input type="submit" name="$submit" value="Ok"/>  
  34.           </td>  
  35.           <td>  
  36.             <input type="submit" name="$submit" value="Back"/>  
  37.           </td>  
  38.           <td>  
  39.             <input type="submit" name="$submit" value="Cancel"/>  
  40.           </td>  
  41.         </tr>  
  42.       </table>  
  43.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;confirm&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Banana&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;input\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{}}&quot;,&quot;price&quot;:&quot;250&quot;,&quot;id&quot;:&quot;5&quot;,&quot;submit&quot;:&quot;Input&quot;}}"/>  
  44.     </form>  
  45.   </body>  
  46. </html>  

画面に入力したデータが表示されます。この結果を確認した上で、以下のいずれかのボタンを押下します。

OK
確認OK
Back
入力画面にモデル
Cancel
キャンセル

Okボタンを押下するとエンティティ作成のための次の画面に遷移します。

結果ページ

登録データ確認画面でOKボタンが押されたので、エンティティの作成が行われ、作成されたエンティティの情報表示ページに移ります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
  6.     <meta name="keywords" content="TBD"/>  
  7.     <meta name="description" content="TBD"/>  
  8.     <meta name="robots" content="noindex,nofollow"/>  
  9.     <meta name="author" content="TBD"/>  
  10.   </head>  
  11.   <body>  
  12.     <form action="" method="POST">  
  13.       <table class="">  
  14.         <tbody>  
  15.           <tr class="">  
  16.             <th scope="row" class="">Id</th>  
  17.             <td class="">1</td>  
  18.           </tr>  
  19.           <tr class="">  
  20.             <th scope="row" class="">Name</th>  
  21.             <td class="">Apple</td>  
  22.           </tr>  
  23.           <tr class="">  
  24.             <th scope="row" class="">Price</th>  
  25.             <td class="">100</td>  
  26.           </tr>  
  27.         </tbody>  
  28.       </table>  
  29.       <input type="hidden" name="id" value="1"/>  
  30.       <input type="hidden" name="name" value="Apple"/>  
  31.       <input type="hidden" name="price" value="100"/>  
  32.       <table>  
  33.         <tr>  
  34.           <td>  
  35.             <input type="submit" name="$submit" value="Ok"/>  
  36.           </td>  
  37.         </tr>  
  38.       </table>  
  39.       <input type="hidden" name="$scenario" value="{&quot;name&quot;:&quot;update-entity&quot;,&quot;state&quot;:&quot;show&quot;,&quot;entity&quot;:&quot;product&quot;,&quot;schema&quot;:{&quot;columns&quot;:[{&quot;name&quot;:&quot;id&quot;,&quot;datatype&quot;:&quot;token&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;name&quot;,&quot;datatype&quot;:&quot;string&quot;,&quot;multiplicity&quot;:&quot;1&quot;}, {&quot;name&quot;:&quot;price&quot;,&quot;datatype&quot;:&quot;int&quot;,&quot;multiplicity&quot;:&quot;1&quot;}]},&quot;data&quot;:{&quot;name&quot;:&quot;Banana&quot;,&quot;scenario&quot;:&quot;{\&quot;name\&quot;:\&quot;update-entity\&quot;,\&quot;state\&quot;:\&quot;confirm\&quot;,\&quot;entity\&quot;:\&quot;product\&quot;,\&quot;schema\&quot;:{\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;id\&quot;,\&quot;datatype\&quot;:\&quot;token\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;name\&quot;,\&quot;datatype\&quot;:\&quot;string\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;},{\&quot;name\&quot;:\&quot;price\&quot;,\&quot;datatype\&quot;:\&quot;int\&quot;,\&quot;multiplicity\&quot;:\&quot;1\&quot;}]},\&quot;data\&quot;:{\&quot;name\&quot;:\&quot;a\&quot;,\&quot;$scenario\&quot;:\&quot;{\\\&quot;name\\\&quot;:\\\&quot;update-entity\\\&quot;,\\\&quot;state\\\&quot;:\\\&quot;input\\\&quot;,\\\&quot;entity\\\&quot;:\\\&quot;product\\\&quot;,\\\&quot;schema\\\&quot;:{\\\&quot;columns\\\&quot;:[{\\\&quot;name\\\&quot;:\\\&quot;id\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;token\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;},{\\\&quot;name\\\&quot;:\\\&quot;name\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;string\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;},{\\\&quot;name\\\&quot;:\\\&quot;price\\\&quot;,\\\&quot;datatype\\\&quot;:\\\&quot;int\\\&quot;,\\\&quot;multiplicity\\\&quot;:\\\&quot;1\\\&quot;}]},\\\&quot;data\\\&quot;:{}}\&quot;,\&quot;price\&quot;:\&quot;10\&quot;,\&quot;id\&quot;:\&quot;5\&quot;,\&quot;$submit\&quot;:\&quot;Input\&quot;}}&quot;,&quot;price&quot;:&quot;250&quot;,&quot;id&quot;:&quot;5&quot;,&quot;submit&quot;:&quot;Ok&quot;}}"/>  
  40.     </form>  
  41.   </body>  
  42. </html>  

作成したエンティティのデータが表示されます。この結果を確認した後に、OKボタンを押下するとトップページに戻ります。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>HelloResource</title>  
  6.   </head>  
  7.   <body>  
  8.     <ul>  
  9.       <li>  
  10.         <a href="product">List</a>  
  11.       </li>  
  12.       <li>  
  13.         <a href="product/_create_">Create</a>  
  14.       </li>  
  15.       <li>  
  16.         <a href="product/_update_">Update</a>  
  17.       </li>  
  18.     </ul>  
  19.   </body>  
  20. </html>  

確認

確認のためにリソースproductの一覧を表示してみましょう。

  1. $ curl http://localhost:8080/web/HelloResource/product  

以下のようにオブジェクトID 1のAppleの値段が100に変更されました。

  1. <?xml version="1.0"?>  
  2. <!DOCTYPE html>  
  3. <html>  
  4.   <head>  
  5.     <title>Product List</title>  
  6.   </head>  
  7.   <body>  
  8.     <table class="">  
  9.       <caption class="">product</caption>  
  10.       <thead class="">  
  11.         <tr class="">  
  12.           <th scope="col" class="">Id</th>  
  13.           <th scope="col" class="">Name</th>  
  14.           <th scope="col" class="">Price</th>  
  15.         </tr>  
  16.       </thead>  
  17.       <tbody class="">  
  18.         <tr data-href="product/1.html">  
  19.           <td class="">1</td>  
  20.           <td class="">Apple</td>  
  21.           <td class="">100</td>  
  22.         </tr>  
  23.         <tr data-href="product/2.html">  
  24.           <td class="">2</td>  
  25.           <td class="">Orange</td>  
  26.           <td class="">350</td>  
  27.         </tr>  
  28.         <tr data-href="product/3.html">  
  29.           <td class="">3</td>  
  30.           <td class="">Peach</td>  
  31.           <td class="">400</td>  
  32.         </tr>  
  33.         <tr data-href="product/4.html">  
  34.           <td class="">4</td>  
  35.           <td class="">Banana</td>  
  36.           <td class="">250</td>  
  37.         </tr>  
  38.       </tbody>  
  39.     </table>  
  40.   </body>  
  41. </html>  

まとめ

Cozy Web上でエンティティのモデル定義をすることで、Web上でのリソースアクセスをノンプログラミングで行う方法についてみています。

リソースの作成に続いて、今回はリソースの更新の基本形について説明しました。

次回も引き続きリソースの更新について説明します。

諸元

Cozy
0.0.13