4

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.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Jacob
  • 14,463
  • 65
  • 207
  • 320
  • Make a hidden inputText attached with some valus in jsf and get the value of disabled inputText using javascript and provide it to hidden inputText. – Vinod Chauhan Dec 17 '18 at 05:17

4 Answers4

3

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.

jFrenetic
  • 5,384
  • 5
  • 42
  • 67
2

You should try readonly=true instead of disabled=true (just like in plain HTML)

Tristan
  • 8,733
  • 7
  • 48
  • 96
  • If I make readonly true, then from calendar popup window user could select a date values in inputText field. – Jacob Aug 07 '11 at 08:44
  • maybe you should clarify what you would like to disable, and what should not be disabled... – Tristan Aug 07 '11 at 10:03
  • Based on a condition, I would like to disable the inputText. InputText is attached with a popup calendar for user to pick dates. If I make inputText readonly then user is able to select dates from popup calendar. Ideally I would like user not to make any change in inputText. Like you mentioned disabled would make values null in jsf page. – Jacob Aug 07 '11 at 10:25
  • This way, HTML will indeed send the value to server, but JSF still won't set the value in model. So this answer is invalid for the question in its current form. – BalusC Nov 06 '15 at 07:26
  • 1
    making readonly=true also creates same problem as I found out during my work – Ajay Sharma Apr 15 '16 at 06:52
2

The browser is following the HTML 4.0.1 spec:

A successful control is "valid" for submission.

...elided text...

  • Controls that are disabled cannot be successful.

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:

If a Renderer chooses to implement decode behavior, it must consult the "disabled" and "readonly" attributes of the component to be rendered, if the value of either attribute is equal to, ignoring case, the string "true" (without the quotes) the decode method must take no action and return immediately.

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.

McDowell
  • 107,573
  • 31
  • 204
  • 267
1

When you set disabled = true or readonly = 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 property disabled = true.

bilelovitch
  • 1,975
  • 1
  • 16
  • 24