[solved] How do I use the outcome parameter with Rewrite? (Ans: use annotations)

Splash Forums Rewrite Users [solved] How do I use the outcome parameter with Rewrite? (Ans: use annotations)

Tagged: 

This topic contains 13 replies, has 4 voices, and was last updated by  Christian Kaltepoth 2 years, 5 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #25872

    austinian
    Participant

    I was trying to do this:

    <p:button value="Register" outcome="/register" />

    But that gives me an NPE, like here http://stackoverflow.com/questions/17503177/pbutton-outcome-throws-npe-while-houtputlink-value-works where Lincoln pointed out that this was wrong, and a couple of ways to get around it if you’re using PrettyFaces.

    The relevant section of my HttpConfigurationProvider is a simple
    .addRule(Join.path("/register").to("/Register.xhtml"))
    (I discovered the annotation method after authoring the HttpConfigurationProvider).

    I’m using Rewrite, not PrettyFaces. I’m new to JSF and haven’t used PrettyFaces, so I’m jumping into this purely from a Rewrite perspective. I’ve fetched the documentation from the GitHub repo because the documentation on this site keeps failing for me, but that’s another issue.

    I’m using tomcat 7.0.50, javax.faces-2.2.4, javax.servlet.jsp.jstl-api-1.2.2, primefaces-4.0, rewrite-servlet-2.0.10.Final, and rewrite-integration-faces-2.0.10.final.

    • This topic was modified 2 years, 5 months ago by  austinian.
    • This topic was modified 2 years, 5 months ago by  austinian.
    #25882

    You have to use the plain JSF view for the outcome like this:

    <p:button value="Register" outcome="/Register.xhtml" />

    And to get nice redirects, you should do this:

    <p:button value="Register" outcome="/Register.xhtml?faces-redirect=true" />

    #25893

    ravindra
    Participant

    Hi,

    Hope following code will helpful .

    public Navigate getTestView() {
    return Navigate.to(“Register.xhtml”);
    }

    <p:button value=”Register” outcome=”bean.testView” />

    Regards
    Ravindra

    #25894

    austinian
    Participant

    Right, I know how to do that, I guess I didn’t state my question well. I’m trying to get the button to send the user to “/register”, you know, a nicer looking URL. Since I’m not using prettyfaces, I’m not sure how to get the URL to look like that when the outcome is “/Register.xhtml”

    #25896

    The second code I posted in my first reply should result in a clean URL. Clicking the button will result in a postback to the server followed by a redirect to the clean URL.

    #25904

    austinian
    Participant

    I tried using the second code you wrote, but the URL in the browser after I click the button is http://localhost:8080/Register.xhtml;jsessionid=C5DDFB24FCDFEA5F7DDADC0844566AAA
    I guess the section in the documentation I’m looking for is the yet-to-be-published-or-created “Response Interception”?

    • This reply was modified 2 years, 5 months ago by  austinian.
    • This reply was modified 2 years, 5 months ago by  austinian.
    #25917

    Could you please post your complete configuration. The web.xml, the configuration provider, the pom.xml and so on?

    #25924

    austinian
    Participant

    Sorry, I thought I had already included a link to Github. The navigation branch is the one that I’m working out how to use Rewrite on:
    https://github.com/davidhockey22/CommunityServiceWeb/tree/navigation

    #25927

    Not sure why exactly, but try using /Web/Register.xhtml instead of just Register.xhtml in your Navigate result.

    #25928

    Your rules look simple enough, I see no reason why this shouldn’t be working.

    #25929

    Could you also try this:

    <h:link outcome="/Register.xhtml">Register</h:link>

    Just to make sure that this problem isn’t caused by the PrimeFaces button.

    #25930

    austinian
    Participant

    Code:
    <h:link value="Register" outcome="/NewVolunteer.xhtml" />
    Resulting URL:
    http://localhost:8080/Web/NewVolunteer.xhtml?jftfdi=&jffi=%2FNewVolunteer.xhtml

    Code:
    <h:link value="Register" outcome="/NewVolunteer.xhtml?faces-redirect=true" />
    Resulting URL:
    http://localhost:8080/Web/NewVolunteer.xhtml?jftfdi=&jffi=%2FNewVolunteer.xhtml%3Ffaces-redirect%3Dtrue

    I’m going to try to use annotations and see if I get different results.

    • This reply was modified 2 years, 5 months ago by  austinian.
    #25931

    austinian
    Participant

    Alright, I’m not sure why, but this is what ended up working:

    I added this annotation to RegistrationBean.java
    @Join(path="/register", to="/Web/NewVolunteer.xhtml")

    commented out this line in the HttpConfigurationProvider
    .addRule(Join.path("/register").to("/Web/NewVolunteer.xhtml"))

    and used this line in the facelet
    <p:button value="Register" outcome="/NewVolunteer.xhtml" />

    and now the URL shows up as expected. I’m going to just use annotations everywhere now, as it’s both how I’m used to working with this stuff, and it seems to be the way that’s working best. Thanks for your help with troubleshooting, not sure how useful this is as a test case for you, since I’m unsure as to whether this is expected behavior.

    #25934

    Perhaps your configuration provider wasn’t picket up correctly? However, I’m glad to hear you got it working.

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

You must be logged in to reply to this topic.

Comments are closed.