Question

For the past 3 days I have been trying to get the following to work. I have a datatable which gets data from a backing bean and shows a column with 3 radio buttons. The page renders as expected and the radio buttons get the correct value. Submitting the form however does not go as intended. Whenever I submit the form the values for the corresponding object are set to the value of the last object in the table. Oddly enough, when I view the form being sent through Fiddler, the correct values are being sent instead of duplicating the value of the object in the last row. I'm guessing the selectOneRadio id has something to do with, but setting a dynamic value for the id results in an error.

Thanks in advance and let me know in case more info is needed.

<rich:dataTable id="facilities_organisation"
                var="orgFacility"
                value="#{organisationFacilitiesHandler.findAllFacilitiesForCurrentOrganisation}">
    <rich:column>
        <f:facet name="header">
            <h:outputText value="Naam" />
        </f:facet>
        <h:outputText value="#{orgFacility.facility.name}" />
    </rich:column>
    <rich:column>
        <f:facet name="header">
            <h:outputText value="Beschikbaar?" />
        </f:facet>
        <h:selectOneRadio id="facility" value="#{orgFacility.availabilityType.id}">
            <f:selectItems value="#{organisationFacilitiesHandler.findAllAvailabilityTypes}" />
        </h:selectOneRadio>
    </rich:column>
</rich:dataTable>

Backbean

private Organisation activeOrganisation = null;
private List<OrganisationFacility> facilities = new ArrayList<OrganisationFacility>();

public Organisation getActiveOrganisation() {
    return this.activeOrganisation;
}
public void setActiveOrganisation(Organisation organisation) {
    activeOrganisation = organisation;
}

public List<OrganisationFacility> getFindAllFacilitiesForCurrentOrganisation() {
    this.facilities = new ArrayList<OrganisationFacility>();
    if (this.activeOrganisation != null) {
        //Error handling omitted
        this.facilities = facilityManager.findAllFacilitiesForOrganisation(this.activeOrganisation);
    }
    return this.facilities;
}
public void setFindAllFacilitiesForCurrentOrganisation(List<OrganisationFacility> facilities) {
    //This function doesn't ever seem to get called...
    LOG.debug("setFindAllFacilitiesForCurrentOrganisation was called");
}

public List<SelectItem> getFindAllAvailabilityTypes() {
    List<SelectItem> selectItems = new ArrayList<SelectItem>();

    //Error handling omitted
    List<AvailabilityType> types = this.facilityManager.findAllAvailabilityTypes();
    for (AvailabilityType t : types)
        selectItems.add(new SelectItem(t.getId(), t.getLabel() + (t.getName().equals("specific") ? " opleiding" : "")));

    return selectItems;
}

public String save() {
    AvailabilityType defaultType = facilityManager.defaultAvailabilityType();
    if (defaultType == null)
        return "showOrganisation";

    for (Iterator<OrganisationFacility> it = this.facilities.iterator(); it.hasNext(); ) {
        OrganisationFacility f = it.next();

        //Business code omitted for readability
        //At this point every f.AvailabilityType has already been duplicated from the last object in the datatable
    }

    return "showOrganisation";
}
Was it helpful?

Solution

I just found my own answer to this problem. It might not be optimal or completely in line with the usual way of handling this, so feel free to still come up with solutions to my question.

This line seemed to be the culprit:

<h:selectOneRadio id="facility" value="#{orgFacility.availabilityType.id}">

It seems that nested properties aren't handled as I expected. I solved the problem by changing my 'getFindAllFacilitiesForCurrentOrganisation' method to return a list of simplified objects without any nested properties. Instead they just contain the necessary id's which I later use in the 'save' method to perform the actual update. So now it looks like this:

<h:selectOneRadio id="facility" value="#{orgFacility.typeId}">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top