I wanted to achieve following UI in JSF.
[RadioButton] [Image] [Label]
[RadioButton] [Image] [Label]
[RadioButton] [Image] [Label] and so on...
After implementing following codes, the UI looks good. But when I click on any radio button, selection does not appear in the UI (radio not checked) although bean class get updated by valueChanged event. So how can I set selectOneRadio checked?
JSF code:
<!-- payment options -->
<ui:repeat value="#{shoppingCartBean.paymentMethods}" var="m">
<!-- radio button -->
<div style="float:left;">
<ice:selectOneRadio
value="#{shoppingCartBean.selectedPaymentMethod}"
layout="pageDirection"
partialSubmit="true"
valueChangeListener="#{shoppingCartHandler.valueChanged}">
<f:selectItem itemLabel="" itemValue="#{m}"/>
</ice:selectOneRadio>
</div>
<!-- card image -->
<div style="float:left;">
<ice:graphicImage value="#{layoutBean.currentImagesPath}/#{m}.png"/>
</div>
<!-- payment method description or label -->
<div style="padding: 10px">
<ice:outputText value="#{bundleMessages.messages[m]}"/>
</div>
<div style="clear:both;"></div>
</ui:repeat>
<!-- payment options end-->
and method in the bean class:
public List<String> getPaymentMethods() {
List<String> paymentMethods = new ArrayList<String>();
paymentMethods.add("crditcard");
paymentMethods.add("directbanking");
paymentMethods.add("paypal");
return paymentMethods;
}
public String getSelectedPaymentMethod() {
return this.selectedPaymentMethod;
}
public void setSelectedPaymentMethod(String selectedPaymentMethod) {
this.selectedPaymentMethod = selectedPaymentMethod;
}
and valueChanged event in the handler class:
public void valueChanged(ValueChangeEvent event) {
String value = null;
if (event.getSource() instanceof HtmlSelectOneRadio) {
value = ((String) event.getNewValue());
}
if (value != null) {
this.shoppingCartBean.setSelectedPaymentMethod(value);
}
}