Question

in my usecase I have a (Primefaces) selectOneRadio. This is within an ui:repeat. Values of selectOneRadio are displayed fine. I want each selectOneRadio to have a useful default-value, depending on the iterated entity. This works fine, too, default is selected. But with my approach, I am not able to set the value of the selectOneRadio, as an exception rises:

javax.el.PropertyNotWritableException: [...] value="#{orderBean.getProductPriceId(product)}": Illegal Syntax for Set Operation

How do I set a selectiOneRadioButton-value inside an ui:repeat depending on the iterated entity?

OrderBean:

public class OrderBean {
    private String productPriceId; // + getter and setter
    public String getProductPriceId(final Product product) {
        return product == null ? "" : product.getPricesAsList().get(0).getId().toString();
    }
}

xhtml:

<ui:repeat var="product" value="...">
        <p:selectOneRadio value="#{orderBean.getProductPriceId(product)}">
            ...
        </p:selectOneRadio>
</ui:repeat>
Was it helpful?

Solution

This makes indeed no sense. You need to make sure that the model matches the view without any need for additional business logic.

Just use

<p:selectOneRadio value="#{product.priceId}">

and give the default item a value of null instead of "" so that it matches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top