Unable to have an error 404 not found with a pattern validator

Splash Forums PrettyFaces Users Unable to have an error 404 not found with a pattern validator

This topic contains 4 replies, has 3 voices, and was last updated by  weljoweb 5 years, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18011

    ez.dummy
    Participant

    Hi,

    I would like know if it’s possible to have a status error 404 not found when using a validator.

    Currently i use a “Path parameters” with a validator.

    <pattern value=”/store/#{cat}/”>

    <validate index=”0″ validator=”#{store.validateCat}” onError=”pretty:error” />

    </pattern>

    And now on error on validateCat i don’t have a status error “404 not found” but a “302 Moved Temporarily”.

    How can i do to have an error status 404 ?

    Waiting for all your suggestions and solutions.

    Thank you.

    #21276

    You are getting a 302 instead of a 404 because you are using the onError attribute in your configuration. This tells PrettyFaces, that you want to redirect the user to another URL (the one with the id “error”) in case of validation errors.

    Just remove the onError attribute and you should get a 404! :)

    #21277

    ez.dummy
    Participant

    Thanks lot for your reply !

    If i remove the onError attribute, i have a 404 but it’s my default error page define in my web.xml.

    But now i would like have a specific error page for exemple the search or the detail of article.

    Is there a way to have different error pages with a status 404?

    #21278

    Sorry, but I think this is currently not possible. You can either redirect the user to some other page with a 302 using the onError attribute or you can send a standard 404 result code. If you use the latter, PrettyFaces will execute HttpServletResponse.sendError(404) using the standard Servlet API.

    If you want to be able to show different error pages depending of the page the user tries to access and the specific validation error, you should think about whether it is possible to do this validation when the user submits the search form or something like this.

    I hope this helps! :)

    #21279

    weljoweb
    Participant

    Hi,

    I have the same issue, please see http://ocpsoft.com/support/topic/unable-to-navigate-to-onerror-outcome-during-query-param-validation for my analysis.

    As an alternative what I did was to do my validation inside the action. Then set the desired response code e.g.

    /**

    * Action for pretty faces url redirection

    *

    */

    public String loadPage() {

    /**

    * PrettyFaces won’t allow forwards on error

    * except to standard 404 so for now we handle validation here.

    */

    ParameterValidator validator = getValidator();

    try {

    validator.validateProductId(context, null, productId);

    } catch (Exception e) {

    productId = null;

    }

    if (productId != null) {

    initialize();

    return null;

    } else {

    FacesContext.getCurrentInstance().getExternalContext().getResponse();

    resp.setStatus(SC_NOT_FOUND);

    return “showProductNotFoundPage”;

    }

    }

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.