PROBLEM: The following primefaces selectonemenu is populating correctly from a list of Objects fetched from a database. However when I select an item from the populated selectonemenu, the selected item is not set on the backing bean (inputFileAdminBean.selectedFilePath). I have looked at huge number of forums but have not found what the problem could be.
Any help would be appreciated!
XHTML:
<h:form>
<p:selectOneMenu id="filePath" value="#{inputFileAdminBean.selectedFilePath}"
label="File Path" effect="fade" var="fp" converter="filePathConverter">
<f:selectItems value="#{inputFileAdminBean.allFilePaths}" var="filePaths"
itemLabel="#{filePaths.filePath}" itemValue="#{filePaths}" />
<p:column>
<h:outputText value="#{fp.filePathId}" />
</p:column>
<p:column>
<h:outputText value="#{fp.filePath}" />
</p:column>
</h:form>
--
<p:commandButton value="Save Entry" class="button tableHeaderFacet" actionListener="#{inputFileAdminBean.saveEntryAction(actionEvent)}" process="@form">
</p:commandButton>
CONVERTER:
@FacesConverter("filePathConverter")
public class FilePathConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if(value != null && value.trim().length() > 0) {
try {
FilePathServiceImplementation service = (FilePathServiceImplementation) context.getExternalContext().getApplicationMap().get("FilePathServiceImplementation");
return service.getAllFilePath().get(Integer.parseInt(value));
} catch(NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid file path."));
}
}
else {
return null;
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if(value != null) {
return String.valueOf(((FilePath) value).getFilePathId());
}
else {
return null;
}
}
}
BACKING BEAN:
...
List<FilePath> allFilePaths;
FilePath selectedFilePath;
... Getters & Setters ...
@PostConstruct
public void init() {
allFilePaths = fetchAllFilePaths();
}