{"id":18426405,"url":"https://github.com/complate/complate-sample-spring-boot","last_synced_at":"2025-04-13T18:54:21.066Z","repository":{"id":42932251,"uuid":"210546989","full_name":"complate/complate-sample-spring-boot","owner":"complate","description":"Example project for complate spring support","archived":false,"fork":false,"pushed_at":"2023-01-07T04:31:33.000Z","size":232,"stargazers_count":2,"open_issues_count":6,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-16T08:26:52.648Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://complate.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/complate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-24T08:07:03.000Z","updated_at":"2021-10-02T11:09:26.000Z","dependencies_parsed_at":"2023-02-06T11:46:36.666Z","dependency_job_id":null,"html_url":"https://github.com/complate/complate-sample-spring-boot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/complate%2Fcomplate-sample-spring-boot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/complate%2Fcomplate-sample-spring-boot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/complate%2Fcomplate-sample-spring-boot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/complate%2Fcomplate-sample-spring-boot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/complate","download_url":"https://codeload.github.com/complate/complate-sample-spring-boot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766303,"owners_count":21158297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T05:07:51.252Z","updated_at":"2025-04-13T18:54:21.038Z","avatar_url":"https://github.com/complate.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# complate-sample-spring-boot\n\n This sample repository demonstrates the server-side rendering of an\n[java spring](https://spring.io) application using the\n[corresponding adaptor](https://github.com/complate/complate-spring).\n\n## Getting Started\n\n```shell script\nnpm install                                # Install js dependencies\n./mvnw spring-boot:run                     # Start server\n```\n\nThe application should now be running on `localhost:8080`.\n\n## Walkthrough\n\nThis sample project is based on [Spring Initializr](https://start.spring.io/).\nThe interesting parts is the views in `src/jsx` and the\n[SampleController class](src/main/java/org/complate/spring/boot/sample/SampleController.java),\nthe controller that renders the views in response to HTTP requests.\n\n### The Spring Controller\n\nThe Spring controller resolves JSX views from a bundeled javascript file under\nthe path `templates/complate/bundle.js`.\n\nThe request handler returns the view and model at once as a `ModelAndView`\nobject.\n\n```java\n@GetMapping(\"/\")\npublic ModelAndView index() {\n    return new ModelAndView(\"Person\")\n            .addObject(\"age\", 99)\n            .addObject(\"name\", \"John Doe\");\n}\n```\n\nThe Spring framework takes care of rendering the JSX views using the\n[configured](src/main/java/org/complate/spring/boot/sample/ComplateConfiguration.java)\n`ComplateViewResolver`, imported from the\n[spring complate adaptor](https://github.com/complate/complate-spring).\n\nThis sample project specifies two mapping functions with their corresponding\nviews, a \"person view\" corresponding to `/` and a \"bootstrap view\"\ncorresponding to `/bootstrap`.\n\n### The JSX Views\n\nThe JSX views themselves exist in `src/jsx` and is bundled together by\n [faucet](http://faucet-pipeline.org) using `npm run compile`. The [faucet\n example configuration](faucet.config.js) in this project shows how to configure\n faucet to generate a javascript file compatible with the Nashorn Scripting\n Engine, which the `ComplateViewResolver` uses internally.\n\nThe entry level file for faucet is `index.js` and the only relevant function to\nthe backend is `render`. This endpoint requires three arguments: `stream` which\nis a writable stream corresponding to response of the spring application, `tag`\nwhich is the name of the view to render (the `viewName` argument) in the\n`ModelAndView` constructor, and `params` which is the view parameters (the\n`model` argument in the `Modelandview` constructor.\n\n```javascript\nexport default function render(view, params, stream) {\n    renderer.renderView(view, params, stream);\n}\n```\n\nThe `render` function uses a `renderer` from the\n[complate-stream](https://github.com/complate/complate-stream) library, the\ncomponent that actually renders the HTML. In order for this to work, the defined\nviews have first to be registred using the same renderer.\n\n```javascript\nimport Renderer from \"complate-stream\";\nimport Person from \"./person\";\nimport BootstrapSample from \"./bootstrap-sample\";\n\nlet renderer = new Renderer(\"\u003c!DOCTYPE html\u003e\");\n\n[Person, BootstrapSample].forEach(view =\u003e {\n    renderer.registerView(view);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomplate%2Fcomplate-sample-spring-boot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomplate%2Fcomplate-sample-spring-boot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomplate%2Fcomplate-sample-spring-boot/lists"}