https://github.com/objectos/demo.sf
Source code for the "Objectos Way In A Single File" series.
https://github.com/objectos/demo.sf
Last synced: 4 months ago
JSON representation
Source code for the "Objectos Way In A Single File" series.
- Host: GitHub
- URL: https://github.com/objectos/demo.sf
- Owner: objectos
- License: other
- Created: 2025-05-25T20:13:39.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-07T12:08:33.000Z (10 months ago)
- Last Synced: 2025-07-07T13:25:56.572Z (10 months ago)
- Language: Makefile
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Objectos Way In A Single File
Source code for the "Objectos Way In A Single File" video series,
where we'll develop a full Objectos Way application contained in a single Java source file.
Of course, in regular development, you'd most likely structure your Objectos Way project around multiple classes and, if that's your thing, multiple packages.
But we hope to show that "full-stack" web development in Java can (and should) be simpler.
## How to Run
To run the latest iteration of the application, you'll need:
- JDK 23 or later.
Then, in a work directory, run the following commands:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.5/objectos.way-0.2.5.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/heads/main/main/Start.java
java -p objectos.way-0.2.5.jar --add-modules objectos.way --enable-preview Start.java
```
Finally, browse to `http://localhost:8080`.
Alternatively, you can run a previous iteration of the application by following the instructions on the relevant section below.
## Iterations
This section lists all the iterations of the application in reverse chronological order.
### OWIASF #006: Objectos HTML template inheritance
Release date: 2025-07-07
In order to remove some of the code duplication observed in the page classes,
we introduce a base template to our application.
In an Objectos Way application, HTML templates are regular Java classes.
So template inheritance is just regular Java class inheritance.
In this iteration, we showcase:
- Creating a base template as an abstract Java class.
- Using an abstract method directly to provide the page title.
- Using the `f` instruction along with an abstract method.
Requires JDK 23 or later.
Instructions to run:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.5/objectos.way-0.2.5.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/tags/v006/main/Start.java
java -p objectos.way-0.2.5.jar --add-modules objectos.way --enable-preview Start.java
```
### OWIASF #005: Soft navigation between pages with Objectos Script
Release date: 2025-06-23
[YouTube Video](https://www.youtube.com/watch?v=J5tcNEQ6HYE)
We link between pages of our application using the soft navigation feature of Objectos Script:
- Including the JS library directly from Java code.
- Creating an Objectos Script powered link using the `data-on-click` attribute.
- Defining `data-frame` attributes.
Requires JDK 23 or later.
Instructions to run:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.4/objectos.way-0.2.4.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/tags/v005/main/Start.java
java -p objectos.way-0.2.4.jar --add-modules objectos.way --enable-preview Start.java
```
After the server starts:
- Browse to `http://localhost:8080` and click on the "Objectos Script" link.
- Observe the changes in the page title, the browser URL and the page contents.
- Browse to `http://localhost:8080/script.js` and see code of the included JS library.
- Use the devtools of your browser, and see that navigations are initiated by the JS library.
### OWIASF #004: Styling our application with Objectos CSS
Release date: 2025-06-16
[YouTube Video](https://www.youtube.com/watch?v=Anp9Fysh1rs)
We style our home page with a CSS file generated by Objectos CSS:
- Using the Objectos HTML `css` attribute.
- Adding CSS utilities directly in Java code.
- Configuring which classes Objectos CSS should scan.
- Using Objectos CSS variants.
- Defining and using theme variables.
Requires JDK 23 or later.
Instructions to run:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.3/objectos.way-0.2.3.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/tags/v004/main/Start.java
java -p objectos.way-0.2.3.jar --add-modules objectos.way --enable-preview Start.java
```
After the server starts:
- Browse to `http://localhost:8080` and see the styles applied.
- Using your browser devtools, switch between light and dark mode and observe the changes.
- Browse to `http://localhost:8080/styles.css` and see the generated CSS.
### OWIASF #003: HTML template variables, conditional rendering and loops.
[YouTube Video](https://www.youtube.com/watch?v=7dD9RI-Vr_M)
We add the `/objectos/html` route which showcases a number of Objectos HTML features:
- HTML template variables.
- Conditional rendering.
- Loops: using the `f` instruction.
Requires JDK 23 or later.
Instructions to run:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.3/objectos.way-0.2.3.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/tags/v003/main/Start.java
java -p objectos.way-0.2.3.jar --add-modules objectos.way --enable-preview Start.java
```
After the server starts:
- Browse to `http://localhost:8080/objectos/html` and see the default `400 Bad Request` response.
- Browse to `http://localhost:8080/objectos/html?name=Objectos+Way` and see the template variable in action.
- Browse to `http://localhost:8080/objectos/html?name=Objectos+Way&show=on` and see the conditional rendering in action.
- Browse to `http://localhost:8080/objectos/html?name=Objectos+Way&show=on&count=3` and see the loops / iteration in action.
### OWIASF #002: HTML response using the `Html.Template` class
[YouTube Video](https://www.youtube.com/watch?v=YUX07kbc2Ss)
We improve on the previous iteration,
and we replace the text response "home page" with an HTML page generated by a `Html.Template` instance.
Requires JDK 23 or later.
Instructions to run:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.2/objectos.way-0.2.2.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/tags/v002/main/Start.java
java -p objectos.way-0.2.2.jar --add-modules objectos.way --enable-preview Start.java
```
After the server starts:
- Browse to `http://localhost:8080` and it see the response generated by the `Start.Home` class.
- Browse to any other path and it responds with "Not Found".
### OWIASF #001: Single-Path Text-Response Web Server
[YouTube Video](https://www.youtube.com/watch?v=OHPDPZG9y2k)
Configures and starts the web server:
- Browse to `http://localhost:8080` and it responds with "It Works!".
- Browse to any other path and it responds with "Not Found".
Requires JDK 23 or later.
Instructions to run:
```
wget -q https://repo.maven.apache.org/maven2/br/com/objectos/objectos.way/0.2.2/objectos.way-0.2.2.jar
wget -q https://raw.githubusercontent.com/objectos/demo.sf/refs/tags/v001/main/Start.java
java -p objectos.way-0.2.2.jar --add-modules objectos.way --enable-preview Start.java
```
After the server starts, browse to `http://localhost:8080`.
## License
Copyright (C) 2025 [Objectos Software LTDA](https://www.objectos.com.br)
Licensed under the Apache License, Version 2.0.