Does prettyfaces 3.3.0 support EL2 method params for the action?

Splash Forums PrettyFaces Users Does prettyfaces 3.3.0 support EL2 method params for the action?

This topic contains 4 replies, has 3 voices, and was last updated by  Christian Kaltepoth 6 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18035

    pestades
    Participant

    Hi all,

    I’m trying to use EL 2 method params with prettyfaces in order to achieve something like this:

    xhtml:

    —-

    <h:commandButton value=”edit” action=”#{itemController.editAction(item)}” />

    Controller bean:

    public String editAction(Item item) {

    }

    This works fine on my setup (Tomcat 6.0.32, EL2.2, PrettyFaces 3.3.0)

    But when I try to use prettyfaces is not working (the editAction method is never reached):

    <h:commandButton value=”edit” action=”pretty:itemEdit” />

    This is the config:

    <url-mapping id=”itemEdit”>

    <pattern value=”/item/” />

    <view-id value=”/item/edit.jsf” />

    <action onPostback=”false”>#{itemController.editAction(item)}</action>

    </url-mapping>

    Does it makes sense or it’s not currently supported?

    Thanks in advance,

    Pablo.

    #21430

    This is not currently supported in PrettyFaces 3.x. It is already possible in PrettyFaces 4.x with a little more configuration if you are using CDI (http://docs.jboss.org/weld/reference/latest/en-US/html/environments.html) – but it does not look like you are?)

    Install 4.0.0-SNAPSHOT:

    https://github.com/ocpsoft/prettyfaces/wiki/Snapshots (use version 4.0.0-SNAPSHOT)

    You will also need to add a Rewrite extensions for CDI and Faces:

    <dependency>
    <groupId>com.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-integration-cdi</artifactId>
    <version>1.0.0.Alpha4</version>
    </dependency>
    <dependency>
    <groupId>com.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-integration-faces</artifactId>
    <version>1.0.0.Alpha4</version>
    </dependency>

    Then you need to implement a custom Rewrite provider: (PrettyFaces 4.0.0 is based on Rewrite, which is included automatically if you are using Maven – you just need to add the extensions above)

    Perform steps 3 and 4 here:

    http://ocpsoft.com/rewrite/

    Then you need to add your custom rule:

    .addRule(Join.path("/item/").to("/item/edit.jsf")
    .perform(PhaseAction.retrieveFrom(
    El.retrievalMethod("#{itemController.editAction(item)}"))));

    I hope this helps, sorry we don’t support it in 3.x :) can only go so fast.

    ~Lincoln

    #21431

    Oh, I suppose if you aren’t using CDI, you could do replace the “rewrite-integration-cdi” extension with your own implementation of com.ocpsoft.rewrite.spi.ExpressionLanguageProvider

    Which requires that you find a way to access the EL-context from JSF, which can work, but might be tricky. You can look at what I’ve done for the CDI extension here: https://github.com/ocpsoft/rewrite/blob/master/integration-cdi/src/main/java/com/ocpsoft/rewrite/cdi/CdiExpressionLanguageProvider.java

    If you decide to do this, would you mind showing us how you did it with JSF? It shouldn’t be too hard, just not much time here at the moment :)

    #21432

    pestades
    Participant

    Hi Lincoln,

    Thanks so mucho for the quick reply :)

    We can’t consider using rewrite until it goes GA :(

    Also, I don’t like very much having to define the navigation rule in code, some kind of XML document will be great.

    Cheers,

    Pablo.

    #21433

    Hey Pablo,

    I think you actually don’t need things like arguments in EL method invocations very often when you are using PrettyFaces. What about some more RESTful URL approach? Something like this:

    Link to the edit page like this. This will create a standard HTML link which will result in a simple GET request when clicked. I assume currentItem is the item you are currently rendering (in a table or something like this):

    <pretty:link mappingId="itemEdit">
    <f:param value="#{currentItem.id}" />
    Click me!
    </pretty:link>

    The URL mapping for the edit page (a URL of the format /item/23):

    <url-mapping id="itemEdit">
    <pattern value="/item/#{ itemController.id }" />
    <view-id value="/item/edit.jsf" />
    <action onPostback="false">#{ itemController.editAction }</action>
    </url-mapping>

    And the class used for the item edit page:

    public class ItemController {

    // injected by PrettyFaces
    private Long id;

    // loaded in action method
    private Item item;

    public void editAction() {
    item = itemDao.getById(id);
    }

    /* getters and setters */

    }

    It loads the item using the ID from the URL. This will create a very RESTful URL that will work independently from other pages.

    That’s the way I design my apps! :)

    Christian

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

You must be logged in to reply to this topic.

Comments are closed.