# KKW22501SFBean

## Purpose

`KKW22501SFBean` is the **view-state bean** for the KKW22501 search/function screen in a Japanese web application built on a custom X33S framework. It holds all the input fields, flags, disabled-state controls, and three repeat (iteration) data lists that constitute the screen's model state. It acts as the single bridge between the JSP view layer (the `.jsp` page) and the business-tier XML configuration, providing reflection-style property access via string-based key routing rather than direct method calls.

## Design

This class follows the **model-view binding** pattern common in JavaServer Faces–like architectures. It is designed around the X33S framework's conventions:

- **Extends `X33VViewBaseBean`** -- a framework base class that handles common information beans (shared state across screens) and provides default `loadModelData`, `storeModelData`, and `typeModelData` implementations.
- **Implements `X33VListedBeanInterface`** -- marking it as a bean that manages iterable/repeat list data.
- **Implements `X31CBaseBean`** -- a marker interface that ties the bean into the framework's screen-control layer.
- **Implements `Serializable`** -- allowing the bean to be serialized across HTTP requests (typical for HTTP session storage in JSP applications).

The class does not perform business logic. Instead, it stores raw screen values and provides infrastructure for the framework to read/write values by string keys. This indirection lets a JSP or XML configuration refer to fields by human-readable Japanese labels (e.g., `"代理店コード"` for "Agency Code") rather than hard-coded property names.

### Field Categories

The fields fall into five distinct groups:

| Category | Fields | Description |
|---|---|---|
| Search input fields | `search_agnt_cd`, `search_campaign_cd`, `search_dchskm_cd`, `search_campaign_nm` | Text inputs for searching by agency code, campaign code, registration data code, and campaign name |
| Date/time fields | `agnt_set_campaign_staymd`, `agnt_set_campaign_endymd` | Start and end dates for campaign receipt periods |
| Repeat (list) data | `dchskm_sete_jkn_list_list`, `bf_dchskm_sete_jkn_list_list`, `dchskm_list_list` | Three `X33VDataTypeList` collections holding bean instances for repeat rows |
| Boolean/UI flags | `search_flg_enabled`, `del_flg_enabled`, `reset_flg_enabled`, `dtl_dsp_flg_enabled`, `process_kbn_enabled` | Control whether search, delete, reset, detail-display, and process-category fields are active |
| Button disabled states | `search_btn_disabled`, `add_cfm_btn_disabled`, `del_cfm_btn_disabled` | Track whether search, register-confirm, and delete-confirm buttons should be disabled |

Each scalar field is split into three sub-properties following the `update/value/state` pattern:

- **`_value`** -- the actual data value (stored as `String` or `Boolean`).
- **`_state`** -- a framework-internal state string (typically `""` by default), likely used to convey validation status, CSS class, or server-side UI hints.
- **`_update`** -- a framework flag indicating whether the field's value was modified since last load, used for optimistic concurrency or dirty-tracking.

The three `X33VDataTypeList` fields hold child bean instances:
- `dchskm_sete_jkn_list_list` -- search condition items (registered data) -- each element is a `KKW22501SF01DBean`.
- `bf_dchskm_sete_jkn_list_list` -- pre-modification search condition items -- each element is also a `KKW22501SF01DBean`.
- `dchskm_list_list` -- data extraction item list -- each element is a `KKW22501SF02DBean`.

## Key Methods

### Constructor

```java
public KKW22501SFBean()
```

Initializes the three repeat data list fields to empty `X33VDataTypeList` instances. Without this initialization, the first call to `addListDataInstance()` would encounter a `NullPointerException` on a null list reference. All other fields are left at their default Java values (`null` for Strings, `false` for Booleans).

### Property Getters and Setters (update / value / state triplets)

The class provides three getter/setter pairs for every scalar field, following the naming convention `get{Field}_update()`, `get{Field}_value()`, and `get{Field}_state()`. For example:

```java
public String getSearch_agnt_cd_value();
public void setSearch_agnt_cd_value(String param);
public String getSearch_agnt_cd_state();
public void setSearch_agnt_cd_state(String param);
public String getSearch_agnt_cd_update();
public void setSearch_agnt_cd_update(String param);
```

There are roughly 12 such fields, each with 3 properties, yielding ~36 accessor methods. The `_enabled` fields (`search_flg_enabled`, `del_flg_enabled`, etc.) have their own getter/setter pair returning `Boolean`, and are initialized to `false` by default.

The `_value` fields are the primary data carriers. The `_state` fields likely communicate UI state from the server to the JSP (e.g., error highlighting). The `_update` fields are framework internal flags.

The `search_err_flg_zero_value` field is a notable exception: it is initialized to `"1"` rather than `null` or `""`. This suggests the search "zero results" error flag defaults to an active/true state.

### List Data Getters and JSF List Converters

```java
public X33VDataTypeList getDchskm_sete_jkn_list_list();
public X33VDataTypeList getBf_dchskm_sete_jkn_list_list();
public X33VDataTypeList getDchskm_list_list();
```

These return the raw `X33VDataTypeList` instances for programmatic access.

Additionally, the class provides JSF `SelectItem` list converters:

```java
public ArrayList<SelectItem> getJsflist_typelist_dchskm_sete_jkn_list();
public ArrayList<SelectItem> getJsflist_typelist_bf_dchskm_sete_jkn_list();
public ArrayList<SelectItem> getJsflist_typelist_dchskm_list();
```

Each iterates over its corresponding list and builds an `ArrayList<SelectItem>` where the item value is extracted from the child bean's `loadModelData("xxx", "value")` call. This converts the list data into a format suitable for JSF `<h:selectOneListbox>` or `<h:selectManyListbox>` components.

### loadModelData (Core Data Accessor)

```java
public Object loadModelData(String gamenId, String key, String subkey);
public Object loadModelData(String key, String subkey);
```

These are the **most important methods** in the class. They implement a string-keyed property access system that replaces direct field access with a routing mechanism.

**How it works:**

1. If `key` is `null`, returns `null`.
2. If `key` starts with `//`, delegates to `super.loadCommonInfoData(key)` for common information bean access.
3. Splits the `key` at the first `/` to determine which field category it refers to. The `key` contains a **human-readable Japanese label** (e.g., `"代理店コード"`, `"検索フラグ"`, `"データ抽出項目設定条件一覧照会（イベントSP）詳細"`).
4. If `subkey` is `"value"`, returns the field's value (e.g., `getSearch_agnt_cd_value()`).
5. If `subkey` is `"state"`, returns the field's state (e.g., `getSearch_agnt_cd_state()`).
6. If `subkey` is `"enable"`, returns the corresponding `_enabled` Boolean flag.
7. For **repeat list fields**, if the key contains an index like `"データ抽出項目設定条件一覧照会（イベントSP）詳細/0/プロシ名前"`, it:
   - Parses the index (`0`), validates it against the list size.
   - If index is `"*"`, returns the list size as `Integer`.
   - Otherwise, retrieves the child bean at that index and delegates `loadModelData(childKey, subkey)` to it.

**Key-to-field mappings** (Japanese label to field):

| Key (Japanese) | Field |
|---|---|
| `代理店コード` | `search_agnt_cd` |
| `表示用データ抽出項目コード` | `search_campaign_cd` |
| `データ抽出項目コード（登録用）` | `search_dchskm_cd` |
| `データ抽出項目名` | `search_campaign_nm` |
| `受付開始年月日時分` | `agnt_set_campaign_staymd` |
| `受付終了年月日時分` | `agnt_set_campaign_endymd` |
| `データ抽出項目設定条件一覧照会（イベントSP）詳細` | `dchskm_sete_jkn_list_list` |
| `変更前データ抽出項目設定条件一覧照会（イベントSP）詳細` | `bf_dchskm_sete_jkn_list_list` |
| `データ抽出項目一覧照会詳細` | `dchskm_list_list` |
| `検索フラグ` | `search_flg` |
| `削除フラグ` | `del_flg` |
| `リセットフラグ` | `reset_flg` |
| `詳細表示フラグ` | `dtl_dsp_flg` |
| `検索エラーフラグ（0件）` | `search_err_flg_zero` |
| `処理区分` | `process_kbn` |
| `検索ボタン使用可否` | `search_btn_disabled` |
| `登録ボタン使用可否` | `add_cfm_btn_disabled` |
| `削除ボタン使用可否` | `del_cfm_btn_disabled` |

### storeModelData (Core Data Mutator)

```java
public void storeModelData(String gamenId, String key, String subkey, Object in_value);
public void storeModelData(String key, String subkey, Object in_value);
public void storeModelData(String key, String subkey, Object in_value, boolean isSetAsString);
```

The mirror of `loadModelData`. Routes incoming values to the correct field based on the same key-parsing logic:

1. If `key` is `null`, returns immediately (no-op).
2. If `key` starts with `//`, delegates to `super.storeCommonInfoData()`.
3. For scalar fields, casts `in_value` to `String` (or `Boolean` for `_enable` subkeys) and calls the appropriate setter.
4. For repeat list fields, parses the index, validates bounds, retrieves the child bean, and delegates `storeModelData()` to it. The `isSetAsString` flag is forwarded to child beans for cases where a `Long` field needs a string value set via property.

### listServiceFormIds

```java
public String[] listServiceFormIds()
```

Returns `null`. This is likely a framework hook that was left unimplemented for this screen, meaning no service forms are associated with it.

### listKoumokuIds

```java
public ArrayList<String> listKoumokuIds(String key)
```

Returns a list of available field keys (Japanese labels). This is a **field introspection method**:

- If `key` is `null`, returns a list of **all** field keys for this screen (17 entries covering all search inputs, date fields, repeat lists, flags, and button states).
- If `key` starts with `//` (common info bean), delegates to `super.listKoumokuIds(key)`.
- For repeat list keys, delegates to the child bean's `listKoumokuIds()` static method:
  - `データ抽出項目設定条件一覧照会（イベントSP）詳細` -> `KKW22501SF01DBean.listKoumokuIds()`
  - `変更前データ抽出項目設定条件一覧照会（イベントSP）詳細` -> `KKW22501SF01DBean.listKoumokuIds()`
  - `データ抽出項目一覧照会詳細` -> `KKW22501SF02DBean.listKoumokuIds()`
- Otherwise returns an empty list.

### addListDataInstance

```java
public int addListDataInstance(String key) throws X33SException
```

Appends a new row to one of the three repeat lists:

1. If `key` starts with `//`, delegates to `super.addListDataInstance(key)`.
2. For `データ抽出項目設定条件一覧照会（イベントSP）詳細`, creates a new `KKW22501SF01DBean` and adds it to `dchskm_sete_jkn_list_list`.
3. For `変更前データ抽出項目設定条件一覧照会（イベントSP）詳細`, creates a new `KKW22501SF01DBean` and adds it to `bf_dchskm_sete_jkn_list_list`.
4. For `データ抽出項目一覧照会詳細`, creates a new `KKW22501SF02DBean` and adds it to `dchskm_list_list`.
5. Returns the index of the newly added element, or `-1` if the key is unrecognized or `null`.

### removeElementFromListData

```java
public void removeElementFromListData(String key, int index) throws X33SException
```

Removes the element at `index` from the specified repeat list. Performs bounds checking before removal. If `key` starts with `//`, delegates to the superclass.

### clearListDataInstance

```java
public void clearListDataInstance(String key) throws X33SException
```

Clears all elements from the specified repeat list. If `key` starts with `//`, delegates to the superclass.

### typeModelData

```java
public Class<?> typeModelData(String gamenId, String key, String subkey);
public Class<?> typeModelData(String key, String subkey);
```

Returns the `Class` type for a given key/subkey pair, enabling framework type introspection:

- Simple fields (`value` or `state` subkeys): returns `String.class`.
- Boolean enable fields (`enable` subkeys): returns `Boolean.class`.
- Repeat list size (`*` index): returns `Integer.class`.
- Repeat list items: delegates to the child bean's `typeModelData()`.
- Common info beans: delegates to `super.typeCommonInfoData(key)`.

## Relationships

```mermaid
flowchart TD
    A["KKW225010PJP.jsp"] -->|"creates/reads"| B["KKW22501SFBean"]
    C["WEBGAMEN_KKW225010PJP.xml"] -->|"binds properties"| B
    B -->|"extends"| D["X33VViewBaseBean"]
    B -->|"implements"| E["X33VListedBeanInterface"]
    B -->|"implements"| F["X31CBaseBean"]
    B -->|"contains X33VDataTypeList"| G["dchskm_sete_jkn_list_list"]
    B -->|"contains X33VDataTypeList"| H["bf_dchskm_sete_jkn_list_list"]
    B -->|"contains X33VDataTypeList"| I["dchskm_list_list"]
    G -->|"element type"| J["KKW22501SF01DBean"]
    H -->|"element type"| J
    I -->|"element type"| K["KKW22501SF02DBean"]
```

**Inbound (2 consumers):**

- **`KKW225010PJP.jsp`** -- The JSP page that renders the screen. It instantiates the bean, reads field values via getters, and writes back submitted form data.
- **`WEBGAMEN_KKW225010PJP.xml`** -- An XML configuration file that binds screen properties to bean fields. This is the X33S framework's view-definition metadata that tells the framework which bean properties map to which UI components.

**Outbound (no direct code references):**

The bean has no direct code-level dependencies on other classes in its package, except through the framework base classes (`X33VViewBaseBean`, `X33VListedBeanInterface`, `X31CBaseBean`) and the child bean types it instantiates in `addListDataInstance` (`KKW22501SF01DBean`, `KKW22501SF02DBean`).

## Usage Example

A typical interaction cycle within an X33S JSP page:

```java
// 1. The JSP creates the bean
KKW22501SFBean bean = new KKW22501SFBean();

// 2. The framework populates values by string key
// (from XML config or POST data)
bean.storeModelData("検索フラグ", "value", "1");
bean.storeModelData("検索フラグ", "enable", Boolean.TRUE);
bean.storeModelData("検索ボタン使用可否", "value", "");

// 3. Adding a repeat row
int idx = bean.addListDataInstance("データ抽出項目設定条件一覧照会（イベントSP）詳細");

// 4. Setting data in the newly added row
bean.storeModelData("データ抽出項目設定条件一覧照会（イベントSP）詳細/" + idx + "/プロシ名前", "value", "MyProcedure");

// 5. Reading back values
Object value = bean.loadModelData("代理店コード", "value");
Class<?> type = bean.typeModelData("検索フラグ", "enable");  // returns Boolean.class

// 6. Removing a repeat row
bean.removeElementFromListData("データ抽出項目設定条件一覧照会（イベントSP）詳細", 0);

// 7. Getting JSF-selectable items
ArrayList<SelectItem> items = bean.getJsflist_typelist_dchskm_list();
```

## Notes for Developers

1. **Key routing is label-based, not property-name-based.** The `loadModelData` and `storeModelData` methods match on human-readable Japanese labels (the field's display name), not on the Java property name. If you rename a field in the bean but forget to update the label, the framework routing will silently fail (returning `null` or doing nothing).

2. **Three-level subkey convention:** Most scalar fields support `"value"` and `"state"` subkeys. Fields with enable/disable toggle support additionally have an `"enable"` subkey that returns/sets a `Boolean`. This is not documented in any interface -- it is an emergent convention from the implementation.

3. **Repeat list type coupling:** `dchskm_sete_jkn_list_list` and `bf_dchskm_sete_jkn_list_list` both hold `KKW22501SF01DBean` instances, while `dchskm_list_list` holds `KKW22501SF02DBean` instances. This coupling is enforced at runtime through casts -- there is no compile-time type safety since `X33VDataTypeList` uses raw types.

4. **No thread safety.** This bean is intended to be created per HTTP request (typical for JSP/JSF view beans). It has no synchronization and should not be shared across threads.

5. **Index-based navigation:** For repeat list access, the routing convention is `"<label>/<index>/<childKey>"`. The index must be a valid non-negative integer. Using `"*"` as the index returns the list size. Using an out-of-bounds index returns `null` without throwing an exception.

6. **Default initialization:** The `search_err_flg_zero_value` field defaults to `"1"` rather than `""` or `null`. This is likely an intentional default reflecting a "zero results error active" state. All other `_value` fields default to `""` (empty string), and `_enabled` flags default to `false`.

7. **`isSetAsString` flag:** The `storeModelData(key, subkey, in_value, isSetAsString)` overload exists to handle cases where a `Long`-typed field needs a string value set via property. When `true`, the framework will attempt a string-to-Long conversion. This flag is forwarded recursively to child beans.

8. **`listKoumokuIds` static delegation:** When querying field metadata for repeat list items, the method delegates to static `listKoumokuIds()` methods on the child bean classes (`KKW22501SF01DBean.listKoumokuIds()` and `KKW22501SF02DBean.listKoumokuIds()`). These must be static methods on those classes.

9. **`listServiceFormIds()` returns `null`:** This suggests the screen does not participate in any service-form composition. If new service forms are later associated with this screen, this method would need to be implemented to return their IDs.
