0

I need to send some parameters from one xhtml to another, but I don't want these parameters to appear in the URL. How to do that? I could use p:commandLink, but then I don't know how to open the destination page from the bean method. The destination page should be accessible by friendly URL, not by xhtml name. This code will open the page /users/view. How can I send parameters without them appearing in the URL?

   <h:outputLink value="/users/view">
      <h:outputText value="#{entry.employee}" />
   </h:outputLink>
ACV
  • 9,964
  • 5
  • 76
  • 81
  • 1
    How do you want to render page before it's requested? If it's a request scoped bean, then you can probably use @PostConstruct method. But I'm not sure what the real problem is. Maybe it would help if you told us what is the REAL problem. This looks like you're overthinking something which has an easy solution you didn't think of. – NeplatnyUdaj Apr 28 '15 at 13:06
  • 1
    It's hard to guess without seeing the code, but you can use `process` attribute of the `commandLink` to submit the values to the backing beans before performing the action. – NeplatnyUdaj Apr 28 '15 at 13:20
  • You can use p:commandLink. Just implement action method in a backing bean, which will return String "/users/view" – NeplatnyUdaj Apr 28 '15 at 13:28
  • The problem is that I cannot make it work with the returning string "/users/view" from the bean method. – ACV Apr 28 '15 at 13:36

1 Answers1

1

Ignoring the strange design, you could use put the data in the flash scope and send a redirect in a <h:commandLink> action method:

public void view() throws IOException {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.getFlash().put("employee", employee);
    ec.redirect(ec.getRequestContextPath() + "/users/view");
}

And then in the backing bean associated with the target page:

@PostConstruct
public void init() {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    employee = (Employee) ec.getFlash().get("employee");
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • You'd better explicitly mention in every single future question that you're on Liferay. Liferay is a portlet environment and it's a world of difference as compared to servlet environment, which I will always assume when nothing in the question suggests otherwise. Portlets are very rare and I know nothing about them. You'd better unaccept the answer so I can delete it. – BalusC Apr 29 '15 at 06:14
  • You are right, but the answer is correct for the normal Servlet based environment. Let's not delete it because it works fine. Thanks – ACV Apr 29 '15 at 06:32
  • ec.getFlash() won't work: http://stackoverflow.com/questions/10595760/adding-faces-message-to-redirected-page-using-externalcontext-redirect – ACV Apr 29 '15 at 11:58
  • 1
    That question concerns an action invoked during `preRenderView` event, not via e.g. `` and is thus not applicable in your case. – BalusC Apr 29 '15 at 12:00