Saturday 2 May 2015

Pages

Blogs normally have one or two pages. An example of what I mean by a page would be an 'about' page.

For now the blog platform's pages will include the following fields:
  • Title
  • Description
  • Body (i.e. the content of the page)
The view will be implemented on the front-end. The back-end will have the create, update, and delete functionality.

The URL pattern to retrieve a page in the front-end will be:

/<hyphenated page title>.html

I will use the page's title to query the database for the record. The .html URL ending will give the regex a solid stopping point. This will let the Java container 404 more invalid requests. Only the requests that match the pattern will hit the database. For the invalid requests that do hit the database something akin to this should do for raising a 404 page not found.

public void findPage(Long id) throws IOException {
        page = ps.getPageById(id);
        if (page == null) {
            FacesContext.getCurrentInstance().getExternalContext().responseSendError(HttpServletResponse.SC_NOT_FOUND, "page not found");
            FacesContext.getCurrentInstance().responseComplete();
        }
    }

Anyway, time to implement it.

No comments:

Post a Comment