# Add External Java Class

ONEWEB allows you to extend application functionality by attaching **external Java classes** to an entity using **Entity Actions**.\
This mechanism enables developers to execute **custom server‑side logic** during entity processing events such as **INSERT**, **UPDATE**, or **DELETE**.

External Java classes are commonly used for:

* Complex business rules
* Data manipulation before persistence
* Integration with external systems
* Custom validation or processing logic

***

### Configure Class Action in App Designer

#### Step 1: Open Entity in App Designer

1. Open **App Designer**
2. Select and open the target **Entity**

***

#### Step 2: Add Entity Action

1. In the **Navigator pane**, go to\
   **Tool → Action**
2. Drag the **Action** icon and drop it onto the entity

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2Fs8YGFVfC3RaonJ9z5b9f%2F1?alt=media" alt=""><figcaption></figcaption></figure>

***

#### Step 3: Configure Module Action

Click the **Edit** icon to open **Module Action Field Configuration**.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FS0r62CQSPIhGPNUXsUcY%2F2?alt=media" alt=""><figcaption></figcaption></figure>

Configure the following:

* **Process Name**: `UPDATE`
* **Class Action**:

  ```
  com.training.manual.ApplicationManualClass
  ```

Click **OK** to save.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2Fq27uzHD6QiDvQUcjLkvs%2F3?alt=media" alt=""><figcaption></figcaption></figure>

***

#### Step 4: Configure INSERT Process

Repeat the same steps for:

* **Process Name**: `INSERT`

***

#### Step 5: Save Configuration

Click **Save** to persist the Entity Action configuration.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FwAdkpsvRjfn81jJozNqv%2F4?alt=media" alt=""><figcaption></figcaption></figure>

***

### Create Java Class in Eclipse

#### Step 6: Create Java Class

1. Open **Eclipse IDE**
2. In **Project Explorer**, right‑click:

   ```
   /MasterWeb/Java Sources/src
   ```
3. Select **New → Class**
4. Name the class:

   ```
   ApplicationManualClass
   ```
5. Click **Finish**

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FCEYUFbGBd6GFuXseLebS%2F5?alt=media" alt=""><figcaption></figcaption></figure>

***

#### Default Generated Class Structure

```
public class ApplicationManualClass
        extends ProcessHelper
        implements ProcessAction {

    @Override
    public Vector modifyResult() {
        return null;
    }

    @Override
    public boolean validateResult() {
        return false;
    }
}
```

**Method Purpose**

| Method             | Description                                           |
| ------------------ | ----------------------------------------------------- |
| `modifyResult()`   | Modify submitted data before INSERT / UPDATE / DELETE |
| `validateResult()` | Validate submitted data before processing             |

***

### Modify Java Class Logic

#### Example: Log Submitted Data and Button Action

```
public class ApplicationManualClass
        extends ProcessHelper
        implements ProcessAction {

    @Override
    public Vector modifyResult() {

        Vector dataModels = getResultForProcess();
        String buttonAction =
            request.getParameter("SUBMIT_BUTTON");

        System.out.println("Data Models: " + dataModels);
        System.out.println("Button Action: " + buttonAction);

        return dataModels;
    }

    @Override
    public boolean validateResult() {
        return true;
    }

    @Override
    public HashMap modifyLoadUpdateResult() {
        return super.modifyLoadUpdateResult();
    }
}
```

***

### Deploy Java Class

#### Step 7: Publish to Server

1. Open the **Servers** view
2. Right‑click the server
3. Select **Publish**
4. Wait until server status becomes **Synchronized**

***

### Test the Java Class

#### Step 8: Run Application

1. Open:

   ```
   http://<host>:8080/FrontWeb
   ```
2. Log in to the application
3. Open **Create Application**
4. Click **Add**
5. Enter application data
6. Click **Submit**

***

#### Verify Execution Output

In **Eclipse → Console**, the output log should display submitted data and button action.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FOuYzRBPJ3cCFT5VS0P2C%2F6?alt=media" alt=""><figcaption></figcaption></figure>

***

### Summary

Adding an **External Java Class** in ONEWEB enables powerful server‑side customization.

Key capabilities include:

* Executing Java code during entity operations
* Modifying data before persistence
* Enforcing business rules
* Integrating with external systems
* Logging and debugging runtime behavior

By leveraging **Entity Actions + Java Classes**, developers can extend Smart Forms far beyond default behavior while maintaining control, security, and scalability.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onewebstack.com/oneweb-platform-th/building-apps/ui-page-designer/ux-ui-customization/smart-form-customization/add-external-java-class.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
