# FUW00943SF02DBean

## Purpose

`FUW00943SF02DBean` is a **data-transfer bean** (DTO) for a survey/enquete web view within the Fujitsu Futurity Web Client (X33) framework. It encapsulates all form-field state — values, enabled/disabled flags, UI states, and dirty-update markers — for a set of survey-related input controls, including text fields, radio buttons, and a dynamically-sized list of answer sub-items. It acts as the contract layer between the JSP view (`FUW009430PJP.jsp`) and the application logic, allowing data to be marshaled to and from the view using string-based key/subkey lookups rather than direct getter/setter calls.

This class exists to support a **dynamic survey-response UI** where the number of answer sub-entries can grow at runtime (via `addListDataInstance`), and each entry carries its own nested data bean (`FUW00943SF06DBean`).

## Design

`FUW00943SF02DBean` follows the **data-bound bean** pattern used throughout the X33/X31 framework. It implements three interfaces:

- **`X33VDataTypeBeanInterface`** — provides the `loadModelData`, `storeModelData`, and `typeModelData` methods that enable reflection-free, key-based data access. The framework uses these to bind page inputs to bean fields without knowing field names at compile time.
- **`X33VListedBeanInterface`** — provides list management methods (`addListDataInstance`, `removeElementFromListData`, `clearListDataInstance`) so the framework can manipulate variable-length collection fields from the view layer.
- **`Serializable`** — allows the bean to be stored in session scope or passed across layers.

The bean is **not immutable**. Fields are `protected` and have public getters/setters, allowing both the framework and subclasses to mutate state. The bean is **not thread-safe** — it holds mutable state and is intended for request-scoped or session-scoped use within a single-threaded web request.

Internally, the bean stores a flat collection of `FUW00943SF06DBean` objects inside an `X33VDataTypeList`. The "listed" interface methods delegate to this list, creating new `FUW00943SF06DBean` instances when adding entries.

### Inheritance

| Aspect | Value |
|---|---|
| Extends | `java.lang.Object` (implicit) |
| Implements | `X33VDataTypeBeanInterface`, `X33VListedBeanInterface`, `Serializable` |
| Framework base | `X33VViewBaseBean` (indirect, via interface contracts) |

### Key Fields

| Field | Type | Default | Purpose |
|---|---|---|---|
| `enquete_content_value` | `String` | `""` | Survey content text value |
| `enquete_content_enabled` | `Boolean` | `false` | Whether content field is editable |
| `enquete_content_state` | `String` | `""` | UI/state metadata for content |
| `enquete_content_update` | `String` | `null` | Dirty-flag: indicates content was updated by the user |
| `enquete_chk_sbt_value` | `String` | `""` | Check type value |
| `enquete_chk_sbt_enabled` | `Boolean` | `false` | Whether check field is editable |
| `enquete_chk_sbt_state` | `String` | `""` | UI state for check field |
| `enquete_chk_sbt_update` | `String` | `null` | Dirty-flag for check field |
| `enquete_content_no_value` | `String` | `""` | Survey number value |
| `enquete_content_no_enabled` | `Boolean` | `false` | Whether number field is editable |
| `enquete_content_no_state` | `String` | `""` | UI state for number field |
| `enquete_content_no_update` | `String` | `null` | Dirty-flag for number field |
| `dsp_jun_content_value` | `String` | `""` | Display ordering value |
| `dsp_jun_content_enabled` | `Boolean` | `false` | Whether display order is editable |
| `dsp_jun_content_state` | `String` | `""` | UI state for display order |
| `dsp_jun_content_update` | `String` | `null` | Dirty-flag for display order |
| `radio_value_value` | `String` | `"1"` | Radio button selected value |
| `radio_value_enabled` | `Boolean` | `true` | Whether radio button is editable |
| `radio_value_state` | `String` | `""` | UI state for radio button |
| `radio_value_update` | `String` | `null` | Dirty-flag for radio button |
| `enquete_answer_list_list` | `X33VDataTypeList` | (new empty list in constructor) | Container for dynamic answer entries |
| `index` | `int` | `0` | Index of the currently selected/focused row |

Every text-like field follows a **four-property pattern**:
1. `{name}_value` — the actual data value
2. `{name}_enabled` — whether the field is editable
3. `{name}_state` — UI state metadata (CSS class, visibility hint)
4. `{name}_update` — dirty-flag indicating the user modified the field on the current request

### Property Keys (Japanese Labels)

The model-data methods use Japanese-language property keys as dispatch identifiers:

| Property Key (Japanese) | Internal ID | UI Purpose |
|---|---|---|
| `アンケート内容` | `enquete_content` | Survey question content |
| `アンケートチェック種類` | `enquete_chk_sbt` | Survey check/response type |
| `アンケート番号` | `enquete_content_no` | Survey response number |
| `表示順序（アンケート内容）` | `dsp_jun_content` | Display order for content |
| `ラジオボタン選択値` | `radio_value` | Radio button selected value |
| `アンケート回答リスト` | `enquete_answer_list` | Dynamic list of answer entries |

## Key Methods

### `loadModelData(String key, String subkey) → Object`

Retrieves a property value by string key and subkey. This is the primary **data-read** method used by the X33 framework to bind values to JSP UI components.

- **`key`** — one of the Japanese property labels listed above (or a hierarchical key like `"アンケート回答リスト/0/プロン名"` for list entries)
- **`subkey`** — `"value"`, `"enable"`, or `"state"` (case-insensitive). For list keys, subkey is passed through to the nested bean.
- **Returns** — the current value of the property. Returns `null` if the key/subkey combination is not recognized or if bounds checking fails.

**Dispatch logic:**
1. For flat fields (content, check type, number, display order, radio), the method matches `key` against the six known property names and returns the corresponding value/enable/state field.
2. For the list field (`"アンケート回答リスト"`), it parses the key as a hierarchical path: `"アンケート回答リスト/{index}/{property}"`. If the key remainder is `"*"`, it returns the **list size** as an `Integer`. Otherwise, it parses the index, validates it's in bounds, and delegates to `loadModelData` on the `FUW00943SF06DBean` element at that index.
3. If no property matches, it returns `null`.

### `storeModelData(String gamenId, String key, String subkey, Object in_value)`

A convenience overload that forwards to the three-argument version, accepting an unused `gamenId` parameter (game ID from the X33 framework).

### `storeModelData(String key, String subkey, Object in_value)`

Delegates to the four-argument version with `isSetAsString = false`.

### `storeModelData(String key, String subkey, Object in_value, boolean isSetAsString) → void`

The primary **data-write** method. Mirrors the dispatch logic of `loadModelData` but invokes the appropriate setter instead of a getter.

- **`key`** — same property keys as `loadModelData`.
- **`subkey`** — `"value"`, `"enable"`, or `"state"`.
- **`in_value`** — the value to set. Cast to the expected type (`String` or `Boolean`).
- **`isSetAsString`** — a flag (unused in the current method body) that appears to be reserved for future Long-type string conversion logic.

**Dispatch logic:**
1. For flat fields, the method matches `key` and calls the corresponding setter (e.g., `setEnquete_content_value` for value, `setEnquete_content_enabled` for enable, `setEnquete_content_state` for state).
2. For list fields, it parses the hierarchical key to extract the index and the remaining property key, validates the index, and delegates to `storeModelData` on the nested `FUW00943SF06DBean` element.

**Important:** The method does **not** validate types before casting — if `in_value` is the wrong type, a `ClassCastException` will be thrown. Callers are expected to provide correctly typed values.

### `typeModelData(String key, String subkey) → Class<?>`

Returns the **Java type** of a property, enabling type-safe data binding by the framework.

- **`key`** — same property keys as above.
- **`subkey`** — `"value"`, `"enable"`, or `"state"`.
- **Returns** — `String.class` for value/state fields, `Boolean.class` for enable fields, `Integer.class` for list count (when key remainder is `"*"`), or `null` if the subkey is not recognized or the index is out of bounds.

The dispatch logic mirrors `loadModelData` and `storeModelData` exactly. For list entries, it delegates to the nested bean's `typeModelData` method.

### `listKoumokuIds() → ArrayList<String>`

A **static** method that returns the complete list of recognized property keys (the six Japanese labels). This allows the framework to enumerate all valid properties on the bean. Returns:

```
["アンケート内容", "アンケートチェック種類", "アンケート番号", "表示順序（アンケート内容）", "ラジオボタン選択値", "アンケート回答リスト"]
```

### `addListDataInstance(String key) → int`

Creates a new element in the specified list field and returns its index.

- **`key`** — must be `"アンケート回答リスト"`.
- **Returns** — the index of the newly added element (i.e., `size - 1`). Returns `-1` if the key is `null` or unrecognized.
- **Side effects** — initializes `enquete_answer_list_list` if it's `null`, creates a new `FUW00943SF06DBean` instance, and adds it to the list.
- **Throws** — `X33SException` (declared but not explicitly thrown in the current body).

This is the primary method for **dynamically growing** the survey answer list from the view layer.

### `removeElementFromListData(String key, int index) → void`

Removes an element from the specified list at the given index.

- **`key`** — must be `"アンケート回答リスト"`.
- **`index`** — the zero-based position to remove.
- **Side effects** — removes the element from `enquete_answer_list_list` if the index is within bounds. Does nothing if the key is `null`, unrecognized, or the index is out of range.
- **Throws** — `X33SException` (declared but not explicitly thrown).

### `clearListDataInstance(String key) → void`

Removes all elements from the specified list.

- **`key`** — must be `"アンケート回答リスト"`.
- **Side effects** — calls `enquete_answer_list_list.clear()`. Does nothing if the key is `null` or unrecognized.
- **Throws** — `X33SException` (declared but not explicitly thrown).

### `getJsflist_typelist_enquete_answer_list() → ArrayList<SelectItem>`

A **view-assistance method** that converts the answer list into JSF `SelectItem` objects. Iterates over the list, reads each entry's `"value"` property via `loadModelData`, and creates a `SelectItem` where the value is the list index (as a string) and the label is the answer's text value. This is used to render a dropdown or select box showing all current answer entries.

### `getIndex() / setIndex(int)`

Tracks the index of the currently selected or focused row in the dynamic list. Used by the JSP to maintain selection state across postbacks.

## Relationships

### Class Diagram

```mermaid
classDiagram
  FUW00943SF02DBean --> FUW00943SF06DBean : contains (list of)
  FUW00943SF02DBean ..|> X33VDataTypeBeanInterface : implements
  FUW00943SF02DBean ..|> X33VListedBeanInterface : implements
  FUW00943SF02DBean ..|> Serializable : implements

  X33VDataTypeBeanInterface <|-- FUW00943SF06DBean
  FUW00943SF06DBean <|-- X33VViewBaseBean
```

### Dependency Summary

```mermaid
flowchart LR
  FUW009430PJP["FUW009430PJP.jsp
(view)"] --> FUW00943SF02DBean["FUW00943SF02DBean
(data bean)"]
  FUW00943SF02DBean --> FUW00943SF06DBean["FUW00943SF06DBean
(nested entry bean)"]
  FUW00943SF02DBean --> X33VDataTypeList["X33VDataTypeList
(list container)"]
  FUW00943SF02DBean --> X33VListedBeanInterface["X33VListedBeanInterface
(interface)"]
  FUW00943SF02DBean --> X33VDataTypeBeanInterface["X33VDataTypeBeanInterface
(interface)"]
  SelectItem["javax.faces.model.SelectItem"] -.-> FUW00943SF02DBean
```

### Inbound Dependencies

| Consumer | Usage |
|---|---|
| `FUW009430PJP.jsp` | References this bean to bind survey form fields, read/write values, and manage the dynamic answer list. |
| X33 framework (indirect) | Uses `loadModelData`, `storeModelData`, `typeModelData`, `addListDataInstance`, `removeElementFromListData`, and `clearListDataInstance` for generic data binding. |

### Outbound Dependencies

| Dependency | Usage |
|---|---|
| `FUW00943SF06DBean` | Created as list elements in `addListDataInstance`; each element is a nested data bean carrying its own survey answer sub-fields. |
| `X33VDataTypeList` | Generic list container for the answer entries. |
| `X33VDataTypeBeanInterface` | Implemented by nested beans; enables recursive `loadModelData`/`storeModelData` delegation. |
| `X33VListedBeanInterface` | Implemented by nested beans; enables recursive list management. |
| `X33SException` | Thrown (declared) by the listed-bean management methods. |

## Usage Example

The typical lifecycle of this bean spans a single web request:

1. **Creation** — The JSP creates or retrieves the bean from session/request scope. The constructor initializes `enquete_answer_list_list` to an empty list.

2. **Pre-population** — If this is a page re-render (not the initial load), the logic layer (`FUW00943SFLogic.java`) calls `storeModelData` to restore field values from the database or session. The framework uses the Japanese property keys as dispatch identifiers:

   ```
   bean.storeModelData("アンケート内容", "value", "Some survey question text");
   bean.storeModelData("アンケート内容", "enable", true);
   bean.storeModelData("ラジオボタン選択値", "value", "2");
   ```

3. **Dynamic list management** — When the user adds answer entries, the framework (or the JSP via Ajax) calls `addListDataInstance("アンケート回答リスト")`, which creates a new `FUW00943SF06DBean` and returns its index. Values for individual list entries are set using hierarchical keys:

   ```
   bean.storeModelData("アンケート回答リスト/0/プロン名", "value", "First answer");
   ```

4. **User submission** — On form submit, the framework iterates over all properties via `listKoumokuIds()`, calling `loadModelData` for each property/subkey pair to collect user-entered values. Dirty-flag fields (the `*_update` properties) indicate which fields the user actually modified.

5. **Validation and processing** — The logic layer reads the bean state via getters and the model-data methods, validates the data, and persists it.

6. **List cleanup** — If entries are removed, `removeElementFromListData` or `clearListDataInstance` is called to adjust the list.

## Notes for Developers

### Property Key Sensitivity
All dispatch logic relies on exact string equality checks (`String.equals`) for the Japanese property keys. A single character mismatch — especially in the full-width parentheses in `表示順序（アンケート内容）` — will cause the dispatch to fall through and return `null` or do nothing silently. Do not rename these keys without updating all three methods (`loadModelData`, `storeModelData`, `typeModelData`) plus `listKoumokuIds` and any callers.

### Null-Safety
- `loadModelData` returns `null` for unrecognized keys, null inputs, or out-of-bounds list indices. Callers must handle `null` returns.
- `storeModelData` silently returns for null keys/subkeys without throwing. No error is logged.
- `enquete_answer_list_list` is initialized in the constructor, but it can still be set to `null` via its setter. Subsequent list operations would NPE if this happens.

### Type Safety in `storeModelData`
The method performs unchecked casts: `(String)in_value` and `(Boolean)in_value`. Passing an incompatible type will throw `ClassCastException`. There is no type validation before the cast. The `typeModelData` method exists to help callers check types before calling `storeModelData`, but there is no enforcement.

### The `isSetAsString` Flag
The four-argument `storeModelData` accepts an `isSetAsString` boolean that is accepted but not used in the current body. It appears to be a reserved parameter for future Long-type string conversion support. It does not affect current behavior.

### List Index Handling
The hierarchical key parsing for list entries (`"アンケート回答リスト/{index}/{property}"`) uses `Integer.valueOf()` with a try-catch for `NumberFormatException`. Non-numeric indices are silently treated as no-match (returns `null` from `loadModelData`, does nothing from `storeModelData`).

### Thread Safety
This bean is **not thread-safe**. It holds mutable state (fields, list contents) and has no synchronization. It is designed for single-request scope. Never share an instance across threads.

### The `update` Fields
Each property group has a corresponding `*_update` field (e.g., `enquete_content_update`). These are set to `null` by default and appear to be set elsewhere (likely by the X33 framework's form binding layer) to indicate that the user modified the field during the current request. They can be used to detect dirty fields for partial updates or change tracking.

### `radio_value_value` Default
The radio button value defaults to `"1"` rather than `""`. This suggests the UI always expects a radio selection and the framework may pre-select the first option by default.

### `X33VViewBaseBean` and `X31CBaseBean`
The bean imports both `X33VViewBaseBean` and `X31CBaseBean` but does not extend either directly. These are base framework classes that provide common infrastructure (lifecycle, context access) — this bean's inheritance is purely through interface implementation, not class inheritance.
