selectCheckboxMenu - converter fails when multiple=true

UI Components for JSF
Post Reply
kimg
Posts: 39
Joined: 22 Aug 2013, 17:13

23 May 2020, 01:01

I'm running PF 8.0, Payara 5.194, JDK 11, Serenity layout.

I don't know if this is a PF problem but it's my best guess.

I have this simple view:

Code: Select all

<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/templateWide.xhtml">


    <ui:define name="title">Setup Review process</ui:define>


    <ui:define name="breadcrumb">
        <li><p:link outcome="/SetupCallAndInvitation">Setup Review process</p:link></li>

    </ui:define>

    <ui:define name="content">
        <div class="ui-g">
            <div class="ui-g-12">
                <h:form id="mainForm" style="width: 95%;" >
                    <div class="ui-g-12 ui-fluid">
                        <h:outputLabel for="menu" value="Basic:" />
                        <p:selectCheckboxMenu id="conference" value="#{converterTestController.selectedConferences}"  multiple="true" >
                            <f:selectItem itemLabel="Select Conference" itemValue="" />
                            <f:selectItems value="#{converterTestController.conferences}" var="conf" itemLabel="#{conf.title}" itemValue="#{conf}"/>

                            <f:facet name="footer">
                                <p:separator />
                                <h:outputText value="3 consoles" style="font-weight:bold;"/>
                            </f:facet>
                        </p:selectCheckboxMenu>
                    </div>
                </h:form>  
            </div>
        </div>
    </ui:define>
</ui:composition>

backed up by this simple controller:

Code: Select all

package dk.druidadmin.controller;

import dk.druid.entity.Conference;
import dk.druid.service.ConferenceService;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import lombok.Data;


@Named
@ViewScoped
@Data
public class ConverterTestController implements Serializable {

    @Inject
    private ConferenceService conferenceService;

    List<Conference>conferences;
    List<Conference>selectedConferences;
    Conference selectedConference;

    @PostConstruct
    private void init() {
        conferences = conferenceService.findAll();
        System.out.println("SIZES =" + conferences.size());
    }

}

and the following converter (stolen almost) verbatim) from 'The definitive guide to JSF in Java EE 8')

Code: Select all

package dk.druidadmin.converter;

import dk.druid.entity.Conference;
import dk.druid.service.ConferenceService;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;

@FacesConverter(forClass = Conference.class, managed = true)
public class ConferenceConverter implements Converter<Conference> {

    @Inject
    private ConferenceService conferenceService;

    @Override
    public Conference getAsObject(FacesContext context, UIComponent component, String id) {
        if (id == null || id.isEmpty()) {
            return null;
        }

        try {
            return conferenceService.find(id);
        } catch (NumberFormatException e) {
            throw new ConverterException(
                    new FacesMessage("Invalid conference ID"), e);
        }

    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Conference conference) {
        if (conference == null) {
            return "";
        }

        if (conference.getId() != null) {
            return conference.getId().toString();
        } else {
            throw new ConverterException(
                    new FacesMessage("Invalid conference ID"));
        }

    }
}

In the view, if I call my controller with this logic:

Code: Select all

 <p:selectCheckboxMenu id="conference" value="#{converterTestController.selectedConference}"  multiple="true" >
everything works and I can see my converter being called. if I change to:

Code: Select all

 <p:selectCheckboxMenu id="conference" value="#{converterTestController.selectedConferences}"  multiple="true" >
so it adresses the List of conferences (notice the s after Conference) instead my converter / CDI throws an exception:

Code: Select all

 Error Rendering View[/user/converterTest.xhtml]
java.lang.NullPointerException
	at com.sun.faces.cdi.CdiUtils.createConverter(CdiUtils.java:102)
	at com.sun.faces.application.applicationimpl.InstanceFactory.createConverter(InstanceFactory.java:481)
	at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:510)
	at javax.faces.application.ApplicationWrapper.createConverter(ApplicationWrapper.java:431)
	at org.omnifaces.cdi.converter.ConverterManager.createConverter(ConverterManager.java:155)
	at org.omnifaces.cdi.converter.ConverterManager$Proxy$_$$_WeldClientProxy.createConverter(Unknown Source)
	at org.omnifaces.application.OmniApplication.createConverter(OmniApplication.java:100)
	at org.primefaces.renderkit.SelectRenderer.findImplicitConverter(SelectRenderer.java:202)
	at org.primefaces.renderkit.SelectRenderer.getOptionAsString(SelectRenderer.java:181)
	at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.encodeOption(SelectCheckboxMenuRenderer.java:143)
	at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.encodeOption(SelectCheckboxMenuRenderer.java:137)
	at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.encodeInputs(SelectCheckboxMenuRenderer.java:128)
	at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.encodeMarkup(SelectCheckboxMenuRenderer.java:93)
	at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.encodeEnd(SelectCheckboxMenuRenderer.java:63)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:595)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1654)
	at javax.faces.render.Renderer.encodeChildren(Renderer.java:152)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:566)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1647)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:468)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:170)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:132)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:132)
	at org.omnifaces.viewhandler.OmniViewHandler.renderView(OmniViewHandler.java:121)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:102)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:199)
	at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:708)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1628)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:339)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:209)
	at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:282)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:251)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:209)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:755)
	at org.apache.catalina.core.StandardPipeline.doChainInvoke(StandardPipeline.java:579)
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
	at java.base/java.lang.Thread.run(Thread.java:834)
Is there a reason for that? Am I doing something wrong here?

br
Kim
Primefaces 6.2 / Glassfish 5 / Payara 5.182

kukeltje
Expert Member
Posts: 9566
Joined: 17 Jun 2010, 13:34
Location: Netherlands

24 May 2020, 10:02

Hi, Yes the reason is that something is null. But seriously (althoug you could in the source of Mojarra see **what** is null) if you want help, create a MCVE, see https://stackoverflow.com/help/mcve. But also seehttps://stackoverflow.com/tags/jsf/info about templates, includes etc... Remove as much from custom code as possible, no lombok, no database things, just static java arrayLists or the likes... And post that. Then it takes less time for us to try to reproduce (and sometimes you even find the solutiuon when creating a mcve). But also try the latest version of PF and the latest version of OmniFaces and the latest Mojarra version (if possible) but at least post all the version info.

Cheers

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests