0

In JSF, I am doing a GET request like follows:

<p:button value="Select Document" icon="fa fa-save" outcome="index">
    <f:param name="documento"
             value="#{dIGRCController.digrc.selectedDigrc.documento}" />
</p:button>

I don't want to display that value in the URL so I am trying to make a POST request instead. How can I accomplish that?

In my project I am using PrimeFaces 5.3, JSF 2.2 and OmniFaces 1.11.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Erick
  • 823
  • 16
  • 37

1 Answers1

2

Use commandButton instead of button.

The POST equivalent of exactly your GET snippet is below:

<h:form>
    <p:commandButton value="Select Document" icon="fa fa-save" action="index">
        <f:param name="documento"
                 value="#{dIGRCController.digrc.selectedDigrc.documento}" />
    </p:commandButton>
</h:form>

You only need to keep in mind that the URL change won't be reflected in address bar and that the target page is not bookmarkable anymore. This shouldn't be a problem if the target page is not idempotent, but it doesn't look like to be one ("SELECT" is always idempotent).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • That worked but when I make a POST request from search.jsf to index.jsf the URL is not updated to index.jsf. It stays as search.jsf. Can I make it change? Also, could you please explain what does it mean for a page to be idempotent? Thanks @BalusC – Erick Apr 11 '16 at 10:55
  • See 2nd and 3rd "See also" links for this spinoff question. – BalusC Apr 11 '16 at 10:58
  • Yep just saw it haha. It is using ?faces-redirect=true. Thanks you sir! – Erick Apr 11 '16 at 10:58
  • I hope you already thought about how exactly the page should behave when enduser bookmarks/copypastes/shares the URL into a different browser window or even session. – BalusC Apr 11 '16 at 11:01