Reputation: 1791
Most of my problems in JSF, so far, seem to boil down to this - communication from (static) client-side to (dynamic) server-side, and vice-versa; for instance, for re-rendering components.
An example: enabling/disabling a button (commandButton
) that depends on the selection of a selectoneradio
.
What is the correct way to communicate the selection of the selectoneradio
(client to server) and then ajaxingly updating the commandButton
(server to client)?
Upvotes: 0
Views: 598
Reputation: 1109112
By using <f:ajax>
.
Here's an example which enables the button when the second item is selected.
<h:selectOneRadio value="#{bean.selectedItem}">
<f:selectItem itemValue="1" itemLabel="First item" />
<f:selectItem itemValue="2" itemLabel="Second item" />
<f:ajax render="button" />
</h:selectOneRadio>
<h:commandButton id="button" disabled="#{bean.selectedItem != 2}" />
Make sure that the #{bean}
is a @ViewScoped
one so that the state is remembered across postbacks. Else it'll fall back to default values when you press the submit button.
That said, I strongly recommend to go through a decent JSF book. The above is usually already covered in 1st chapter.
Upvotes: 1