Skip to content

Queston: Triggers HtmxResponse in 4.0.0? #155

@resmo

Description

@resmo

Hi

I make use of triggers in HtmxResponse and wonder how this would be possible in 4.0.0 with HtmxResponse gone? Thanks in advance.

@HxRequest(boosted = false)
@PostMapping("")
public HtmxResponse hxSave(
        @Valid
        @ModelAttribute("address") AddressDto addressDto,
        BindingResult result,
        Model model
) {
    if (result.hasErrors()) {
        model.addAttribute("address", addressDto);
        Iterable<Person> persons = personService.findAll();
        model.addAttribute("persons", persons);
        return HtmxResponse.builder()
                .view("address/partial/dialogs :: form-dialog")
                .build();
    } else {
        try {
            Address address = addressService.save(addressDto);
            model.addAttribute("success", address);
            return HtmxResponse.builder()
                    .trigger("addressChanged")
                    .view("address/partial/dialogs :: form-dialog")
                    .view("fragments/message :: saved")
                    .build();

        } catch (Exception ex) {
            model.addAttribute("error", ex.getLocalizedMessage());
            model.addAttribute("address", addressDto);
            return HtmxResponse.builder()
                    .view("address/partial/dialogs :: form-dialog")
                    .build();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions