Page navigation using rewrite

Splash Forums Rewrite Users Page navigation using rewrite

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 1 year, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #27127

    sujith ps
    Participant

    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 ?

    • This topic was modified 1 year, 3 months ago by  sujith ps.
    • This topic was modified 1 year, 3 months ago by  sujith ps.
    • This topic was modified 1 year, 3 months ago by  sujith ps.
    #27132

    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.

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

You must be logged in to reply to this topic.

Comments are closed.