将参数传递给 a4j:ajax 方法
我正在尝试使用
为方法提供刚刚在表单上输入的值;
<h:selectOneMenu id="aa" value="#{colorClass.color}">
<f:selectItems value="#{myChoices.colorOptions}"/>
<a4j:ajax event="change" render="colorCode"
execute="#{myChoices.getColorCode(colorClass,colorClass.color)}"/>
</selectOneMenu>
表格上的颜色选择正确;
我的问题是,当我将 colorClass.color
作为执行的一部分传递时,它是空白的; 如果我将 colorClass.color
替换为文字
<a4j:ajax event="change" render="colorCode"
execute="#{myChoices.getColorCode(colorClass,'green')}"/>
,则调用该方法,查找 colorCode 并重新绘制表单
如何“获取”刚刚输入的值,以便可以将其作为参数传递给该方法?
I am trying to use <a4j:ajax>
to feed a method with a value just entered on the form;
<h:selectOneMenu id="aa" value="#{colorClass.color}">
<f:selectItems value="#{myChoices.colorOptions}"/>
<a4j:ajax event="change" render="colorCode"
execute="#{myChoices.getColorCode(colorClass,colorClass.color)}"/>
</selectOneMenu>
Color on the form is selected correctly;
my problem is that when I pass colorClass.color
as part of the execute, it is blank;
if I replace colorClass.color
with a literal
<a4j:ajax event="change" render="colorCode"
execute="#{myChoices.getColorCode(colorClass,'green')}"/>
the method is called, finds the colorCode and repaints the form
How can I "grab" the value just entered so that I can pass it as a parameter to the method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要
listener
属性而不是execute
属性。execute
属性应指向要提交的客户端 ID 的集合(默认为
中的@this
和
中的@form
)。但是,在您的特定情况下,它返回void
并保持execute
为空。listener
属性应该指向 bean 操作侦听器方法。相应地修复它:请注意,
colorClass
参数在这里似乎是多余的,或者至少是colorClass.color
,因为您也可以只执行colorClass.getColor()
code> 在getColorCode()
方法中。只要通过其中一项就足够了。最好传递colorClass.color
,这样您的myChoices
bean 就不会与colorCode
bean 紧密耦合。You need
listener
attribute instead ofexecute
attribute. Theexecute
attribute should point to a collection of client IDs which are to be submitted (which defaults to@this
in<f:ajax>
and@form
in<a4j:ajax>
). However in your particular case it returnsvoid
and keeps theexecute
empty. Thelistener
attribute is supposed to point to a bean action listener method. Fix it accordingly:Note that the
colorClass
argument seems superfluous here, or at least thecolorClass.color
as you could also just docolorClass.getColor()
inside thegetColorCode()
method. Just passing one of them ought to be sufficient. PassingcolorClass.color
would be preferable so that yourmyChoices
bean is not tight coupled with thecolorCode
bean.