• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF retrieve hidden input

 
nikos karanikos
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code

<h:form id="theform">
<h:inputHidden id="user_id" value="3" />
<h:commandButton action="userprofile.xhtml?faces-redirect=true" value="Profile" />
</h:form>
How i can retrieve the value of user_id at page userprofile.xhtml?
Thank you
 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No like that.

The "value=" attribute in an input control is supposed to be an EL backing bean property reference expression and NOT a manifest constant or a (read-only) function call.

In other words:



This will cause the userId property of your backing bean (myBean) to be sent out as part of the initial View render and to be set from the form automatically when the form is submitted.

In practical terms, you could just save the effort by ensuring that "myBean" has sufficiently wide scope (and remember, in JSF, Request Scope Is Almost Useless) and just keeping the userId in the bean rather than just send it out and read it back. But let's say that you have some client-side javascript that wants to update the userId. In that case the client-side code would have modified the hidden value and that modified value would be automatically posted to myBean when the form is submitted.
 
nikos karanikos
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is that user_id takes value while the datatable is created. So i can not use bean to pass the value. So i put the value from the datatable and i want to pass this value to the page userprofile where i want to use it? Do you unterstand whan i am trying to do?
Thank you
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nikos karanikos wrote:My problem is that user_id takes value while the datatable is created. So i can not use bean to pass the value.
Thank you


You can pass the value to the backing bean using the f:param tag inside, say, an h:commandLink which posts to an action in the backing bean. You can then retrieve that selected value from request scope in the backing bean method and put it where your next page will access it.
 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid I don't understand. If you are creating a datatable row, the logic that does the creation will normally either be in a JSF backing bean or in code invoked from a JSF backing bean.

If the page you are displaying uses a different backing bean, there are ways to transfer the necessary information from one bean to another on the server side.

As in the case of EL, I recommend avoiding the f:param option unless there's no choice. Anything that makes the View Definition and the Backing Bean have to know about each other's internals raises the cost of program maintenance.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!