Sujith PS
Sujith PS

Reputation: 4864

JSF Page navigation using rewrite (Need to change browser url for navigation )

I have my RewriteConfiguration class

@RewriteConfiguration
public class ApplicationConfigurationProvider extends HttpConfigurationProvider {

    @Override
    public int priority() {
        return 0;
    }

    @Override
    /**
     * map URL with resource
     */
    public Configuration getConfiguration(ServletContext context) {
        return ConfigurationBuilder.begin()

    .addRule(Join.path("/page1/{param}").to("/view/page1.jsf?product={param}"))
                .addRule(Join.path("/page2/{param}").to("/view/page2.jsf?product={param}"))

        ;
    }
}

My managedBean

@Named("myBean")
@javax.enterprise.context.RequestScoped
public class PageManagedBean {
 ...
    public String success(){
        return "success";
    }

...
}

In my page1.xhtml my submit button code is

<h:commandButton action="#{myBean.success()}" id="nextButton" value="NEXT" >
    <f:param name="product" value="#{param.product}"></f:param>
</h:commandButton>

And my navigation rule in faces-config.xml is

<navigation-rule>
        <from-view-id>/view/page1.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/view/page2.jsf</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>error</from-outcome>
            <to-view-id>/error-500</to-view-id>
        </navigation-case>
    </navigation-rule>

The problem is : When I am click on submit button from page1 , in the browser URL it is showing /page1/xyz even-though the page is redirected to page2

The requirement is to change the url to /page2/xyz.

I added <redirect/> in faces-config.xml , but in URL it is showing the full path of the page2 (/view/page2.jsf) .

How can I redirect to next page with change in URL ?

Upvotes: 1

Views: 909

Answers (1)

chkal
chkal

Reputation: 5668

Your Join looks strange. You should not use query parameters in the to() part. Rewrite automatically converts all path parameters to query parameters.

So instead of:

.addRule(Join.path("/page1/{param}").to("/view/page1.jsf?product={param}"))

You should try:

.addRule(Join.path("/page1/{product}").to("/view/page1.jsf"))

Now your navigation should work. But please include the redirect element. That’s required for the URL to change.

Upvotes: 1

Related Questions