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 8 years, 5 months ago.

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


    I tried following rewrite in JSF 2.1:

       .to("/{page}.jsf") )

    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


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

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

    .addRule(Join.path("/{page}").to("/{page}.jsf") )

    Or you could add an additional constraint via Java:

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

    Hope this helps πŸ™‚



    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.

    • This reply was modified 8 years, 5 months ago by  banifou.

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



    Understand. The exception rule works, just tested!

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

The forum ‘Rewrite Users’ is closed to new topics and replies.

Comments are closed.