tags:

views:

22

answers:

1

I have a JSF page which has a h:inputHidden component and I am setting a hardcoded value. I have set the id, name and value attributes. But when I access the value from the managed bean, I am getting null.

I also noticed that, during runtime, the name is changing to some auto generated id.

Appreciate any help.

+3  A: 

The behavior of the <h:inputHidden> is the same as for a <h:inputText> component for example:

<h:inputHidden id="myHiddenField" value="#{myBean.myValue}"/>

will refer to the property myValue of the bean myBean. So you will have to provide both getMyValue() and setMyValue(String) in this bean.

So if you change the value of this hidden field on the client side (using Javascript), then the new value will be updated on the bean side once the form is submitted.

Regarding the ID, you must specify the id attribute, otherwise JSF will generate one for you (something like j_id123 for example). If you specify a value for this attribute, the ID of the HTML tag will be the one you specified, prefixed by your form ID. So in the following example:

<h:form id="myForm">
    <h:inputHidden id="myField" .../>

the HTML <input> tag will have the id myForm:myField (note the : used as a separator of ids).

romaintaz