# Javax / Faces

## Overview

The `javax.faces` package sits at the core of the JavaServer Faces (JSF) framework — a component-based web application framework for building Java EE web UIs. It provides the foundational APIs and runtime infrastructure that enable developers to construct server-driven, event-driven web applications with a model-view-controller (MVC) architecture.

This package appears as a top-level grouping within the Java EE web stack, serving as the root namespace for all JSF-related types. While the package itself contains no directly indexed source files or classes of its own, it is organized as a parent for functional subpackages — most notably `javax.faces.webapp`, which handles the servlet-level entry point for JSF request processing.

The framework's primary responsibility is to map HTTP requests into a structured component lifecycle, where each request flows through a well-defined series of phases: restoring the view, applying request values, processing validations, updating the model, invoking application logic, and rendering the response. This phased approach gives developers fine-grained control over request processing while abstracting away much of the low-level HTTP handling.

## Sub-module Guide

The `javax.faces` package delegates its functionality to the following sub-packages:

### `javax.faces.webapp`

This sub-package provides the servlet integration layer for JSF. Its centerpiece is `FacesServlet`, which acts as the entry point for all JSF requests within a web application.

**What it does:**
- Receives HTTP requests mapped via URL patterns (commonly `*.xhtml` or `/faces/*`).
- Orchestrates the six-phase JSF lifecycle for each request.
- Manages request context, view state, and component tree rendering.

**How it fits in:**
The `webapp` sub-package is the bridge between the standard Java Servlet API and the JSF-specific framework. Without it, the JSF lifecycle would have no way to intercept and process incoming HTTP traffic. All JSF-based web applications must deploy `FacesServlet` as a configured servlet in their `web.xml`.

**Relationship to the parent:**
The `javax.faces` package defines the core framework abstractions (lifecycles, contexts, component models), while `javax.faces.webapp` implements the web-layer adapter that makes those abstractions accessible over HTTP.

## Key Patterns and Architecture

### The JSF Request Lifecycle

At the heart of this package is the six-phase request lifecycle. Every JSF request follows the same progression:

```mermaid
flowchart TD
    subgraph REQUEST["Request Pipeline"]
        C1["Client Request"] --> CF["EncodingFilter"]
        CF --> FS["FacesServlet"]
    end
    subgraph LIFECYCLE["JSF Lifecycle"]
        FS --> LV["1. Restore View"]
        LV --> ARV["2-4. Apply Values, Validate, Update Model"]
        ARV --> IA["5. Invoke Application"]
        IA --> RR["6. Render Response"]
    end
    subgraph INFRA["Infrastructure"]
        CL["ContextListener
Application State"] --> FS
    end
    RR --> RESP["HTML Response to Client"]
```

1. **Restore View** — The framework either restores the saved component tree from the session or builds a fresh one from the view definition (e.g., an XHTML facelet).
2. **Apply Request Values** — Raw HTTP parameter values are populated into the corresponding UI components.
3. **Process Validations** — Each component's validators run against the submitted values.
4. **Update Model Values** — Validated values are propagated into the backing managed beans.
5. **Invoke Application** — Application logic executes, including action listeners and navigation rule evaluation.
6. **Render Response** — The component tree is rendered to the response format, typically HTML.

This phased model ensures a consistent, predictable request processing flow. Developers can hook into individual phases via lifecycle listeners or phase listeners for custom behavior.

### Configuration-Driven Architecture

In this codebase, the `FacesServlet` class appears as a minimal stub — a declaration with no method-level symbols. This indicates that the actual lifecycle implementation is inherited from the JSF reference implementation (e.g., Mojarra or MyFaces) rather than being defined inline. Consequently, behavioral configuration is entirely driven by deployment descriptors:

- **`web.xml`** — Declares the FacesServlet, registers co-located infrastructure such as an encoding filter (`X33JVRequestEncodingSjisFilter`) and an application context listener (`X33AppContextListener`).
- **`web-full.xml`** — Provides an alternative or extended servlet configuration, typically used for profile-based deployment.

### Request Pipeline Flow

Requests pass through a chain of co-located components before and after hitting the FacesServlet:

```mermaid
flowchart LR
    A["Client
Request"] --> B["EncodingFilter
X33JVRequestEncodingSjisFilter"]
    B --> C["FacesServlet"]
    C --> D["JSF
Lifecycle"]
    D --> E["X33AppContextListener
Application State"]
    E --> F["Response
HTML View"]
```

The encoding filter processes incoming request parameters (potentially handling character encoding for SJIS-encoded requests), the FacesServlet drives the JSF lifecycle, and the context listener maintains application-wide state. These components operate in concert rather than isolation.

## Dependencies and Integration

### External Dependencies

| Dependency | Role |
|---|---|
| `javax.servlet` API | Base `HttpServlet` class provides request/response handling infrastructure |
| `javax.faces` API | Lifecycle management, component tree model, view state |

### Inbound Integrations

- **Deployment descriptors** (`web.xml`, `web-full.xml`) — These XML files are the primary mechanism for configuring `FacesServlet`. URL patterns, init parameters, and filter ordering are all defined here.
- **Encoding filter** (`X33JVRequestEncodingSjisFilter`) — Operates as a pre-processing filter that may transform request character encoding before parameters reach the JSF lifecycle.
- **Context listener** (`X33AppContextListener`) — Initializes application-scoped state when the web application starts, making resources available to the FacesServlet during request processing.

### Namespace Considerations

This package uses the `javax.*` namespace, which is the Jakarta EE 8 or earlier convention. Newer Jakarta EE 9+ projects have migrated to the `jakarta.*` namespace. When assessing this codebase for migration, the package names and all imports across dependent modules will need to be updated from `javax.faces` to `jakarta.faces`.

## Notes for Developers

- **Stub implementation**: The `FacesServlet` source in this codebase is a minimal class declaration with no methods. This appears to be a test fixture or specification placeholder. The real lifecycle logic is provided by the parent `HttpServlet` class hierarchy from the JSF reference implementation.

- **Configuration-first**: Because the class body is empty, all behavioral configuration — URL patterns, init parameters, filter mappings — lives in `web.xml` and `web-full.xml`. Changes to request handling should be made in these deployment descriptors, not in the servlet class itself.

- **Co-located infrastructure awareness**: When modifying request handling behavior, be aware that the encoding filter and context listener are deployed alongside `FacesServlet`. Changes to character encoding, session management, or application initialization may require coordination with these adjacent components.

- **Jakarta EE migration**: If planning to migrate this project to Jakarta EE 9+, the `javax.faces.webapp.FacesServlet` class will become `jakarta.faces.webapp.FacesServlet`, and all XML deployment descriptor class references will need updating.

- **No direct class indexing**: The parent `javax.faces` module shows zero indexed classes, methods, or source files. This is expected — the package serves as a namespace root, with actual types living in its subpackages. Documentation and development efforts should focus on the sub-module level.
