File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,35 @@ public HtmxResponse getMainAndPartial(Model model){
181181
182182Using `ModelAndView ` means that each fragment can have its own model (which is merged with the controller model before rendering).
183183
184+ ### HtmxResponse . Builder as an argument
185+
186+ An `HtmxReponse . Builder ` can be injected as a controller method. This creates the parameter and adds it to the model,
187+ allowing it to be used without requiring it be the method return value. This is useful when the return value is needed for
188+ the template.
189+
190+ This allows for the following usage:
191+
192+ ```java
193+ @GetMapping (" /endpoint" )
194+ public String endpoint(HtmxResponse . Builder htmxResponse, Model model) {
195+ htmxResponse. trigger(" event1" );
196+ model. addAttribute(" aField" , " aValue" );
197+ return " endpointTemplate" ;
198+ }
199+ ```
200+
201+ For example the JTE templating library supports statically typed templates and can be used like so:
202+
203+ ```java
204+ @GetMapping (" /endpoint" )
205+ public JteModel endpoint(HtmxResponse . Builder htmxResponse) {
206+ htmxResponse. trigger(" event1" );
207+ String aField = " aValue" ;
208+ return templates. endpointTemplate(aField);
209+ }
210+ ```
211+
212+
184213### Error handlers
185214
186215It is possible to use `HtmxResponse ` as a return type from error handlers.
You can’t perform that action at this time.
0 commit comments