Enonic version: 7.1.0
OS: Ubuntu
I would like it to be possible to to have a part in a page. And on a POST-request to that page, handle the POST in a post
-function exported from the part, and render something to the page (where the part is included, same as with GET).
Currently nothing is rendered where the part was when we do a POST-request to a page. (See example below)
The background for my experimentation around this, is that I wanted to get more back to basics. I want to ship less JavaScript to improve initial load time of my pages.
I basically want to get the same benefits of having parts and pages, with using a form.
I want to do validation serverside in my part, and render out the form again, with the inputfieldsā errors indicated.
Example:
I have uploaded some test code on Github. For this example the part controller is found here, and the page controller can be found here.
GET Request renders:
POST Request when pressing the āSend nameā-button renders:
We can see that no part is rendered on a POST to a page, and the post
function in the part is not called.
We had a discussion around what is possible and not regarding this topic, as well as some workarounds in this thread on the #developer channel on Slack.
Alternative ways to solve this in XP today feels a bit like hacks:
- Just do everything in a page - The problem is that I want to reuse the part in several pages, and I donāt want to duplicate code.
- Send the POST to a service, and render the resulting html. - This has the same problems as with page above.
- Send the POST to the url of the part - Either I have to render the entire page-html in the part, or I would have to use JavaScript/Ajax to place the parts html inside the correct element on the page.