0

What is a proper way of use h:inputHidden to sending parameters between pages?

kuba44
  • 1,838
  • 9
  • 34
  • 62

2 Answers2

3

That's not possible in JSF (HTTP protocol itself doesn't work like that). What you call page is a view in JSF, given by a navigation case or outcome. h:inputHidden is basically, another input into a form which will be sent to the managed bean of the current view when the form is submitted.

What you need for sending parameters between views is the f:param tag appended to a h:button or h:commandLink in order to perform a sole GET request or append your parameters directly when performing a redirection.

There's also the chance of using JSF flash scope which is specified in 2.x specs, but not yet properly implemented by Mojarra. Until it's solved, you can hack in some way a @SessionScoped bean, setting there the parameters you need and removing them inmediatelly after taking them. Nevertheless, you could implement your own custom scope for that too.

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • so what do you say about this: http://stackoverflow.com/questions/2361616/whats-the-best-way-of-sending-parameters-between-pages ? If I want to use `h:inputHidden` have I add data do one `@ViewScope` bean and get it by `@ManagedProperty` in other `@ViewScope` bean? – kuba44 Jan 03 '14 at 11:54
  • First of all, that's a link which speaks about request scoped environments. JSF 1.x didn't provide capabilities to maintain the state of a view, so you should do it using `h:inputHidden` attributes, which were continuously caching the current state at client side, in order to manually imitate nowadays `@ViewScoped` behaviour. That post doesn't specifically mention JSF 1.x but I'm almost sure it's oriented to that (2010year). Here there's not *view* concept, they're only talking about requests and redirections. Also, even it mentions `h:inputHidden`, doesn't do with the mean you're looking for. – Aritz Jan 03 '14 at 12:06
  • Just forget about `h:inputHidden`. It's not useful anymore at JSF 2.x environments, unless you want to perform some Javascripting specific work. – Aritz Jan 03 '14 at 12:08
  • I will continue here: http://stackoverflow.com/questions/20903577/whats-the-best-way-of-sending-a-lot-ofparameters-between-pages – kuba44 Jan 03 '14 at 12:23
1

This tag is designed to render a HTML hidden input tag: <input type="hidden" ... />.
The tag can be used to send its values between view and managed-bean. When used, it does not appear through the view, but it's supposed to send any attribute/parameter that occupies, to the corresponding view/managed-bean. However, this tag is not supposed to hold and transfer data between views while there're others way to do by (request parameters, scope session, etc.).

Omar
  • 1,430
  • 1
  • 14
  • 31
  • @Omar, what do you mean with send parameters between the views? I think also it would be better explained with some sample code – Aritz Jan 03 '14 at 10:22
  • @kuba44, here's a simple example to do it in a useful case between managed-bean and view: [JSF 2 hidden value example](http://www.mkyong.com/jsf2/jsf-2-hidden-value-example/). Whilst transfering data between views seems to have no interest while there're other ways to do by (request parameters, scope session, etc.). – Omar Jan 03 '14 at 10:45
  • @XtremeBiker, i meant what the question's owner meant: sending h:inputHidden fields' values between views. – Omar Jan 03 '14 at 10:47
  • 1
    @Omar, AFAIK hidden inputs can only be used for POST requests. To switch between views you need to perform a GET in some way, that's where hidden inputs are irrelevant. You need either a view param or use flash scope (even it's still buggy in Mojarra, hope they will solve it for 2.1.27-2.2.5 branches). – Aritz Jan 03 '14 at 10:51
  • 1
    @XtremeBiker, i do agree with you. That's why they're not purposive in this case. Updated, thanks. – Omar Jan 03 '14 at 11:11