I have an inputText on my JSF page and a JavaScript calendar popup is attached to it. Conditionally I'm setting the inputText disabled property to true and false.
When I set disabled = true
and when I then write JSF values to the database, the value in inputText is null. I believe this is due to the disabled = true
.
Is there any way to retain the value in the inputText box even though disabled = true
?
I am using JSF 1.1.
When you set
disabled = true
orreadonly = true
, the JSF mechanism does not send (or processe) the values. Is that why you write a null value in the DB.As a solution, you have to store the values in variable and show it in the
inputText
with the propertydisabled = true
.Another workaround would be to temporarily enable this input when submitting the form, and after model is updated, disable it again. There also was some solution with using hidden input with the same id, but unfortunately I don't remember how it exactly works.
The browser is following the HTML 4.0.1 spec:
Disabled form controls are not submitted as part of the form.
As an additional security measure the JSF component renderer should not process the value in the Apply Request Values phase if it finds
isDisabled() == true
.From the HTML render kit doc:
Since the Apply Request Values phase runs first, evaluation of these booleans cannot be affected by anything in your form submission (unless you bind them to
#{param.foo}
expressions - beware of any security considerations).Your form design and submission strategy must take these constraints into account.
You should try readonly=true instead of disabled=true (just like in plain HTML)