问题: 以下primefaces selectonemenu从数据库中提取的对象列表中正确填充。但是,当我从填充的selectonemenu中选择一个项目时,未在辅助bean上设置所选项目(inputFileAdminBean.selectedFilePath)。我查看了大量的论坛,但没有找到问题所在。
任何帮助将不胜感激!
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>
转换器:
@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();
}