defined rule doesn't work in new version rewrite.

Splash Forums Rewrite Users defined rule doesn't work in new version rewrite.

This topic contains 3 replies, has 3 voices, and was last updated by  dolphincn 5 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18325

    dolphincn
    Participant

    old version rewrite can run well, but changed to new version 1.05 or 1.0.6-SNAPSHOT, the following rule could not work. what’s wrong?

    .addRule(

    Join.path(“/manager/category/{categoryClass.categoryType}.xhtml”)

    .when(Path.matches(“^/manager/category/(menu|product|article).xhtml$”))

    .to(“/manager/manager/category/category_list.xhtml”)

    )

    .addRule(

    Join.path(“/{testClass.categoryType}/{testClass.categoryId}/{testClass.action}.xhtml”)

    .to(“/site/{testClass.categoryType}/{testClass.action}.xhtml”)

    .when(Path.matches(“^/(product|article)/[0-9]+/[A-Za-z][a-zA-Z0-9_-]+.xhtml$”))

    .withInboundCorrection()

    )

    .addRule(

    Join.path(“/{testClass.categoryType}/{testClass.categoryId}/{testClass.action}.xhtml”)

    .to(“/site/{testClass.categoryType}/{testClass.action}.xhtml”)

    .when(Path.matches(“^/(product|article)/[0-9]+/[A-Za-z][a-zA-Z0-9_-]+.xhtml$”))

    .withInboundCorrection()

    )

    #22469

    If I remember correctly Lincoln said that Path doesn’t support regular expressions any more. We modified this because 90% of all problem with rewrite rules in PrettyFaces 3.x occurred due to invalid regular expressions. Building them can get very complex and error prone. Especially because you have to escape certain characters (like .).

    Therefore Path now only allows constant strings. BUT if you have a variable part in your URL you can use a parameter and define a constraint for this one using where(..).matches().

    Your first rule for example should work like this:

    .addRule(
    Join.path("/manager/category/{categoryClass.categoryType}.xhtml")
    .where("categoryClass.categoryType").matches("(menu|product|article)")
    .to("/manager/manager/category/category_list.xhtml")
    )

    As you see in this example your rule even gets much cleaner because you don’t have to repeat the URL in Join.path() and when().

    I hope this works for you. :)

    Christian

    #22470

    Thanks Christian,

    Yes, that’s right. You can also add constraints to your parameters via:

    .addRule(
    Join.path("/manager/category/{categoryClass.categoryType}.xhtml")
    .where("categoryClass.categoryType").constrainedBy(new RegexConstraint("(menu|product|article)"))
    .to("/manager/manager/category/category_list.xhtml")
    )

    The advantage of constraints is that you can add multiple. ( I think. ;))

    #22471

    dolphincn
    Participant

    Thank Christian and Lincoln for your hard work and online support,

    It is work with multi constraints

    .where(“…”).constrainedBy(new RegexConstraint(“….”))

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

You must be logged in to reply to this topic.

Comments are closed.