简体   繁体   English

如果已启用,则无法修改h:inputText

[英]Can't modify h:inputText if it's enabled

I've got a simple question here. 我在这里有一个简单的问题。 If I'm asking it is because I can't find any answer neither here nor google. 如果我问这是因为我既没有找到任何答案,也没有谷歌。

I'm using IceFaces 3.1. 我正在使用IceFaces 3.1。

I'm filling an inputtext from a java bean. 我正在从java bean填充inputtext。 It only works when it has the attribute disabled="true" . 它仅在具有disabled =“true”属性时才有效。

Here is the xhtml code: 这是xhtml代码:

<h:inputText value="#{PageCode.quantity}" disabled="false"/>

And the java code (called form somewhere): 和java代码(在某处称为表单):

this.setQuantity(1);

It doesn't contains the value. 它不包含值。 It's not CSS because I've debugged it, and there is a null value. 这不是CSS,因为我已经调试了它,并且有一个空值。

But if I change it to: 但是,如果我将其更改为:

 <h:inputText value="#{PageCode.quantity}" disabled="true"/>

It works. 有用。 But I need it enabled so as to edit it an so on... 但我需要它启用,以便编辑它...

How can it be posible? 它怎么可能有效?

Apparently you called setQuantity(1) at the wrong moment. 显然你在错误的时刻调用了setQuantity(1)

When not disabled, the <h:inputText> will set its submitted value during update model values phase. 未禁用时, <h:inputText>将在更新模型值阶段设置其提交的值。 So if you have manually set it before the update model values phase (eg during validations phase inside a validator or a value change listener), then it would be overridden by the submitted value later. 因此,如果您在更新模型值阶段之前手动设置它(例如,在验证程序或值更改侦听器内的验证阶段),那么稍后它将被提交的值覆盖。 If the component is disabled, then it won't set its submitted value. 如果禁用该组件,则不会设置其提交的值。 This explains the symptoms you're seeing. 这解释了您所看到的症状。

You need to make sure that you call setQuantity(1) during invoke action phase, which is after the update model values phase. 您需要确保在调用操作阶段(即更新模型值阶段之后 setQuantity(1)调用setQuantity(1)

Based on most commonly occurring beginner's mistakes, I guess that you actually did the job in a valueChangeListener method while you're not interested in the old value. 基于最常见的初学者错误,我猜你实际上是在valueChangeListener方法中完成了这项工作,而你对旧值不感兴趣。 You shouldn't do that. 你不应该这样做。 You should use <f:ajax listener> instead. 您应该使用<f:ajax listener>代替。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM