Correct way to show error page in page action method

Splash Forums Rewrite Users Correct way to show error page in page action method

This topic contains 0 replies, has 1 voice, and was last updated by  Ultranium 11 months, 2 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #27240

    Ultranium
    Participant

    I have a bean that uses a path parameter to find an item in database. If there is no item with such ID, I want to show user an error page with HTTP status 404.
    Now I’m using this solution for the job:

    @RequestAction
    @Deferred
    public String loadItem() {
      // some DB logic here
    
      if (!itemExist) {
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        try {
          response.setStatus(404);
          return "/404.xhtml";
        } catch (Exception e) {
          log.info("Error here!");
          return null;
      }
    }

    It works, but it looks ugly to me.
    What is the preferred way to do it?

    • This topic was modified 11 months, 2 weeks ago by  Ultranium.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

Comments are closed.