开发者

Passing parameters to a4j:ajax method

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.colorOpti开发者_运维百科ons}"/>
    <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?


You need listener attribute instead of execute attribute. The execute 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 returns void and keeps the execute empty. The listener attribute is supposed to point to a bean action listener method. Fix it accordingly:

<a4j:ajax event="change" render="colorCode" 
    listener="#{myChoices.getColorCode(colorClass,colorClass.color)}"/>

Note that the colorClass argument seems superfluous here, or at least the colorClass.color as you could also just do colorClass.getColor() inside the getColorCode() method. Just passing one of them ought to be sufficient. Passing colorClass.color would be preferable so that your myChoices bean is not tight coupled with the colorCode bean.

<a4j:ajax event="change" render="colorCode" 
    listener="#{myChoices.getColorCode(colorClass.color)}"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜