0

I'm using Primefaces 6.1 and have an issue with one of the selectOneMenu. I have reduced the page to the selectOneMenu-Item only, but couldn't figure out, where the issue is located.

xhtml-Page:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui" template="/WEB-INF/template.xhtml">
    <ui:define name="content">
        <h:form id="formCenter">
            <div class="ContainerIndent">
                <div class="EmptyBox20"/>
                <p:selectOneMenu value="#{bankAccountEntryClearing.selectedInterfaceFile}"
                                 var="interfaceFileItem"
                                 converter="#{interfaceFileConverter}">  
                    <f:selectItem itemLabel="Bank-Daten auswählen" itemValue="#{null}" noSelectionOption="true"/>
                    <f:selectItems value="#{bankAccountEntryClearing.items}" 
                                   var="interfaceFileItem" 
                                   itemLabel="#{interfaceFileItem.fileName}" 
                                   itemValue="#{interfaceFileItem}"/>              
                    <p:column style="text-align: left">  
                        #{interfaceFileItem.fileName}
                    </p:column>  
                    <p:ajax event="change" process="@this" update=":formCenter:testSetterId"/>
                </p:selectOneMenu>
            </div>
            <p:inputText id="testSetterId" value="#{bankAccountEntryClearing.fileName}"/>
        </h:form>
    </ui:define>
</ui:composition>

Converter:

@ManagedBean
@SessionScoped
@Named("interfaceFileConverter")
public class InterfaceFileConverter implements Converter {

    private final Logger logger = Logger.getLogger(this.getClass().getName());

    @Inject
    private InterfaceFileFacade ejbFacade;

    private Integer getKey(String value) {
        Integer key = Integer.valueOf(value);
        return key;
    }

    public String getAsString(FacesContext fc, UIComponent uic, Object object) {
        if (object == null) return null;
        if (object instanceof InterfaceFile) 
            return String.valueOf(((InterfaceFile) object).getInterfaceFileId());
        return null;
    } 


    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            logger.info("Interface Converter : null");
            return null;
        }
        InterfaceFile interfaceFile = this.ejbFacade.findInterfaceFile(getKey(value));
        logger.info("Interface Converter : " + interfaceFile.getInterfaceFileId());
        return interfaceFile;
    }
}

Bean:

@SessionScoped
@ManagedBean
@Named(value = "bankAccountEntryClearing")
public class BankAccountEntryClearing extends AbstractHouseController<InterfaceFile> implements Serializable {

    private static final long serialVersionUID = 1L;
    private final Logger logger = Logger.getLogger(this.getClass().getName());

    @Inject
    private InterfaceFileFacade         ejbFacade;

    private InterfaceFile               interfaceFile = null;
    private Integer                     houseId;
    private List<InterfaceFile>         interfaceFiles = null;

    public BankAccountEntryClearing() {
        super(InterfaceFile.class);
    }

    @PostConstruct
    public void init() {
        super.setFacade(ejbFacade);
    }

    public List<InterfaceFile> getItems() {
        if (this.getHouseId() == null)
            return null;

        if (this.getHouseId() != this.houseId) {
            interfaceFiles = ejbFacade.getInterfaceFiles(this.getHouseId(),1);
        }

        return interfaceFiles;
    }

    public InterfaceFile getSelectedInterfaceFile() {
        logger.info("Interface Bean getter");
        return interfaceFile;
    }

    public void setSelectedInterfaceFile(InterfaceFile interfaceFile) {
        logger.info("Interface Bean setter: " + interfaceFile.getFileName());
        this.interfaceFile      = interfaceFile;
    }

    public String getFileName() {
        if (this.interfaceFile != null)
            return this.interfaceFile.getFileName();
        return "";
    }
}

The items are loaded prober and could be selected. After an item is selected, the getAsObject from converter is called, but never the setter-routine.

16:55:23,411 INFO  [com.np.propmgmt.controller.BankAccountEntryClearing] (default task-30) Interface Bean getter
16:55:23,412 INFO  [com.np.propmgmt.controller.BankAccountEntryClearing] (default task-30) Interface Bean getter
16:55:27,772 INFO  [com.np.propmgmt.converter.InterfaceFileConverter] (default task-48) Interface Converter : 69
Nik
  • 9
  • 3

1 Answers1

0

I found an hind and solved the issue. The reason was the entity-class object InterfaceFile itself. This JPA entity-class was the only one, which was generated by Eclipse JPA-Tool. In this case no "equals" and "hashCode" function with the primary-key was generated. At the time the item was selected, the "selectOneMenu" compare of the returned InterfaceFile (from getAsObject) to the list (from getItems) and failes. With adding a "" the validation-error was shown.

After adding this two functions to the InterfaceFile-entity-class, everything worked fine.

It is the same as Validation Error: Value is not valid

Nik
  • 9
  • 3