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?
You need
listenerattribute instead ofexecuteattribute. Theexecuteattribute should point to a collection of client IDs which are to be submitted (which defaults to@thisin<f:ajax>and@formin<a4j:ajax>). However in your particular case it returnsvoidand keeps theexecuteempty. Thelistenerattribute is supposed to point to a bean action listener method. Fix it accordingly:Note that the
colorClassargument seems superfluous here, or at least thecolorClass.coloras you could also just docolorClass.getColor()inside thegetColorCode()method. Just passing one of them ought to be sufficient. PassingcolorClass.colorwould be preferable so that yourmyChoicesbean is not tight coupled with thecolorCodebean.