Double slash in URL with JSF 2.1 navigation rules

Hey. I have a problem with a navigation rule in JSF 2.1. This configuration worked with JSF 1.2. The project uses several additional libraries: JSF 2.1, RichFaces 4.2, Tomahawk, Spring 3.1, urlrewrite, acegi.

The problem is this:

I open the page in the browser url: localhost: 8080 / cat1 / cat2, I see the index.xhtml page. I fill out the form and click the button, after 2 seconds I see the result on the .xhtml page, everything is fine, but the URL in the browser has a double slash. There is localhost: 8080 / cat1 / cat2 // index.xhtml instead of localhost: 8080 / cat1 / cat2 / page.xhtml.

When I try to click a link on my page. xhtml, I see that the page was not found due to a double slash in the URL.

On the page.xhtml page, I again have a count function that calls the same form of the bean method. After clicking this button, the response is ok, my url is localhost: 8080 / cat1 / cat2 / page.xhtml without a double slash. All links on the page work.

When I type in the URL: localhost: 8080 / cat1 / cat2 / index.xhtml and click on the button, I can see my page.xhtml, but the URL is localhost: 8080 / cat1 / cat2 / and all the links to the page work

I added this line:

<from-action>#{bean.method}</from-action> 

but did not help

on my index.html:

 <h:commandButton action="#{bean.method}" value="" styleClass="method right" tabindex="8" /> 

Act:

 public String method() { // few instruction return "success"; } 

Rule:

 <navigation-rule> <from-view-id>/cat1/cat2/*</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/cat1/cat2/page.xhtml</to-view-id> </navigation-case> <!-- Here is more cases --> </navigation-rule> 

Has anyone encountered a similar problem?

+4
source share
1 answer

The double // is due to the start / in your welcome file, it should be index.xhtml , not /index.xhtml .

 <welcome-file-list> <welcome-file>index.xhtml</welcome-file> </welcome-file-list> 

In JSF 2.0, you do not need to explicitly write navigation rules in faces-config.xml. You can simply return the identifier of the result type.

So, if you return β€œsuccess” in your action method, it will automatically select success.xhtml .

So, just return the β€œpage” and you can remove the navigation rule from your faces-config.xml .

+3
source

Source: https://habr.com/ru/post/1436866/


All Articles