# Business Logic — KKW14901SFLogic.afterSearch() [80 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW14901SF.KKW14901SFLogic` |
| Layer | Controller |
| Module | `KKW14901SF` (Package: `eo.web.webview.KKW14901SF`) |

## 1. Role

### KKW14901SFLogic.afterSearch()

This method implements **post-search processing** for the "Phone Number Absence Advance Notice" screen (番ポなし番号事前通知 — advance notification for telephone numbers not yet registered in the system). After the search service interface (`BmpNonNoPreTchiReSearchCC`) executes and returns results in `outputMap`, this method determines whether search results are displayable and, if so, prepares the data for list presentation on the UI.

The method handles **three search result states** via conditional branching on the search error flag: (1) zero results (flag = "1") — displays an informational message and short-circuits to prevent empty list rendering; (2) results exceeding the maximum display count (flag = "2") — displays an error message with the configurable max count threshold and short-circuits; (3) no data found (flag = "3") — displays an informational message but **continues** processing to allow the empty list to render (preserving the table structure on the UI).

When processing continues, the method applies a **page link info downmapper** to reconstruct pagination links for the search result page, resets the search command to the paging action, toggles the list display flag to true to activate the list view, and restores the previously selected row by matching the stored KANUORESO_HAKKO_NO (加加入御礼書発行番号 — acknowledgment receipt issue number) against each row. It also applies alternating row styles (odd/even CSS classes) for visual stripe formatting.

In the larger system, `afterSearch()` serves as the **final assembly step** in the search command chain. It is called by `actionInit()` (initial load) and `execSearch()` (search execution) within `KKW14901SFLogic`, ensuring the list view is always in a consistent state after any search operation. It follows a **delegation pattern**, relying on `JCCWebCommon` for web-layer utilities and `OneStopDataBeanAccess` for data bean manipulation, keeping the logic method focused and testable.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["afterSearch bean outputMap"])
    CHECK_ERR["Get search error flag from outputMap"]
    COND_ERR{Search error flag?}
    ZERO_FLG["Flag = 0 results / no error"]
    MSG0["Set error message EKB0330__I"]
    RET0["Return skip remaining processing"]
    OVERMAX_FLG["Flag = exceeded max results"]
    MSG1["Set error message EKB0340__I with max count"]
    RET1["Return skip remaining processing"]
    NODATA_FLG["Flag = no data found"]
    MSG2["Set message EKB0350__I"]
    CONTINUE["Continue to processing"]
    DLMAP["Downmapper page link info"]
    SETCMD["Set search command to paging"]
    SETLIST["Set list display flag to true"]
    SETCHOICE["Set default choice row to 0"]
    GETBF["Get previous choice KANUORESO_HAKKO_NO"]
    GETLIST["Get search result list as data bean array"]
    LOOP_START["For each item in list"]
    GETROW["Get dataBean at index i"]
    GETKANU["Get KANUORESO_HAKKO_NO_02 from dataBean"]
    MATCH{Kanuroso number matches?}
    UPDATE_CHOICE["Update choice row to i"]
    SKIP_CHOICE["No update to choice"]
    ODDSTYLE{Is i+1 odd?}
    SET_ODD["Set row style to odd"]
    SET_EVEN["Set row style to even"]
    LOOP_END{More items?}
    DONE(["End method"])

    START --> CHECK_ERR
    CHECK_ERR --> COND_ERR
    COND_ERR -->|"SEARCH_ERR_FLG_ZERO = 1"| ZERO_FLG
    ZERO_FLG --> MSG0
    MSG0 --> RET0
    COND_ERR -->|"SEARCH_ERR_FLG_OVERMAX = 2"| OVERMAX_FLG
    OVERMAX_FLG --> MSG1
    MSG1 --> RET1
    COND_ERR -->|"SEARCH_ERR_FLG_NODATA = 3"| NODATA_FLG
    NODATA_FLG --> MSG2
    MSG2 --> CONTINUE
    CONTINUE --> DLMAP
    DLMAP --> SETCMD
    SETCMD --> SETLIST
    SETLIST --> SETCHOICE
    SETCHOICE --> GETBF
    GETBF --> GETLIST
    GETLIST --> LOOP_START
    LOOP_START --> GETROW
    GETROW --> GETKANU
    GETKANU --> MATCH
    MATCH -->|Yes| UPDATE_CHOICE
    MATCH -->|No| SKIP_CHOICE
    UPDATE_CHOICE --> ODDSTYLE
    SKIP_CHOICE --> ODDSTYLE
    ODDSTYLE -->|Yes| SET_ODD
    ODDSTYLE -->|No| SET_EVEN
    SET_ODD --> LOOP_END
    SET_EVEN --> LOOP_END
    LOOP_END -->|Yes| LOOP_START
    LOOP_END -->|No| DONE
    RET0 --> DONE
    RET1 --> DONE
```

**Branch summary:**

| Condition | Constant | Constant Value | Business Meaning | Behavior |
|-----------|----------|----------------|------------------|----------|
| `JPCModelConstant.SEARCH_ERR_FLG_ZERO.equals(search_err_flg)` | `SEARCH_ERR_FLG_ZERO` | `"1"` | Search returned 0 results (normal empty, not an error) | Display info message `EKB0330__I`, return early |
| `JPCModelConstant.SEARCH_ERR_FLG_OVERMAX.equals(search_err_flg)` | `SEARCH_ERR_FLG_OVERMAX` | `"2"` | Results exceed maximum display threshold | Display info message `EKB0340__I` with max count, return early |
| `JPCModelConstant.SEARCH_ERR_FLG_NODATA.equals(search_err_flg)` | `SEARCH_ERR_FLG_NODATA` | `"3"` | No data found in search | Display info message `EKB0350__I`, continue processing to show empty list |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `bean` | `X31SDataBeanAccess` | The service form data bean that holds the current screen state. Provides access to list data beans (search results), message communication for reading/writing UI state values (e.g., row choice, display flags, previous row selection), and data bean array retrieval for iterating search results. |
| 2 | `outputMap` | `HashMap<String, Object>` | The business data map returned from the AP server's search processing. Contains the search result data and the search error flag (`"BmpNonNoPreTchiReSearchCC"`). The error flag is read to determine if results are displayable, and the search result list data is stored in this map. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `PAGING_CMD` | `String` | The search command value `"paging"` used to set the active search command for pagination control. |

**Constant values resolved:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `JPCModelConstant.SEARCH_ERR_FLG_ZERO` | `"1"` | No results returned from search (0 rows) |
| `JPCModelConstant.SEARCH_ERR_FLG_OVERMAX` | `"2"` | Search results exceed maximum allowed display count |
| `JPCModelConstant.SEARCH_ERR_FLG_NODATA` | `"3"` | No data found matching search criteria |
| `KKW14901SFConst.LIST_DISP_FLG` | `"一覧表示フラグ"` (List Display Flag) | Flag key for enabling/disabling the list table on screen |
| `KKW14901SFConst.BMPNONNOPRETCHI_CHOICE` | `"番ポなし番号事前通知選択行"` (Phone Number Absence Advance Notice Selection Row) | Key for the currently selected row index in the results list |
| `KKW14901SFConst.KANUORESO_HAKKO_NO` | `"加入御礼書発行番号"` (Acknowledgment Receipt Issue Number) | Key for the previously selected acknowledgment receipt number |
| `KKW14901SFConst.BMPNONNOPRETCHI_LIST` | `"番ポなし番号事前通知一覧"` (Phone Number Absence Advance Notice List) | Key for the search result list data bean array |
| `KKW14901SFConst.KANUORESO_HAKKO_NO_02` | `"加入御礼書発行番号"` (Acknowledgment Receipt Issue Number) | Key for the acknowledgment receipt number in each list row |
| `KKW14901SFConst.ROW_STYLE_02` | `"行スタイル"` (Row Style) | Key for the CSS row style (odd/even) on each list row |
| `JKKScreenConst.SCREEN_ID_KKW14901` | `"KKW14901"` | Screen identifier used for page link info management |
| `PAGING_CMD` | `"paging"` | Search command identifier for pagination actions |
| `X31CWebConst.DATABEAN_SET_VALUE` | `"SET_VALUE"` | Mode flag for writing a value to a data bean |
| `X31CWebConst.DATABEAN_GET_VALUE` | `"GET_VALUE"` | Mode flag for reading a value from a data bean |
| `JTUStrConst.ROW_STYLE_ODD` | `"odd"` | CSS class for alternating odd row styling |
| `JTUStrConst.ROW_STYLE_EVEN` | `"even"` | CSS class for alternating even row styling |
| `JPCOnlineMessageConstant.EKB0330__I` | — | Informational message: "Search result is 0 records" |
| `JPCOnlineMessageConstant.EKB0340__I` | — | Informational message: "Exceeded maximum display count" (with parameterized count) |
| `JPCOnlineMessageConstant.EKB0350__I` | — | Informational message: "No data to display on this page" |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JCCWebCommon.setMessageInfo` | - | - | Sets a message (error/info) in the display area. Called with error flag = 0 (EKB0330__I) and with error flag = exceeded max (EKB0340__I). |
| - | `JCCWebCommon.setMessageInfo` | - | - | Sets informational message EKB0350__I when no data found (flag = 3). Displayed but processing continues. |
| R | `JCCWebCommon.getSearchErrFlg` | JCCWebCommon | - | Retrieves the search error flag from the outputMap keyed by `"BmpNonNoPreTchiReSearchCC"`. The flag value determines whether results are displayable. |
| R | `JCCWebCommon.getSearchConst` | JCCWebCommon | - | Retrieves the maximum display count constant `KKW14901_MAX_SHOW_CNT` used as a parameter in the exceeded-count error message. |
| - | `JCCWebCommon.downmapperPageLinkInfo` | JCCWebCommon | - | Downmappers pagination link info for the search result page, reconstructing page navigation controls using screen ID `"KKW14901"`. |
| - | `JCCWebCommon.setSearchCommand` | JCCWebCommon | - | Sets the current search command to `"paging"` for subsequent pagination actions. |
| - | `bean.sendMessageBoolean` | - | - | Sets the list display flag to `true`, activating the list table view on the UI. |
| - | `bean.sendMessageString` | - | - | Sets the default row choice index to `"0"` (first row). |
| - | `bean.sendMessageString` | - | - | Sets the row style CSS class (`"odd"` or `"even"`) for each list row to enable alternating row shading. |
| - | `bean.sendMessageString` | - | - | Writes the selected row index to the choice data bean when the previous acknowledgment receipt number is matched. |
| R | `bean.sendMessageString` | - | - | Reads the previously selected acknowledgment receipt number (KANUORESO_HAKKO_NO) to restore row selection after re-search. |
| R | `bean.sendMessageString` | - | - | Reads the acknowledgment receipt number (KANUORESO_HAKKO_NO_02) from each list row for matching against the previous selection. |
| R | `bean.getDataBeanArray` | - | - | Retrieves the search result list as an `X31SDataBeanAccessArray` for iteration over all rows. |
| R | `datalist.getCount` | - | - | Returns the total number of rows in the search result list, controlling loop iteration count. |
| R | `datalist.getDataBean` | - | - | Retrieves the individual data bean at index `i` for processing within the loop. |

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `KKW14901SFLogic.actionInit()` | `actionInit()` -> `afterSearch(bean, outputMap)` | `getSearchErrFlg [R]`, `setMessageInfo [-]`, `downmapperPageLinkInfo [-]`, `setSearchCommand [-]`, `sendMessageBoolean [-]`, `sendMessageString [-]`, `getDataBeanArray [R]`, `getCount [R]`, `getDataBean [R]` |
| 2 | `KKW14901SFLogic.execSearch()` | `execSearch()` -> `afterSearch(bean, outputMap)` | `getSearchErrFlg [R]`, `setMessageInfo [-]`, `getSearchConst [R]`, `downmapperPageLinkInfo [-]`, `setSearchCommand [-]`, `sendMessageBoolean [-]`, `sendMessageString [-]`, `getDataBeanArray [R]`, `getCount [R]`, `getDataBean [R]` |

**Notes:**
- `actionInit()` — Called during initial screen load. Invokes `afterSearch()` to populate the list with initial search results (or show empty state).
- `execSearch()` — Called when the user submits a search condition. Invokes `afterSearch()` after the search service returns to prepare results for display.
- No external screen entry points (KKSV*) or CBS (Command-by-Service) chains route through this method. It is an internal logic method within `KKW14901SFLogic`.
- Terminal operations reach no database tables directly; all reads originate from in-memory data beans populated by the prior search service call.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `JPCModelConstant.SEARCH_ERR_FLG_ZERO.equals(search_err_flg)` [SEARCH_ERR_FLG_ZERO="1"] (L953)

> Retrieves the search error flag from the outputMap. The flag value indicates the search result state.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `String search_err_flg = JCCWebCommon.getSearchErrFlg("BmpNonNoPreTchiReSearchCC", outputMap)` // Get search error flag from search result info // [BmpNonNoPreTchiReSearchCC = search service key] |

**Block 2** — [IF] `JPCModelConstant.SEARCH_ERR_FLG_ZERO.equals(search_err_flg)` [SEARCH_ERR_FLG_ZERO="1"] (L956)

> Branch for zero results. Per the Javadoc (検索結果が0件の場合 — When search results are 0 records), the result column is not displayed. An informational message is set and the method returns early, skipping all remaining list preparation logic.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCCWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB0330__I)` // Set error message for 0 results // [EKB0330__I = informational message for empty search results] |
| 2 | RETURN | `return;` // 後処理は実施しない (Do not implement subsequent processing) |

**Block 3** — [ELSE-IF] `JPCModelConstant.SEARCH_ERR_FLG_OVERMAX.equals(search_err_flg)` [SEARCH_ERR_FLG_OVERMAX="2"] (L961)

> Branch for results exceeding maximum count. Per the Javadoc (検索結果が最大検索件数超えの場合 — When search results exceed max search count), the result column is not displayed. The method retrieves the configured maximum display count and passes it as a parameter to the error message, then returns early.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCCWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB0340__I, new String[]{JCCWebCommon.getSearchConst("KKW14901_MAX_SHOW_CNT")})` // Set error message with max display count parameter // [EKB0340__I = exceeded max results, KKW14901_MAX_SHOW_CNT = configurable max row count] |
| 2 | RETURN | `return;` // 後処理は実施しない (Do not implement subsequent processing) |

**Block 4** — [ELSE-IF] `JPCModelConstant.SEARCH_ERR_FLG_NODATA.equals(search_err_flg)` [SEARCH_ERR_FLG_NODATA="3"] (L967)

> Branch for no data found. Per the Javadoc (表示ページに該当するデータなし — No data matching on display page), an informational message is displayed. Critically, the method does NOT return — processing continues to render the empty list table structure on the UI, preserving the visual layout.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCCWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB0350__I)` // Set message for no data on this page // [EKB0350__I = no matching data for display] |
| 2 | — | (No return; processing continues) // 後処理を実施すべし (Implement subsequent processing) |

**Block 5** — [SEQUENCE] Post-error-flag processing (L975)

> After all error flag checks pass (including the continue-on-nodata case), this block prepares the UI state for list display. It reconstructs pagination links, resets the search command, activates the list view, sets a default row selection, and retrieves the previously selected row identifier.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCCWebCommon.downmapperPageLinkInfo(this, "BmpNonNoPreTchiReSearchCC", outputMap, JKKScreenConst.SCREEN_ID_KKW14901)` // ページング情報下りマッピング (Page link info downmapper) // [SCREEN_ID_KKW14901 = "KKW14901"] |
| 2 | EXEC | `JCCWebCommon.setSearchCommand(this, PAGING_CMD)` // ページングのコマンドマッブIDを設定 (Set paging command mapping ID) // [PAGING_CMD = "paging"] |
| 3 | EXEC | `bean.sendMessageBoolean(KKW14901SFConst.LIST_DISP_FLG, X31CWebConst.DATABEAN_SET_VALUE, true)` // 一覧表示フラグの設定 (Set list display flag) // [LIST_DISP_FLG = "一覧表示フラグ", true = enable list view] |
| 4 | EXEC | `bean.sendMessageString(KKW14901SFConst.BMPNONNOPRETCHI_CHOICE, X31CWebConst.DATABEAN_SET_VALUE, "0")` // 行選択のデフォルト設定 (Set default row selection) // [BMPNONNOPRETCHI_CHOICE = 番ポなし番号事前通知選択行, "0" = first row] |
| 5 | SET | `String kanuoreso_hakko_no_bf = bean.sendMessageString(KKW14901SFConst.KANUORESO_HAKKO_NO, X31CWebConst.DATABEAN_GET_VALUE)` // 前回選択していた加入御礼書発行番号を取得 (Get previously selected acknowledgment receipt issue number) // [KANUORESO_HAKKO_NO = 加入御礼書発行番号] |
| 6 | SET | `X31SDataBeanAccessArray datalist = bean.getDataBeanArray(KKW14901SFConst.BMPNONNOPRETCHI_LIST)` // 検索結果一覧を取得 (Get search result list) // [BMPNONNOPRETCHI_LIST = 番ポなし番号事前通知一覧] |

**Block 6** — [FOR LOOP] `for (int i = 0; i < datalist.getCount(); i++)` (L981)

> Iterates over all rows in the search result list. For each row, two operations are performed: (1) matching the row's acknowledgment receipt number against the previously selected number to restore row selection, and (2) applying alternating CSS row styles for visual stripe formatting.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X31SDataBeanAccess dataBean = datalist.getDataBean(i)` // Get data bean at current index |
| 2 | SET | `String kanuoreso_hakko_no = dataBean.sendMessageString(KKW14901SFConst.KANUORESO_HAKKO_NO_02, X31CWebConst.DATABEAN_GET_VALUE)` // 加入御礼書番号を取得 (Get acknowledgment receipt number for this row) // [KANUORESO_HAKKO_NO_02 = 加入御礼書発行番号] |

**Block 6.1** — [IF] `kanuoreso_hakko_no_bf != null && kanuoreso_hakko_no_bf.equals(kanuoreso_hakko_no)` (L987)

> Checks if the current row's acknowledgment receipt number matches the previously selected number. Per the code comment (検索結果に同一加入御礼書発行番号の情報が存在する場合、該当のインデックス番号で選択行を更新 — When information with the same acknowledgment receipt issue number exists in search results, update the selection row with the corresponding index number), if there is a match, that row becomes the active selection.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `bean.sendMessageString(KKW14901SFConst.BMPNONNOPRETCHI_CHOICE, X31CWebConst.DATABEAN_SET_VALUE, String.valueOf(i))` // 選択行を更新 (Update selection row to index i) // [BMPNONNOPRETCHI_CHOICE = 番ポなし番号事前通知選択行] |

**Block 6.2** — [IF-ELSE] `(i + 1) % 2 == 1` (L997)

> Alternating row style assignment for visual stripe formatting. Per the code comments (奇数行 = odd row, 偶数行 = even row), odd-numbered rows (1st, 3rd, 5th...) receive the `"odd"` CSS class and even-numbered rows (2nd, 4th, 6th...) receive the `"even"` CSS class.

| # | Type | Code |
|---|------|------|
| 1 | [IF TRUE: 奇数行 (odd row)] | `dataBean.sendMessageString(KKW14901SFConst.ROW_STYLE_02, X31CWebConst.DATABEAN_SET_VALUE, ROW_STYLE_ODD)` // [ROW_STYLE_02 = 行スタイル, ROW_STYLE_ODD = "odd"] |
| 2 | [IF FALSE: 偶数行 (even row)] | `dataBean.sendMessageString(KKW14901SFConst.ROW_STYLE_02, X31CWebConst.DATABEAN_SET_VALUE, ROW_STYLE_EVEN)` // [ROW_STYLE_EVEN = "even"] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| 番ポなし番号事前通知 (BmpNonNoPreTchi) | Domain term | Phone Number Absence Advance Notice — a notification service for telephone numbers not yet registered in the system, proactively notifying subscribers of upcoming service availability |
| BMPNONNOPRETCHI | Constant | Abbreviated key for "Ban Pointer Nashi Bangou Jizen Tsuchi" — internal key naming for phone number absence advance notice entities |
| 加入御礼書発行番号 (KANUORESO_HAKKO_NO) | Field | Acknowledgment Receipt Issue Number — unique identifier for the welcome/acknowledgment letter issued upon service subscription |
| LIST_DISP_FLG | Constant | List Display Flag — UI flag that toggles the visibility of the search results table on screen |
| 一覧表示フラグ | Field name | Japanese label for LIST_DISP_FLG |
| 選択行 (CHOICE) | Field concept | Selected Row — the currently highlighted/selected row index in the results list table |
| 行スタイル (ROW_STYLE) | Field concept | Row Style — CSS class applied to list rows for alternating visual stripe formatting |
| BmpNonNoPreTchiReSearchCC | CC / Service Component | Ban Pointer Nashi Bangou Jizen Tsuchi Re-Search Common Component — the search service component that executes the phone number absence advance notice search query |
| SEARCH_ERR_FLG_ZERO | Constant | Search error flag value `"1"` — indicates search returned zero results (normal empty state) |
| SEARCH_ERR_FLG_OVERMAX | Constant | Search error flag value `"2"` — indicates search results exceed the maximum configurable display count |
| SEARCH_ERR_FLG_NODATA | Constant | Search error flag value `"3"` — indicates no data matching the search criteria was found |
| EKB0330__I | Constant | Informational message code — displayed when search returns 0 results |
| EKB0340__I | Constant | Informational message code — displayed when results exceed maximum display count (parameterized with max count value) |
| EKB0350__I | Constant | Informational message code — displayed when no data matches search criteria on the page |
| downmapperPageLinkInfo | Method | Pagination link reconstruction utility — rebuilds page navigation controls (page links) for the search result UI after search |
| setSearchCommand | Method | Sets the active search command for the page, routing subsequent user actions to the correct handler |
| PAGING_CMD | Constant | `"paging"` — the search command identifier used to route pagination-related user actions |
| SCREEN_ID_KKW14901 | Constant | `"KKW14901"` — unique screen identifier for the phone number absence advance notice screen |
| X31SDataBeanAccess | Type | Service form data bean — the primary data container for screen state, providing get/set operations for all display fields and list data |
| X31SDataBeanAccessArray | Type | Array wrapper for multiple data beans — represents the list of search results, each element being an individual row's data bean |
| OneStopDataBeanAccess | Type | Unified data bean access interface — base interface for all data bean operations in the OneStop framework |
