0

I'm using JSF 2.0 and I have the following on my jsf page

<p:commandLink id="takeLink"
action="#{myQBean.displayApp(app)}" value="Take">
</p:commandLink>

and the method triggered by the backing bean

public String displayApp(App app) {
    markAppAsTaken(app);
    return "SingleAppView?faces-redirect=true&appRefNo="+app.getNo()+"&verNo="+app.getVersionNo();
    }

My problem is that this approach doesn't bound the URL to the link before click, it bounds the #, and If I would to right click and open in a new tab it will open the same page.

I want the same behavior of <h:link /> tag and <h:outputLink /> to retrieve the whole url SingleAppView?faces-redirect=true&appRefNo=1&verNo=3 instead of #, and also to invoke a method in the backing bean.

I want a way to invoke the method in the backing bean and retain the full URL at the same time.

Ghada
  • 175
  • 1
  • 5
  • 17
  • What do you mean by "retain the worthy url"? Returning that String value you're achieving what an `h:link` does. – Xtreme Biker Mar 10 '14 at 14:38
  • Do you mean something like that `getFacesContext().getExternalContext().redirect(getRequest().getContextPath() + "/page.jsf?" + Constants.SOME_PARAM + "="+bean.getSomeValue());`? – Vasil Lukach Mar 10 '14 at 16:09
  • Xtreme Biker I want to have the same behavior that I would have If I used `` which means that I want the URL not the # if I hover over the link or open in a new tab.. – Ghada Mar 11 '14 at 07:19
  • Vasil Lukach not really because that won't work if I open in a new tab – Ghada Mar 11 '14 at 07:20
  • Is it acceptable if the action is only invoked on the GET request? – BalusC Mar 11 '14 at 07:56
  • BalusC yes, this is what I want, only when the Get is invoked – Ghada Mar 11 '14 at 08:06
  • http://stackoverflow.com/questions/6377798/what-can-fmetadata-and-fviewparam-be-used-for – BalusC Mar 11 '14 at 09:36
  • BalusC I'm sorry it seems that I misunderstood your question, when I was saying the GET request I meant the one that gets invoke when clicking the link, from what I understood of the link you provided that it calls the method when loading the page, I want the action to only be invoked when I click on the link – Ghada Mar 11 '14 at 10:58

1 Answers1

-1

You can use something in the lines of:

<h:link value="Take" outcome="#{myQBean.displayApp}" >
    <f:param name="appNo" value="#{app.No}" />
    <f:param name="verNo" value="#{app.VersionNo}" />
</h:link>

and...

public String displayApp() {
    String appNo = FacesContext.getExternalContext().getRequestParameterMap().get("appNo");
    App app = service.findApp(appNo);
    markAppAsTaken(app);
    return "SingleAppView?faces-redirect=true&includeViewParams=true";
}
Tasos P.
  • 2,856
  • 1
  • 18
  • 32
  • Sorry, but this answer is nonsense. As long as you're new to JSF and can't reliably answer off top of head, please actually run and test it carefully before doing it off as an answer. Bonus is, you will actually learn by experience. – BalusC Mar 11 '14 at 07:54