PrettyFaces: outbound rewriting broken on Rewrite

Splash Forums PrettyFaces Users PrettyFaces: outbound rewriting broken on Rewrite

This topic contains 17 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 11 months ago.

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #24715

    hendrik
    Participant

    Hello,

    to get around some bugs (http://ocpsoft.org/support/topic/error-on-ajax-post-required-value-was-null/ agin) i’m know trying to use outbound URL rewriting from Prettyfaces which works with prettyfaces-3.3.3 but not with rewrite-2.0.5.

    // Action from bean
    public String go() {
      return "/faces/Page.xhtml?id=2&path=page&faces-redirect=true";
    }
    <!-- pretty-config --><url-mapping id="start">
            <pattern value="/#{ /[a-zA-Z0-9]{3}[a-zA-Z0-9]*/ path : someBean.path}" >
                <validate index="0" validator="#{someBean.validate}" />
            </pattern>
            <view-id value="/faces/Home.xhtml" />
        </url-mapping>
    
        <url-mapping id="next" parentId="start">
            <pattern value="/page"/>
            <view-id value="/faces/Page.xhtml" />
        </url-mapping>

    Home.xhtml has this:
    <h:commandButton action="#{someBean.go}" value="Button"/>

    Result URL with prettyfaces-3.3.3:
    http://localhost:8080/PrettyFacesTest/page/page;jsessionid=ae602354fd86a7644ece6d887b84?id=2

    Result URL with rewrite 2.0.5:
    http://localhost:8080/PrettyFacesTest/faces/Page.xhtml;jsessionid=b04ffa0cc20125fb0bc6613df36e?path=page&id=2

    I guess you guys know that there are other issues with prettyfaces-3.3.3, so i really don’t want to go back.

    So any ideas?

    Edit:Typos…

    • This topic was modified 2 years, 11 months ago by  hendrik.
    #24717

    Could you show me the rewrite dependencies in your POM file?

    #24718

    hendrik
    Participant

    Sure.
    Rewrite:

    <dependency>
                <groupId>org.ocpsoft.rewrite</groupId>
                <artifactId>rewrite-servlet</artifactId>
                <version>2.0.5.Final</version>
            </dependency>
    
            <dependency>
                <groupId>org.ocpsoft.rewrite</groupId>
                <artifactId>rewrite-config-prettyfaces</artifactId>
                <version>2.0.5.Final</version>
            </dependency>

    And prettyfaces:

     <dependency>
                <groupId>com.ocpsoft</groupId>
                <artifactId>prettyfaces-jsf2</artifactId>
                <version>3.3.3</version>
            </dependency>

    Looks right to me, it matches the documentation.

    #24719

    First thing to try is to remove this:

    <dependency>
                <groupId>com.ocpsoft</groupId>
                <artifactId>prettyfaces-jsf2</artifactId>
                <version>3.3.3</version>
            </dependency>

    It is not required if you are using the rewrite dependencies you’ve included.

    #24722

    hendrik
    Participant

    I know, it’s commented out. Only one of the two is in the POM. If i go with the prettyfaces 3.3.3 dependenciy it’s working, with the rewrite + prettyfaces compat module it’s not.

    Edit: typos…

    • This reply was modified 2 years, 11 months ago by  hendrik.
    #24724

    hendrik
    Participant

    Have a look at my test project. I’m on Glassfish 3.1.2, JavaEE 6, Servlet 3.

    EDIT: http://localhost:8080/PrettyFacesTest/home, klick the button and check URL. Rewriting should work with prettyfaces but not with rewrite + compat module.

    • This reply was modified 2 years, 11 months ago by  hendrik.
    • This reply was modified 2 years, 11 months ago by  hendrik.
    #24749

    Hey Hendrik,

    I just want to send you a quick “thank you” for uploading the example app. This will hopefully help to identify the problem. Unfortunately both Lincoln and I are very busy currently. So it may take some time to have a deeper look at your app.

    Christian

    #24750

    I just played a bit with your app. I think you are right. Something is not working correctly with the PrettyFaces compatibility module. I’m not sure what is causing this. But it seems to be caused by the path parameter in your mapping. If I remove the parameter and replace it with a constant string, everything works fine… Really weird…

    #24751

    I tried to reproduce these issues with some tests.

    Here is the pretty-config.xml:

    https://github.com/ocpsoft/rewrite/blob/master/config-prettyfaces-tests/src/test/resources/outbound/outbound-pretty-config.xml

    I’m using some h:link components to test the outbound rewriting:

    https://github.com/ocpsoft/rewrite/blob/master/config-prettyfaces-tests/src/test/resources/outbound/outbound.xhtml

    And here are the tests:

    https://github.com/ocpsoft/rewrite/blob/master/config-prettyfaces-tests/src/test/java/org/ocpsoft/rewrite/prettyfaces/outbound/OutboundRewritingTest.java#L23

    It seems like the outbound rewriting isn’t working at all as soon as there is a parameter added to the h:link. Even if I add a parameter that doesn’t correspond to a path parameter. Very weird. I wonder why other tests doesn’t fail. Perhaps our test coverage isn’t as good as we thought in this area.

    #24753

    Good news. I think I just fixed this issue.

    https://github.com/ocpsoft/rewrite/commit/96428db56c069d9b6fa04e540b9ba5549116b786

    The problem was that QueryString.build() was used for URLs even if there wasn’t a query string at all which lead to invalid parameters in the resulting QueryString object. I don’t want to bore you with the details, but I think it should work now.

    Could you perhaps give the latest build of 2.0.6-SNAPSHOT a try? Some infos on how to use the snapshots can be found here:

    http://ocpsoft.org/rewrite/docs/configuration/install

    #24842

    hendrik
    Participant

    Hey,

    i was moving last week, now back at work.

    The link to http://ocpsoft.org/rewrite/docs/configuration/install does not work for me, looks like the content could not be loaded.

    I guess i have to add the sonatype-snapshots repository, but i can’t find any 2.0.6-SNAPSHOT. Or do i have to get the snapshot from github in some way?

    #24843

    Yes, the snapshots are available in the sonatype repository:

    https://oss.sonatype.org/index.html#nexus-search;gav~org.ocpsoft.rewrite~rewrite-servlet~~~

    You should be able to get 2.0.6-SNAPSHOT if you add this repository declaration to your pom:

    <repository>
      <id>sonatype-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
    
    #24844

    hendrik
    Participant

    Thanks for the help Christian. It’s working now for my test application, i will also try the snapshot with my actual application today. That might take some time.

    #24845

    Awesome! Thanks for letting me know. I hope we will be able to release 2.0.6.Final soon.

    #24846

    hendrik
    Participant

    Looks like there is still a problem. I can’t really figure out why:

    On one page i have a viewParam like these:

    <ui:define name="metadata">
            <f:metadata>
                <o:viewParam name="id"
                             value="#{someBean.someId}"
                             required="true" />
                <f:event type="preRenderView"
                         listener="#{someBean.preRenderView}" />
            </f:metadata>
        </ui:define>

    But in my preRenderView someId is null. “id” is totally unmapped in the pretty-config, should therefore be appended as query-param (&id=whatever) and be injected into someBean.someId. Is this expected behaviour? Should the value be null?
    I’m actually trying to avoid the query-param tag because of problems like the one mentioned in http://ocpsoft.org/support/topic/error-on-ajax-post-required-value-was-null/.

    There are also 2 parentIds (in a hierarchy) in the pretty-config for the URL in question, i don’t know if this might be related.

    It works if i define a query-param mapping for anotherBean.id, set this value and invoke the navigationhandler:

    // anotherBean
    public void onRowSelect(SelectEvent selectEvent) {
            setId(whatever);
            this.navigationHandler.handleNavigation(this.facesContext, null, pretty:someBeansId);
        }
    <url-mapping id="someBeansId" parentId="parentId">
            <pattern value="/some" />
            <view-id value="/fs/private/parent/Some.xhtml" />
            <query-param name="id">#{anotherBean.id}</query-param>
        </url-mapping>

    But then i get problems with AJAX + ViewScope etc(see http://ocpsoft.org/support/topic/error-on-ajax-post-required-value-was-null/), so i actually want to navigate with a link like “/fs/private/parent/Some.xhtml?id=1234&mappedParam=whatever” which is supposed to be rewritten to /whatever/some?id=1234.

    PrettyFacesTest project works fine now, but it lacks the viewParam and navigationHandler. Should be easy to add and test though.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.

Comments are closed.