Question

  1. Can I configure PrettyFaces / Rewrite for mapping all incoming URL request to one page?
  2. Then how I can get full URL path after domain name from PrettyFaces / Rewrite? Maybe have some annotation or some like this {URLPATH}? Looks like this, but maybe have another solutions on this moment

I need: from all requests with:

"/../../../*......." or/and "/a/b/c/*/*/*/.." or/and "/{param}/**" or/and "/{param}/{param2}/{param3}/**/**" 

map to one JSF page.

Something like this:

<url-mapping id="pages">
    <pattern value="/**" />
    <view-id value="/pages.xhtml" />
</url-mapping>


In Spring MVC I do this like "/україна/452454/45/4774/7744/longpath.html":

@RequestMapping(value = {"/**"},method=RequestMethod.GET)
public @ResponseBody String info(HttpServletRequest request) {
    String remainingPaths = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    return "<H1>Good Work</H1><br/>" + remainingPaths;
}

On output I have:

<H1>Good Work</H1><br/>/україна/452454/45/4774/7744/longpath.html

How I can get same effect from PrettyFaces / Rewrite?

Was it helpful?

Solution

I think Rewrite is the solution you are looking for. First, you'll need to upgrade from "PrettyFaces 3.x" to "Rewrite Config PrettyFaces" using the steps outlined here: PrettyFaces Homepage. This should be a drop-in replacement, requiring no additional configuration on your part.

Once you've upgraded and verified that your application is working normally using the "Rewrite Config Prettyfaces" module, you'll want to create a Rule in a new Rewrite Configuration Provider (follow the steps on the Rewrite Homepage):

package com.example;
public class AllPagesToOneViewProvider extends HttpConfigurationProvider
{
   @Override
   public int priority()
   {
     return 0;
   }

   @Override
   public Configuration getConfiguration(final ServletContext context)
   {
     return ConfigurationBuilder.begin()
       .addRule(Join.path("/{all}").to("/pages.xhtml"))
       .where("all").matches(".*");
    }
}

NOTE:

^^ Make sure to register this Configuration Provider in your META-INF/services (as described in the instructions!)

I've also added an issue to support the super-wildcard character in the next version of Rewrite, meaning you will be able to use a Join Annotation instead of being required to create a Configuration Provider just for this one rule (however, I think you will find the Configuration API useful.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top