Client side fragment retrieval

Phoenix has a special feature which allows fragments to be rendered server-side and returned to the client-side via GET requests. This features allows building of modern and complex web applications with dynamically constructed web-pages and elements added on the page after the page load. Similar to modern JavaScript UI frameworks, Phoenix allows the creation and reusability of fragments/components.

To enable this feature, include the following configuration option: fragmentRetrieveEnabled: true

When this option is on, a special controller is activated in your Spring application which can be called to retrieve the HTML code generated by a fragment. The endpoint requires the fragment name as a RequestParameter and a list of Strings representing the String representation of the fragment's input parameters. If the fragment has no input parameters, then no secondary RequestParameters are sent.

Example: GET /phoenix/fragment?name=myfragments.testFragment&param=4&param=Test

The order of the parameters must match the order they are declared in the fragment. Furthermore, due to limitations that are currently present in the code, only primitive types and Strings are allowed as input parameters. See list of allowed input types below.

The endpoint will return the HTML code rendered by the specified fragment or notFound() if the fragment and parameter combination can't be found.

Calling this endpoint makes it easy to dynamically add elements to a web page that has already been rendered by calling the endpoint from JavaScript and appending the returned HTML code to the DOM.

Allowed input types for client-retrieved fragments
  • int/Integer
  • double/Double
  • float/Float
  • long/Long
  • short/Short
  • byte/Byte
  • char/Character
  • boolean/Boolean
  • String