JSF - Different between f:converter and converter tag inside selectOneMenu

61 Views Asked by At

I am using ICEFaces 3.3 framework and I had a weird problem with converter.

Below code segment will cause the value passed to setter becomes null

<ice:setEventPhase events="ValueChangeEvent" phase="INVOKE_APPLICATION">
    <ice:selectOneMenu id="obj" style="width: 120px;" value="#{MyClass.obj}" rendered="#{not objectBean.disabled}" partialSubmit="true" converter="#{MyControlClass.myCustomConverter}">
       <f:selectItem itemValue="" />
       <f:selectItems id="items" value="#{MyControlClass.itemList}"/>
    </ice:selectOneMenu>
</ice:setEventPhase>

Note that the above converter is defined as variable (which type is MyCustomConverter) in MyControlClass.

The converter before modification

public class MyCustomConverter implements Converter {
    private List<MyObject> objs;

    public MyCustomConverter(List<MyObject> objs) {
       this.objs = objs;
   }

However, when changed to below , the bug does not exist anymore

<ice:setEventPhase events="ValueChangeEvent" phase="INVOKE_APPLICATION">
    <ice:selectOneMenu id="obj" style="width: 120px;" value="#{MyClass.obj}" rendered="#{not objectBean.disabled}" partialSubmit="true">
       <f:selectItem itemValue="" />
       <f:selectItems id="items" value="#{MyControlClass.itemList}"/>
       <f:converter converterId = "MyCustomConverter" />
    </ice:selectOneMenu>
</ice:setEventPhase>

The converter after modification

@FacesConverter("MyCustomConverter")
public class MyCustomConverter implements Converter {

private List<MyObject> objs;

public MyCustomConverter() {
    super();
    ...business logic, get records and store it into objs...
}

My question

Is there a difference between two implementation above? I cannot find an explanation of why the value becomes null when it goes setter after event is fired if I use the first implementation. This situation does not exist anymore if I use the latter implementation.

0

There are 0 best solutions below