Matching rule with same pattern

Splash Forums Rewrite Users Matching rule with same pattern

This topic contains 7 replies, has 2 voices, and was last updated by  chongma 1 year, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #26893

    chongma
    Participant

    I want to configure two different rules which match a prefix followed by an id

    // first
    .addRule(
    Join.path("/{prefix}{someId}").to("/first.xhtml"))
    .where("prefix").matches("(first)")
    .where("someId").matches("[0-9]")
    
    // second
    .addRule(
    Join.path("/{prefix}{someId}").to("/second.xhtml"))
    .where("prefix").matches("(second)")
    .where("someId").matches("[0-9]")

    Also tried this sort of thing

    .addRule(
    Join.path("/first{someId}").to("/second.xhtml?prefix=first"))
    .addRule(
    Join.path("/second{someId}").to("/second.xhtml?prefix=second"))

    The problem is that forms on the pages point to /second.xhtml instead of /second0001. And h:link doesn’t seem to work properly. And the parameters are not picked up properly inside beans. Every thing I try *almost* works but fails slightly in one respect.

    Hope that makes sense

    #26894

    First question, this might be a simple solution:

    Are you using rewrite-integration-faces?

    <dependency>
       <groupId>org.ocpsoft.rewrite</groupId>
       <artifactId>rewrite-integration-faces</artifactId>
    </dependency>

    If this dependency is missing, that could certainly explain the behavior you are seeing. If you already have that dependency, it could be something else.

    #26895

    chongma
    Participant

    That dependency was missing and adding it seems to have cleared up some of the issues. The original issue still seems to persist. e.g.

    builder.addRule(Join.path("/{prefix}{someId}")
    .to("/first.xhtml")).where("prefix")
    .matches("(first)");

    It is retrieving someId like this:

    FacesContext.getCurrentInstance().getApplication()
    .evaluateExpressionGet(context,"#{param.someId}", Integer.class)

    It is complaining that param.someId is identical to param.prefix i.e. a String populated with the value of “first”. I have tried binding parameters

    #26896

    Could you post the error message?

    Also, a question… Why are you matching “first” as a parameter at all? Why not just do this?

    Join.path("/first{someId}").to("/first.xhtml")

    alternatively you could do this:

    .addRule(Join.path("/{prefix}{someId}").to("/{prefix}.xhtml")).where("prefix").matches("(first)")

    That way “prefix” would actually have a value on outbound generation.

    #26897

    chongma
    Participant

    This line

    setSomeId(context.getApplication().evaluateExpressionGet(context,
    					"#{param.someId}", Integer.class));

    produces this error
    javax.el.ELException: Cannot convert first of type class java.lang.String to class java.lang.Integer
    I tried your examples but it seems to have the same result

    #26898

    chongma
    Participant

    here is a test war with source files. tested on TomEE plume. using rule builder.addRule(Join.path("/{prefix}{someId}").to("/first.xhtml")).where("prefix").matches("(first)");

    if i load for instance http://localhost:8080/Test/first808 the result is javax.el.ELException: Cannot convert first of type class java.lang.String to class java.lang.Integer

    if i debug and look inside FacesContext->externalContext->parametermap i see prefix=first, someId=first

    #26899

    chongma
    Participant

    marked dependencies as scope provided in order to upload war file

    Attachments:
    1. Test.war
    #26901

    chongma
    Participant

    sorry uploading again. realised i had included primefaces as well so this one includes everything needed

    Attachments:
    1. Test1.war
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Comments are closed.