Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/docs/advanced/open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Opening URLs
sidebar_class_name: new-content
---

The <JavadocLink type="foundation" location="com/webforj/Page" code='true'>Page</JavadocLink> utility class comes with a few options to open URL's.

The `Page.getCurrent().open(...)` method is used to programmatically open a new browser window or tab with a specified URL.

## `open(...)`

Opens the provided URL in a new window or tab. It's possible to supply both the window name and a string with parameters like height,
position, or window type.

```java
Page.getCurrent().open("https://example.com");

Page.getCurrent().open("https://example.com", "self");

Page.getCurrent().open("https://webforj.com/", "webforJ",
"popup,left=100,top=100,width=600,height=600");
```

These features match those available in standard [window.open()](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) behavior in browsers.
26 changes: 23 additions & 3 deletions docs/docs/building-ui/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sidebar_position: 10
title: Events
slug: events
draft: false
sidebar_class_name: updated-content
---

<JavadocLink type="foundation" location="com/webforj/component/event/Event" top='true'/>
Expand Down Expand Up @@ -63,9 +64,9 @@ listenerRegistration.remove();

## Using event payload

It's important to note that events often come with a payload, which contains additional information related to the event. You can efficiently utilize this payload within the event handler to access relevant data without making unnecessary round trips between the client and server. By doing so, you can improve the performance of your application.
It's important to note that events often come with a payload, which contains additional information related to the event. You can efficiently utilize this payload within the event handler to access relevant data without making unnecessary round trips between the client and server. By doing so, you can improve the performance of your app.

The following code snippet queries the component to get information that, for our demonstration's purposes, is already included in the event payload, representing inefficient code:
The following code snippet queries the component to get information that, for the demonstration's purposes, is already included in the event payload, representing inefficient code:

```java
myComponent.addEventListener(e -> {
Expand Down Expand Up @@ -102,4 +103,23 @@ javaE='https://raw.githubusercontent.com/webforj/webforj-documentation/refs/head
height='100px'
/>

<!-- <EventTable base events={['drawerOpen', 'drawerClose']} /> -->
<!-- <EventTable base events={['drawerOpen', 'drawerClose']} /> -->

### Page-level event registration

In addition to attaching event listeners to specific UI components, the <JavadocLink type="foundation" location="com/webforj/Page" code='true'>Page</JavadocLink> utility class itself supports global HTML event registration. This enables use cases where an event should be captured across the entire page, without requiring a specific element reference.

For example, the following registers a page-wide click event listener that logs the cursor position on click:

```java
PageEventOptions options = new PageEventOptions();
options.addData("clientX", "event.clientX");
options.addData("clientY", "event.clientY");

Page.getCurrent().addEventListener("click", event -> {
int x = (int) event.getData().get("clientX");
int y = (int) event.getData().get("clientY");

console().log("Clicked at x: " + x + ", y: " + y);
}, options);
```
26 changes: 23 additions & 3 deletions docs/docs/introduction/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ With `Application.java` set up, the app is now configured with a title and route
### Discovering an `App`

A single <JavadocLink type="foundation" location="com/webforj/App" code='true'>App</JavadocLink> limit is enforced in webforJ, which shifts all error handling responsibilities to the Java side and gives developers full control over error management.

<!-- vale off -->
During the webforJ bootstrap process, all classes that extend <JavadocLink type="foundation" location="com/webforj/App" code='true'>com.webforj.App</JavadocLink> are scanned. If multiple apps are found, the system looks for the <JavadocLink type="foundation" location="com/webforj/annotation/AppEntry" code='true'>com.webforj.annotation.AppEntry</JavadocLink> annotation. If any of the discovered classes are annotated with <JavadocLink type="foundation" location="com/webforj/annotation/AppEntry" code='true' >@AppEntry</JavadocLink>, the first one encountered is considered the entry point.

<!-- vale on -->
- If a class is annotated with `@AppEntry`, that class is selected as the entry point.
- If multiple classes are annotated with `@AppEntry`, an exception is thrown, listing all the discovered classes.
- If no class is annotated and only one subclass of `App` is found, that class is selected as the entry point.
Expand Down Expand Up @@ -146,4 +146,24 @@ Finally, the hello text field and btn button are added to the [`FlexLayout`](../

The `styles.css` file provides custom styling for your webforJ app. This CSS file is referenced in the Application class using the [`@StyleSheet`](../managing-resources/importing-assets#importing-css-files) annotation, which allows the app to apply styles to components within the app.

This file is located in the `resources/static` directory of the project, and can be referenced using the web server URL `ws://app.css`.
This file is located in the `resources/static` directory of the project, and can be referenced using the web server URL `ws://app.css`.

## Cleanup

The <JavadocLink type="foundation" location="com/webforj/Page" code='true'>Page</JavadocLink> class provides an `onUnload()` method that allows you to register a listener for when the browser is unloading the page. This can be useful for cleanup tasks such as logging, releasing resources, or tracking session activity.

This event is triggered when the user:

* Closes the browser tab or window
* Refreshes the page
* Navigates to a different URL

### Example

```java
Page.getCurrent().onUnload(event -> {
System.out.println("Page is unloading, webforj is shutting down");
});
```

This listener is registered using `addUnloadListener()` and returns a `ListenerRegistration<PageUnloadEvent>` that can be used to remove the listener later if needed.