开发者

InputText value null when disabled is true [duplicate]

This question already has an answer here: How to disable/enable JSF input field in JavaScript? (1 answer) Closed 5 years ago.

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.


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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜