I have next form:
<h:form>
<h:selectManyListbox value="#{reports.selectedCategories}"
converter="#{categoryConverter}">
<f:selectItems value="#{reports.categories}"/>
</h:selectManyListbox>
<h:commandButton value="Submit" action="#{reports.action}" />
</h:form>
I use custom converter to transform Category to string and vice versa:
public class CategoryConverter implements Converter {
@Autowired
private CategoryService categoryService;
public Object getAsObject(FacesContext context, UIComponent component, String value) {
System.out.println ("CONVERTER: GET AS OBJECT");
return categoryService.findByName (value);
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
System.out.println ("CONVERTER: GET AS STRING");
return ((Category) value).getName ();
}
}
And finally my backing bean code:
public class ReportsController {
private Category[] selectedCategories;
public void setSelectedCategories (Category[] categories) {
System.out.println ("SET CATEGORIES");
this.selectedCategories = categories;
}
public Category[] getSelectedCategories () {
System.out.println ("GET CATEGORIES");
return selectedCategories;
}
public void action () {
System.err.println ("ACTION");
}
....
//methods for accessing data
}
When I start my app, I see correct listbox with 2 items and a button "Submit". But when I press submit nothing happens. The only output I see is:
GET CATEGORIES
CONVERTER: GET AS STRING
CONVERTER: GET AS STRING
Neither setSelectedCategories () nor action () methods are ever called. And I don't understand why. Any suggestions?
UPD: the problem is even more stupid: when I commented all stuff related to Category class (i.e. my selectManyListbox, my converter, all related setters and getters) and left only method action, it still isn't being called.
<h:form>
<h:commandButton value="Submit" action="#{reports.action}" />
</h:form>
UPD2: here is the output from phase listener
START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE APPLY_REQUEST_VALUES 2
END PHASE APPLY_REQUEST_VALUES 2
START PHASE PROCESS_VALIDATIONS 3
END PHASE PROCESS_VALIDATIONS 3
START PHASE UPDATE_MODEL_VALUES 4
END PHASE UPDATE_MODEL_VALUES 4
START PHASE INVOKE_APPLICATION 5
END PHASE INVOKE_APPLICATION 5
START PHASE RENDER_RESPONSE 6
GET STR
END PHASE RENDER_RESPONSE 6
It seems that all phases worked fine but actually it's not true. I'm a bit confused.