JSF actions using Rewrite

Splash Forums Rewrite Users JSF actions using Rewrite

This topic contains 5 replies, has 2 voices, and was last updated by  Lincoln Baxter III 3 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #23821

    Will Durman
    Participant

    Does Rewrite have way to execute JSF page-action methods, like PrettyFaces did?

    For example, can you replicate this PrettyFaces configuration:

    <url-mapping id="viewItem">
      <pattern value="/store/item/#{ iid : bean.itemId }/" />
      <view-id value="/faces/shop/item.jsf" /> 
      <action>#{bean.loadItem}</action>
    </url-mapping>

    Update: I found the backwards compatibility module rewrite-config-prettyfaces-2.0.1.Final.jar referenced in this forum topic http://ocpsoft.org/support/topic/prettyfaces-4-0-0/. It seems to be functioning fine so far.

    I would like to eliminate xml configuration eventually. How do I achieve the same results using Rewrite rules?

    • This topic was modified 3 years, 2 months ago by  Will Durman. Reason: Clarified question
    #23823

    Hi Willdurman,

    Yes! There is a way to do this using Rewrite, which is actually the core mechanism that Rewrite uses to execute PrettyFaces action methods in the compatibility module.

    
          return ConfigurationBuilder
                   .begin()
                   .addRule()
                   .when(Path.matches("/name/{name}"))
                   .perform(PhaseAction.retrieveFrom(El.retrievalMethod("#{expressionLanguageBean.action}"))
                            .after(PhaseId.RESTORE_VIEW)
                            .and(Forward.to("/expression-language.xhtml")))
                   .where("name").bindsTo(PhaseBinding.to(El.property("#{expressionLanguageBean.name}"))
                            .after(PhaseId.RESTORE_VIEW));
    

    This handles both EL value injection, but also EL method invocation using the PhaseAction deferred operation handler. It should be pretty self-explanatory from here, but let me know if anything is confusing. I know it seems simple to the guy who wrote it, and that doesn’t always carry through to others!

    #23837

    Will Durman
    Participant

    Very good, I am using the sample code you provided to replace my PrettyFaces xml configuration.

    I have a followup question, is there a way to pass a matched portion of the URL directly to the action method? I am using JSF 2.

    I tried passing a hard-coded value like this:

    .perform(PhaseAction.retrieveFrom(El.retrievalMethod("#{expressionLanguageBean.action('hardCodedText')}"))

    which worked just fine. I tried passing

    .perform(PhaseAction.retrieveFrom(El.retrievalMethod("#{expressionLanguageBean.action(name)}"))

    attempting to pass the value matched by

    .when(Path.matches("/name/{name}"))

    but it fails.

    If not, I can create a field and getter/setter on the class which will work fine, but I’d like to understand what the problem is.

    • This reply was modified 3 years, 2 months ago by  Will Durman.
    • This reply was modified 3 years, 2 months ago by  Will Durman.
    #23841

    Unfortunately, you’ll have to use a getter/setter. Rewrite doesn’t support EL parameters :(, but… if you’d like, maybe you’d want to look into adding this support? It would probably involve setting some values into the ELContext via Rewrite Parameter Bindings.

    I can point you in a few places that will help you get started, but I don’t have any bright ideas coming to mind immediately.

    #23842

    Will Durman
    Participant

    OK! Well I think Rewrite is really cool, and if I run into some free time I will take a look at it. It’s a bit over my head but what’s the worse that could happen?

    #23844

    I doubt it’s over your head 🙂 Just a few Classes and Interfaces. Nothing special. Just have to get familiar, and we have lots of tests to help with that!

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

You must be logged in to reply to this topic.

Comments are closed.