1

I have this Method that adds a new customer, So when i put a nickname that already exists an exception is thrown, how can i show the message of the exception in the adding form, iam using primefaces

   public String addCustomer() {

            webClient
            .post()
            .uri("/customer/addCustomer")
            .bodyValue(customer)
            .retrieve()
            .onStatus(HttpStatus.BAD_REQUEST::equals,
                    response -> Mono.error(new NickNameExistException("NickName Exist. Please Try another one.")))
            .bodyToMono(Customer.class);

1 Answers1

1

I think that you can show the message in a dialog like that (for more details see this answer)

            webClient
            .post()
            .uri("/customer/addCustomer")
            .bodyValue(customer)
            .retrieve()
            .onStatus(HttpStatus.BAD_REQUEST::equals,
                 response -> {
                 FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Error", "NickName Exist. Please Try another one");
                 // For PrimeFaces >= 6.2
                 PrimeFaces.dialog().showMessageDynamic(message);
             return Mono.error(new NickNameExistException("NickName Exist. Please Try another one."));
            }
            )
            .bodyToMono(Customer.class);
Oussama ZAGHDOUD
  • 1,767
  • 5
  • 15