如果将相同的backing bean属性以相同的形式绑定到两个输入字段,那么JSF的行为是什么? [英] What is the JSF behaviour, if you bind the same backing bean property to two input fields in the same form?

查看:58
本文介绍了如果将相同的backing bean属性以相同的形式绑定到两个输入字段,那么JSF的行为是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果两个输入字段绑定到同一会话范围的Backing Bean属性,则JSF中是否存在已定义的行为.

Is there a defined behaviour in JSF, if two input fields are bound to the same session scoped Backing Bean property.

这是我的代码段

<h:form id="myForm">
   <h:inputText id="field1" value="#{TheBackingBean.theProperty}" />
   <h:inputText id="field2" value="#{TheBackingBean.theProperty}" />

   <h:commandButton id="continueButton" action="#{TheBackingBean.doSomething}" />
</h:form>

我的问题:如果field1和field2接收不同的值,那么将如何绑定到后备bean属性?甚至允许吗?

My question: If field1 and field2 receive different values, what will be bound to the backing bean property? Is this even allowed?

我知道这是一个粗略的情况.我的动机是,我们为应用程序运行了htmlunit测试.在我们的JSF应用程序中,我们想使用一个很酷的Ajaxified自定义组件.这与htmlunit不能很好地协同工作.所以我的想法是,我只是将一个隐藏字段绑定到同一属性.然后,单元测试将填充隐藏的字段,而不是真实"的东西.

I know this is a crude scenario. My motivation is, that we have htmlunit tests running for our application. In our JSF application we want to use a cool ajaxified custom component. This doesnt work together very well with htmlunit. So my idea was, I just put in a hidden field that binds to the same property. The unit test then fills the hidden field instead of the "real" thing.

致谢

推荐答案

我认为允许使用这种代码,但是我不确定提交后 theProperty 的价值.我认为JSF将执行以下操作:

I think this kind of code is allowed, but I am not sure of the value of theProperty after the submission. What I think is that JSF will do the following:

TheBackingBean.setTheProperty(field1.value);
TheBackingBean.setTheProperty(field2.value);

但是,据我所知,没有任何东西指定setter调用的顺序.因此,在更新值 JSF阶段之后,您将不确定 theProperty 是否等于 field1.value field2.值.

However, nothing - as far as I know - specifies the order of the setter calls. Thus, after the update values JSF phase, you will not be sure if theProperty will be equal to field1.value or field2.value.

关于您的方案,您说要将相同的属性绑定到inputText和隐藏的文本.由于hiddenText不会提交其值,与inputText不同,因此不会发生此问题.确实,如果您具有这种JSF代码:

Concerning your scenario, you say that you want to bind the same property to an inputText and an hiddenText. As the hiddenText will not submit its value, unlike the inputText, this problem will not occur. Indeed, if you have this kind of JSF code:

<h:inputText id="field1" value="#{TheBackingBean.theProperty}"/>
<h:inputHidden id="field2" value="#{TheBackingBean.theProperty}"/>

然后,JSF将只执行以下操作:

then JSF will only do:

TheBackingBean.setTheProperty(field1.value);

在提交阶段.

这篇关于如果将相同的backing bean属性以相同的形式绑定到两个输入字段,那么JSF的行为是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆