1

As I read in docs and tried myself, JSF 2.0 applied bookmarkable urls to h:link and h:button elements.

Is it possible to make bookmarkable URL for h:commandLink element? I experience that f:param is not applied to the result URL of h:commandLink.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sergionni
  • 13,290
  • 42
  • 132
  • 189

1 Answers1

4

h:commandLink fires a POST request, so no, it's not possible. Just use h:link.

If the sole reason of using h:commandLink is that you'd like to fire a bean action method, then just move that to the bean constructor or @PostConstruct of a request scoped bean which is attachted to the view which is opened by h:link. You can access f:param values by @ManagedProperty.

public BeanOfTargetPage {
    @ManagedProperty(value="#{param.foo}")
    private String foo;

    @PostConstruct
    public void init() {
        // Parameter 'foo' is available here.
    }

    // ...
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • yes,this commandLink invoked method on backend(in sessions scoped bean).What do you mean under request scoped bean attached for view?Should i create one more bean?This commandLink except of method firing, redirects user to other page(/details.jsf). – sergionni Dec 16 '10 at 15:19
  • The `details.jsf` page get the data from a request scoped bean, right? Just do the `@PostConstruct` job as illustrated in my answer in this bean. – BalusC Dec 16 '10 at 15:31
  • details.jsf gets data from SessionScoped bean – sergionni Dec 16 '10 at 15:49
  • Then create another request scoped bean and make the session scoped bean a managed property of the request scoped bean so that you have access to it from in the request scoped bean. – BalusC Dec 16 '10 at 15:59
  • No, it's only for URL rewriting. It doesn't turn POST actions into GET actions like as you basically want. – BalusC Dec 16 '10 at 21:51
  • BalusC,thank you for idea. Looks like working.I've done as you advised with one more thing-added outcome string to RequestScoped bean method, string looks like "details?faces-redirect=true&includeViewParams=true",according to PRG pattern.Is it ok solution? – sergionni Dec 17 '10 at 11:19
  • looks loke it's not,that i need,because if to go by this permalink,that it forwards to already remembered page in cache – sergionni Dec 17 '10 at 15:02