InputText value null when disabled is true [duplic

2020-06-23 05:09发布

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.

标签: java jsf
4条回答
欢心
2楼-- · 2020-06-23 05:35

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.

查看更多
老娘就宠你
3楼-- · 2020-06-23 05:42

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.

查看更多
成全新的幸福
4楼-- · 2020-06-23 05:46

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.

查看更多
干净又极端
5楼-- · 2020-06-23 05:49

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

查看更多
登录 后发表回答