0

I have a JSF page with the following radio button definition:

<h:selectOneRadio id="durationList" value="#{rentalEquipmentCheckoutController.selectedDuration}" styleClass="durationList">
<f:selectItems var="d" value="#{rentalEquipmentCheckoutController.durationList}" itemValue="#{d}" itemLabel="#{d.label}">
 </f:selectItems>
<f:converter converterId="durationConverter" />
<f:ajax />
</h:selectOneRadio>

I have a convertor that seems to be working fine. I have stepped through it and it is doing what it is supposed to be doing on get and set.

    @Override
public Object getAsObject(FacesContext context, UIComponent component, String durationHours) {
    RentalDuration rentalDuration = DurationFactory.getDuration(Integer.parseInt(durationHours));
    return rentalDuration;
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {

    if (object != null) {
        RentalDuration duration = (RentalDuration) object;
        return Integer.toString(duration.getHours());
    }

    return "Error";
}

The controller is a ManagedBean and it is view scoped. The list appears fine on the UI and all of the values appear to be working in google web dev tools. When I click on one of the radio buttons, the convertor's getAsObject fires and returns the correct instance of RentalDuration. The setSelectedDuration method in the bean is never called though. I tried just setting up a simple implementation with a list of Strings, and that seems to work just fine (same page, bean etc). The setTestString method is called. I have read so many of @BalusC's posts that my eyes are bleeding, but I cannot seem to figure out what I am doing wrong.

Hodglem
  • 554
  • 8
  • 17

1 Answers1

0

Ugh. It seems like it never fails; I can work on something for 16 hours and after I post on SO I find the answer not too long after posting. The problem was that the objects I filled up the backing list with to populate the radio buttons weren't the same objects that I was trying to use in the converter. I was trying to create new Duration objects in the converter and I was hoping that some JSF magic was going to figure out that they were the same as in the list. Once I set the factory to return the same objects, the backing method setSelectedDuration method started firing. If anyone can explain how this works in the guts of JSF I'd love to hear it. The comparison of the objects and then the setting of the selected object etc.

Hodglem
  • 554
  • 8
  • 17
  • Next time when setter or action is not invoked, go through http://stackoverflow.com/q/2118656 first. – BalusC Feb 11 '17 at 10:46