简体   繁体   English

f:ajax侦听器无法与h:selectOneRadio一起使用

[英]f:ajax listener not working with h:selectOneRadio

Edited with additional info for clarity 使用其他信息进行编辑以使内容更清晰

We are migrating application from JBoss 5 to Tomee 7.0.1+. 我们正在将应用程序从JBoss 5迁移到Tomee 7.0.1+。 On Tomee we are using MyFaces 2.2.10 and RichFaces 4.2.0 (on Jboss we used Mojarra JSF instead of MyFaces). 在Tomee上,我们使用MyFaces 2.2.10和RichFaces 4.2.0(在Jboss上,我们使用Mojarra JSF代替MyFaces)。

We have a problem with f:ajax listener not triggering on value change in the radio button list. f:ajax侦听器有一个问题,单选按钮列表中的值更改未触发。 Here is our code: 这是我们的代码:

 <h:selectOneRadio value="#{managedBean.paramsType}"
   layout="pageDirection">
   <f:selectItem itemValue="Item1" itemLabel="Item1" />
   <f:selectItem itemValue="Item2" itemLabel="Item2" />
   <f:ajax render="@form" execute="@form" listener="#{managedBean.checkSelection}" />
  </h:selectOneRadio>

<h:selectManyCheckbox value="#{managedBean.objectList}" layout="pageDirection">
   <f:selectItem itemValue="checkOption1" itemLabel="Option1" itemDisabled="#{managedBean.paramsType == 'Item3'}"/>
   <f:selectItem itemValue="checkOption2" itemLabel="Option2" itemDisabled="#{managedBean.paramsType == 'Item1'}"/>
   <f:selectItem itemValue="checkOption3" itemLabel="Option3" itemDisabled="#{managedBean.paramsType == 'Item2'}"/>
</h:selectManyCheckbox>

In managed bean the checkSelection method has the following signature: 在托管bean中,checkSelection方法具有以下签名:

public void checkSelection()
{
 //update objectList (select or deselect items) based on radio button selection
}

Check selection is never called when running the app on TomEE but the same worked on JBoss (identical code). 在TomEE上运行应用程序时,永远不会调用检查选择,但是在JBoss(相同代码)上也是如此。

On TomEE, we tried adding AjaxBehaviorEvent as input parameter of checkSelection method, but the method is never called with or without this parameter. 在TomEE上,我们尝试将AjaxBehaviorEvent添加为checkSelection方法的输入参数,但是无论是否使用此参数,都不会调用该方法。 It looks like the listener attribute of f:ajax is not processing the event for some reason. 看起来f:ajax的listener属性由于某种原因未处理事件。

No errors are reported in the browser console or in application or server logs - the method is simply never called. 浏览器控制台,应用程序或服务器日志中均未报告任何错误-根本不会调用该方法。 Also, h:messages doesn't display any error. 另外,h:messages不会显示任何错误。

Also, we tried with a4j:ajax and valueChangeListener. 此外,我们尝试使用a4j:ajax和valueChangeListener。 a4j:ajax behaves the same as f:ajax - method defined in managed bean is not called; a4j:ajax的行为与f:ajax相同-不调用托管bean中定义的方法; valueChangeListener doesn't work for us because it is triggered by a different event than the f:ajax listener and we need a change of selection in radio buttons to affect the selection of ah:selectManyCheckbox component on the same form. valueChangeListener对我们不起作用,因为它由与f:ajax侦听器不同的事件触发,并且我们需要更改单选按钮中的选择以影响对同一表单上的ah:selectManyCheckbox组件的选择。

For newcomers: I had pretty much the same issue, practically exhausted the Internet, no solution. 对于新来者:我遇到了几乎相同的问题,实际上耗尽了Internet,没有解决方案。

Solved when migrated from jsf 2.2(.?) to 2.3. 从jsf 2.2(。?)迁移到2.3时解决。

By the way, @#$%!@#$*, 2 days lost in the other way, so take this as the hard way to learn/remember, when facing such problems, ALWAYS upgrade your libraries first... 顺便说一下,@#$%!@#$ *,否则损失了2天,因此将其作为学习/记住的困难方法,当遇到此类问题时,请务必先升级您的库...

Addendum : Don't blindly update your libraries. 附录 :不要盲目更新您的库。

As Jon Bates pinpointed, every change carries with it the potential of introduce new bugs into the system, and while the old vs new theme is by itself controversial, there is a general consensus that the good practice, when dealing with a already proved stable system, is to keep changes to the minimum, up to archiving the new desired goals. 正如乔恩·贝茨(Jon Bates)所指出的那样,每次更改都带有将新错误引入系统的潜力,尽管旧主题还是新主题本身是有争议的,但人们普遍认为,良好做法在处理已经证明稳定的系统时,是将更改保持在最低水平,直至归档新的期望目标。 That's one of the reasons why good libraries usually have major, minor, and revision numbers, look at them. 这就是为什么好的库通常具有主,次和修订号的原因之一。

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

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