0

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();
}
StuStlr
  • 1
  • 2
  • Your question is ambiguous. First of all, do you see any conversion/validation error when you add `` as stated in [this troubleshooter](http://stackoverflow.com/q/2118656)? Let me guess, it's a "Validation Error: Value is not valid"? Did you already copypaste this error message into a search engine for clues? – BalusC May 11 '16 at 13:38
  • Hi, that troubleshooter is very useful. I found the problem to be with the command button, added ajax="false" and took away the process tag. It is now working as expected. Thanks. – StuStlr May 12 '16 at 13:33

0 Answers0