Rewrite conflicts with JSF ImageServlet (h:graphicImage)

Splash Forums Rewrite Users Rewrite conflicts with JSF ImageServlet (h:graphicImage)

This topic contains 4 replies, has 2 voices, and was last updated by  banifou 2 years, 12 months ago.

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

    banifou
    Participant

    Hello,
    I tried following rewrite in JSF 2.1:

    addRule(Join.path("/{page}")
       .to("/{page}.jsf") )
    .where("page").matches("[a-zA-Z/]+")
    

    But then all images <h:graphicImage value="/image?file=#{img}" /> returned from a servlet are not displayed any more:`WARNING: StandardWrapperValve[ImageServlet]: PWC1406: Servlet.service() for servlet ImageServlet threw exception
    com.sun.faces.context.FacesFileNotFoundException: /image.xhtml Not Found in ExternalContext as a Resource`
    What is wrong? Thanks in advance

    #24593

    This is because your /image URL matches the Join rule specified. You need to add an exception, like this:

    .addRule(Join.path("/{page}").to("/{page}.jsf") )
    .when(Not.any(Path.matches("/image")))
    .where("page").matches("[a-zA-Z/]+")

    This is one way to do it. You could also simply use a more restrictive regex:

    .addRule(Join.path("/{page}").to("/{page}.jsf") )
    .where("page").matches("(!?image)[a-zA-Z/]+")

    Or you could add an additional constraint via Java:

    .addRule(Join.path("/{page}").to("/{page}.jsf") )
    .where("page")
     .matches("[a-zA-Z/]+")
     .constrainedBy(new Constraint<String>() {
       boolean isSatisfiedBy(Rewrite event, EvaluationContext context, String value) {
         return !string.matches("image")
       }
     })

    Hope this helps 🙂

    #24598

    banifou
    Participant

    Waw, I see, rewrite is very flexible! I’ll try this.
    But why matches my url the Join rule? There is no .jsf in it.
    Thanks

    • This reply was modified 2 years, 12 months ago by  banifou.
    #24600

    Very flexible indeed 🙂

    Join.path("/{page}") is why it matched. The path declaration is what controls matching, not the internal resource URL, which may or may not be an actual file (it might be virtual, or another defined Rule).

    #24602

    banifou
    Participant

    Understand. The exception rule works, just tested!
    Bye

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

You must be logged in to reply to this topic.

Comments are closed.