Keep url parameters when posting

Splash Forums Rewrite Users Keep url parameters when posting

This topic contains 8 replies, has 3 voices, and was last updated by  detestable 4 years, 10 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #18602

    detestable
    Participant

    I’m not sure if this is achievable in JSF, may be it’s not directly related with rewrite but I’m asking here anyway.

    I’d like to post data on a rewriten url :

    /admin/{segmentIdentifier}/product

    With the following rule :

    .defineRule()
    .when(Direction.isInbound()
    .and(Path.matches("/admin/{segmentIdentifier}/product")
    .where("segmentIdentifier")
    .bindsTo(El.property("#{segmentBean.identifier}"))
    )
    )
    .perform(Forward.to("/WEB-INF/faces/admin/product.xhtml"))
    .addRule(Join.path("/admin/{segmentIdentifier}/product").to("/WEB-INF/faces/admin/product.xhtml").when(Direction.isOutbound()))

    In product.xhtml I have a form :

    <h:form>
    (...)
    <h:commandButton action="#{productBean.create}" value="Create" />
    </h:form>

    The problem I’m facing is that I’m getting in the html result something like :

    <form action="/WEB-INF/faces/admin/product.xhtml"

    Because no rules apply.

    How can I keep my segmentIdentifier in this case?

    #22816

    Good question :) Do you have the rewrite-integration-faces dependency installed in your project? This should fix compatibility with JSF (note, this module is moving to PrettyFaces in the next release or so.)

    #22817

    Shouldn’t it be:

    .addRule(Join.path("/admin/{segmentIdentifier}/product")
    .to("/WEB-INF/faces/admin/product.xhtml")
    .where("segmentIdentifier")
    .bindsTo(El.property("#{segmentBean.identifier}"))
    )

    I think one Join should work fine here.

    #22818

    detestable
    Participant

    @lincoln

    I just added rewrite-integration-faces and it looks like it is working! Awesome!

    I’m just getting some error randomly when submitting the form :

    javax.servlet.ServletException: org.ocpsoft.rewrite.exception.RewriteException: El provider [org.ocpsoft.rewrite.faces.FacesExpressionLanguageProvider] could not inject property [#{segmentBean.identifier}} with value [[Ljava.lang.String;@7945c7e6]

    root cause

    org.ocpsoft.rewrite.exception.RewriteException: El provider [org.ocpsoft.rewrite.faces.FacesExpressionLanguageProvider] could not inject property [#{segmentBean.identifier}} with value [[Ljava.lang.String;@7945c7e6]

    root cause

    java.lang.IllegalArgumentException: FacesContext.getCurrentInstance() returned null. EL expressions can only be evaluated in the JSF lifecycle. You should use PhaseAction and PhaseBinding to perform an deferred operation instead.

    I’m still using the same rewrite rules from my first post.

    @Christian

    When I use the rule you wrote segmentBean.identifier remains empty.

    Just in case :

    SegmentBean.java :

    import javax.inject.Inject;
    import javax.inject.Named;

    @Named
    @RequestScoped
    public class SegmentBean {

    private String identifier;

    public String getIdentifier() {
    return identifier;
    }

    public void setIdentifier(String identifier) {
    this.identifier = identifier;
    }
    }

    pom.xml :

    <properties>
    <opcsoft.rewrite.version>1.0.5.Final</opcsoft.rewrite.version>
    </properties>
    <dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-servlet</artifactId>
    <version>${opcsoft.rewrite.version}</version>
    </dependency>
    <dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-integration-cdi</artifactId>
    <version>${opcsoft.rewrite.version}</version>
    </dependency>
    <dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-integration-faces</artifactId>
    <version>${opcsoft.rewrite.version}</version>
    </dependency>

    Am I doing something wrong?

    #22819

    Try wrapping your El.property("#{segmentBean.identifier})" in PhaseBinding.to(El.property("#{segmentBean.identifier}")). That should work :)

    #22820

    detestable
    Participant

    With PhaseBinding.to(El.property("#{segmentBean.identifier}"))

    SegmentBean.identifier is never set!

    .defineRule()
    .when(Direction.isInbound()
    .and(Path.matches("/admin/{segmentIdentifier}/product")
    .where("segmentIdentifier")
    .bindsTo(PhaseBinding.to(El.property("#{segmentBean.identifier}")))
    )
    )
    .perform(Forward.to("/WEB-INF/faces/admin/product.xhtml"))
    .addRule(Join.path("/admin/{segmentIdentifier}/product").to("/WEB-INF/faces/admin/product.xhtml").when(Direction.isOutbound()))

    #22821

    Try selecting a phase or phases?

    PhaseBinding.to(El.property("#{segmentBean.identifier}")).after(PhaseId.RESTORE_VIEW)

    Strange that this wouldn’t work…

    #22822

    I think you have to specify the phase for which the binding should be executed:

    .bindsTo( PhaseBinding.to(El.property("#{segmentBean.identifier}")).after(PhaseId.RESTORE_VIEW) )

    #22823

    detestable
    Participant
    .defineRule()
    .when(Direction.isInbound()
    .and(Path.matches("/admin/{segmentIdentifier}/product")
    .where("segmentIdentifier")
    .bindsTo(PhaseBinding.to(El.property("#{segmentBean.identifier}")).after(PhaseId.RESTORE_VIEW))
    )
    )
    .perform(Forward.to("/WEB-INF/faces/admin/product.xhtml"))
    .addRule(Join.path("/admin/{segmentIdentifier}/product").to("/WEB-INF/faces/admin/product.xhtml").when(Direction.isOutbound()))

    Is working well.

    I wish I could make only one rule but I’m glad it is working now!

    Thank you!

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

You must be logged in to reply to this topic.

Comments are closed.