**Complete Beginner-Friendly Step-by-Step Guide: Generate REST API + Its Java Client + Use the Client for CRUD in Auto-Generated JSF (NetBeans 26, Jakarta EE 10, Payara 6, MySQL, JPA + JTA, Fully Offline)** This guide is 100% offline once your environment is set up. NetBeans 26’s built-in wizards make this extremely simple — no manual coding for the REST API, entities, or basic JSF pages. We will create **two separate projects** (best practice for clean separation): - **Backend**: REST API (auto-generated from MySQL via JPA/JTA). - **Frontend**: JSF web app (auto-generated CRUD pages) that uses the auto-generated REST Java Client for all CRUD operations. Everything uses **Payara 6** (Jakarta EE 10 compatible), **JPA** with **JTA** persistence unit, and **MySQL**. ### Prerequisites (Do These Once) 1. **NetBeans 26** installed (with Jakarta EE / Java EE plugins — default in full installer). 2. **Payara Server 6** installed and registered in NetBeans: - Go to **Services** window → **Servers** → right-click → **Add Server** → **Payara Server** → point to your Payara install folder → use default domain1 (admin user, no password) → Finish. 3. **MySQL** installed and running. Create a simple database (example name: `mydb`). - In NetBeans **Services** → **Databases** → register your MySQL connection. - Create at least one table (example: `Customer` with columns `id` (PK, auto-increment), `name`, `email`). 4. MySQL JDBC driver is already in NetBeans (it comes bundled or you added it once). You are now ready — no internet needed from here. ### Phase 1: Create the REST API Backend (Auto-Generated) 1. **File → New Project** → **Java with Maven** → **Web Application** → Next. 2. Project Name: `RestApiBackend` Group Id: `com.example` (or your choice) Click Next. 3. **Server**: Select your **Payara Server 6**. **Jakarta EE Version**: Jakarta EE 10 Web (or the highest available). Click **Finish**. 4. **Generate JPA Entities + REST Services in one go** (the magic wizard): - Right-click the project → **New** → **Other** → **Web Services** → **RESTful Web Services from Database** → Next. - **Data Source**: Click **New Data Source** → select your MySQL connection → give JNDI name `jdbc/mydb` → Finish. - Select your tables (e.g. `Customer`) → **Add** → Next. - **Entity Classes**: - Package: `com.example.entities` - Check **Generate JAXB Annotations** (needed for REST JSON/XML). - Next. - **REST Resources**: - Package: `com.example.service` - Accept defaults → **Finish**. NetBeans auto-generates: - JPA entities (`Customer.java` etc.) with annotations. - REST service classes (e.g. `CustomerFacadeREST.java`) with full CRUD (@GET, @POST, @PUT, @DELETE). - `persistence.xml` with **JTA** transaction-type (container-managed, exactly what you asked for). - `ApplicationConfig.java` (Jakarta REST configuration). **Result**: You now have a complete REST API at paths like `/webresources/customer`. ### Phase 2: Deploy & Test the REST API 1. Right-click `RestApiBackend` → **Run**. - Payara starts → project deploys automatically. 2. Open browser: `http://localhost:8080/RestApiBackend/webresources/customer` - You should see JSON list of customers (or empty array if no data). 3. Test CRUD quickly: - Use tools like Postman (or NetBeans generated test client) to POST a new customer, GET list, etc. ### Phase 3: Generate the REST Java Client (Auto-Generated) 1. Make sure the backend is running (so the service is discoverable). 2. In NetBeans, go to **Services** window → **Web Services** (if not visible, it appears after first REST project). 3. Right-click the project `RestApiBackend` → **Test RESTful Web Services** (this registers the service). 4. Now generate the client: - **File → New Project** → **Java with Maven** → **Web Application** → Name it `RestClientLibrary` (or add to a new project). - Better: In your main project or a new library project, right-click → **New** → **Other** → **Web Services** → **RESTful Java Client**. - Select the registered service (from `RestApiBackend`). - Package: `com.example.client` - Click **Finish**. NetBeans generates a clean Java client class (e.g. `CustomerClient.java`) with methods like: - `create(...)`, `edit(...)`, `remove(...)`, `findAll(...)`, `find(...)` etc. - It handles JSON automatically. You can now use this client from **any** Java project (including JSF). ### Phase 4: Create JSF Frontend (Auto-Generated CRUD Pages) + Use the REST Client 1. **File → New Project** → **Java with Maven** → **Web Application** → Name: `JsFClientApp` → Next. 2. Server: **Payara Server 6**, Jakarta EE 10 Web → **Frameworks**: check **JavaServer Faces** → Finish. 3. **Generate entities** (copy or re-generate for JSF): - Copy the `entities` package from the backend project into this project (or run **New → Entity Classes from Database** again — same steps as Phase 1). 4. **Auto-generate full JSF CRUD pages** (the wizard you asked for): - Right-click project → **New** → **Other** → **JavaServer Faces** → **JSF Pages from Entity Classes** → Next. - Select your entity (e.g. `Customer`) → Next. - **JSF Classes Package**: `com.example.jsf` - **JPA Session Bean Package**: `com.example.session` (this will create facades — we will override them later). - Click **Finish**. NetBeans auto-generates: - All Facelets pages: `Create.xhtml`, `Edit.xhtml`, `List.xhtml`, `View.xhtml`, `template.xhtml` etc. - Managed beans (JSF controllers). - CSS and everything ready to run. **Now the key part — wire the REST Client into the JSF managed beans (super simple):** 5. Copy the generated `CustomerClient.java` (and any helper classes) from Phase 3 into `com.example.client` package in this JSF project. 6. Open the generated JSF controller (e.g. `CustomerController.java` or whatever the wizard named it). 7. **Replace the JPA/EJB code with REST Client** (only ~5 lines change): Find the place where it uses `ejbFacade` (or `getFacade()`), and replace with: ```java private CustomerClient client = new CustomerClient(); // <-- our REST client // Example: instead of ejbFacade.create(customer); public String create() { client.create(customer); // calls REST POST return "List"; // or whatever navigation you want } // Similarly for edit, remove, findAll etc. public List getItems() { return client.findAll(); // calls REST GET } ``` (The exact method names match what the REST client generated — just copy-paste from the client class.) 8. Add the client dependency if needed (Maven will handle Jakarta REST client automatically, or add `jakarta.ws.rs-api` if prompted). 9. Right-click the JSF project → **Run**. You now have a beautiful auto-generated JSF CRUD application that **never touches the database directly** — all CRUD goes through your REST API via the generated client! ### Summary of What NetBeans Did Automatically for You - REST API + JPA entities + JTA persistence unit → 1 wizard. - REST Java Client → 1 wizard. - Full JSF CRUD pages + managed beans → 1 wizard. - Payara 6 deployment + MySQL connection → built-in. ### Tips for Beginners - Want to add more tables? Just re-run the wizards — NetBeans handles relationships automatically. - Error about datasource? NetBeans creates `payara-resources.xml` in the backend project — deploy once and it registers the JDBC pool in Payara. - JSON vs XML? The client and REST services default to JSON (Jakarta EE 10 standard). - Want to see the persistence unit? Open `src/main/resources/META-INF/persistence.xml` — it uses `jdbc/mydb` and JTA. You now have a professional, layered architecture (REST backend + JSF frontend using REST client) generated almost entirely by NetBeans wizards — exactly what you asked for! Run both projects on Payara (they can run together). Test CRUD in the JSF browser pages — it will hit your REST API. If you get stuck on any exact wizard screen (NetBeans 26 layout is almost identical to the classic ones), just describe the error and I’ll give the next click. Enjoy! 🚀