在 Primefaces 中显示异常消息

发布于 2025-01-20 12:38:49 字数 483 浏览 0 评论 0原文

我有这个添加新客户的方法,所以当我输入已经存在的昵称时会引发异常,我如何在添加表单中显示异常消息,我使用 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);

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2025-01-27 12:38:49

我认为您可以在这样的对话框中显示消息(有关更多详细信息,请参阅此

            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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文