0

related links: PrimeFaces PickList with OmniFaces validateAll leads to NullPointerException

this problem is similar with this link becuase when I do the debug of the picklistRender I got the same error showed in the link before,the same syntoms, but I am reading all issue history related, Thomas Andraschko sugguest is a problem of mojarra but I tried to test with myfaces-version-22 and myfaces-version-23 and I face the same problem


Im trying to figure out to resolve my example works like showcase p:picklist but not worls as well said the docs, I tried several options like

 - don't use mojarra,use myfaces
 - change primefaces version 7.0 to 8.0.RC1
 - put a custom converter
 -jboss-deployment-structure.xml (disables packages from jboss)

When does the error occur? - loading page why am I using a converter? - is an option I tried to fix the problem, but, the ussue raises before, I test with or withoutconverter and happens the same error.

enviroment

-Jboos EAP 7.2 
- repo https://github.com/Qleoz12/Primefaces-Mydemo

but always I have this error

java.lang.NullPointerException

viewId=/components/usingCompositeComponent.xhtml
location=I:\developer\Fado\Servidores\jboss-eap-7.2\standalone\deployments\Primefaces-        
Mydemo.war\components\usingCompositeComponent.xhtml
phaseId=RENDER_RESPONSE(6)

Caused by:
java.lang.NullPointerException
at org.primefaces.component.picklist.PickListRenderer.encodeMarkup(PickListRenderer.java:103)

xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ccp="http://java.sun.com/jsf/composite/cc"
    template="../template/ui.xhtml">
    <ui:define name="body">
        <p:pickList 
            id="FF"
            value="#{CompositeComponent.cities}" 
            var="cities"
            itemLabel="#{cities}"
            itemValue="#{cities}"
            converter="PickListConverter"
        >
        </p:pickList>
    </ui:define>
</ui:composition>

bean

package Beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Named;

import org.primefaces.model.DualListModel;

@Named
@javax.faces.view.ViewScoped
public class CompositeComponent implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CompositeComponent.class);
    private DualListModel<String> cities;
    List<String> citiesSource = new ArrayList<String>();
    List<String> citiesTarget = new ArrayList<String>();

    public CompositeComponent() {
        super();
    }

    @PostConstruct
    public void init() {
        // Cities
        citiesSource.add("San Francisco");
        citiesSource.add("London");
        citiesSource.add("Paris");
        citiesSource.add("Istanbul");
        citiesSource.add("Berlin");
        citiesSource.add("Barcelona");
        citiesSource.add("Rome");

        cities = new DualListModel<String>(citiesSource, citiesTarget);
    }

    public DualListModel<String> getCities() {
        return cities;
    }

    public void setCities(DualListModel<String> cities) {
        this.cities = cities;
    }

}

converter

package converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import org.primefaces.component.picklist.PickList;
import org.primefaces.model.DualListModel;


@SuppressWarnings({"unused", "rawtypes"})
@FacesConverter("PickListConverter")
public class PickListConverter implements Converter{

    public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
        PickList  p = (PickList) component;
        DualListModel dl = (DualListModel) p.getValue();
        return dl.getSource().get(Integer.valueOf(submittedValue));
    }

    public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
        PickList  p = (PickList) component;
        DualListModel dl = (DualListModel) p.getValue();
        return  String.valueOf(dl.getSource().indexOf(value));
    }
}

  1. question And for the PickListRenderer the NPE is in line 78 then 128 inside PickListRenderer:

    encodeList(context, pickList, clientId + "_target", PickList.TARGET_CLASS, model.getTarget(),
            pickList.getFacet("targetCaption"), pickList.isShowTargetFilter(), false); 
    

    issue of primefaces

the NPE var is related with model always is null inside encodeMarkup that afterward call encodeList with this model null.

DualListModel model = getModelValueToRender(context, pickList);

stackTrace https://pastebin.com/wLKZWReg


  1. the both question is related because in sme point in the other question they can achieve to resolve the problem but Im following all stuffs they made, but I cant figure out, yeah both questions are similar , them have somo little differets but for me is the same scenary

7: If it is not mojarra related, please remove the mojarra tag. 8: Run you jsf application in JSF development mode.

yes I trying to resolve this error testing with mojarra or testing myfaces for that I dont remove the tag of mojarra.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
qleoz12
  • 513
  • 5
  • 15
  • @Kukeltje yes, I do, I Crete a simple project of primefaces only for test picklist and not work for all problems that you can find in the related link.... – qleoz12 Dec 30 '19 at 11:37
  • I'm enviorement is the link of the repo I create, I made this ask because the other users suggest to create a new ask, yes is very similar to the related link but I tried to comment in the link post but my reputation is less that 50 points for that I can't, and I dont use omnifaces – qleoz12 Dec 30 '19 at 12:02
  • I didnt understand this is my minimal example for test the situaction https://github.com/Qleoz12/Primefaces-Mydemo, – qleoz12 Dec 30 '19 at 15:29
  • A [mcve] should be in the question, not in github or other external system (it might disappear there). Also read https://stackoverflow.com/tags/jsf/info. There is waaaaay to much code in your github example – Kukeltje Dec 30 '19 at 15:35
  • now I update the question – qleoz12 Dec 30 '19 at 15:39
  • 1
    1: the xhtml code is not complete (no close tag) 2: Why are you using a converter, you have plain strings 3: If relevant, where is the code of the converter – Kukeltje Dec 30 '19 at 15:52
  • give me a while for update – qleoz12 Dec 30 '19 at 16:47
  • No problem.. great you respond. Even this little feedback is appreciated, compliments. Many stay silent which greatly reduces tge incentice to help in the future – Kukeltje Dec 30 '19 at 17:16
  • hi, Kukeltje Im not undertand very well about validation, but I update whith all question you coment me before. – qleoz12 Dec 30 '19 at 22:05
  • If it fails for both mojarra an myfaces, the mojarra tag is wrong and a generic jsf tag is better (I changed it) If the converter makes no difference, **remove** it from the question. And there is still a composition. Does it start to work if you remove it, then its content is relevant. If not, also remove it from the code and make a real [mcve] PLEASE 8: does it make a difference? Errors? Warnings? And if you now know the model is empty, I assume you tried removing the picklist component and just put a `#{CompositeComponent.cities}` instead? And you tried to see if the getter is called? – Kukeltje Dec 31 '19 at 09:07
  • That is what developers would do. Please **investigate** – Kukeltje Dec 31 '19 at 09:07
  • I have finished im goint to update the ask. thnsk for the advices – qleoz12 Jan 03 '20 at 05:09

1 Answers1

0

problems

-Fix on the xhtml the name of the bean the name of the bean usually starts with lowercase for that I chabge

value="#{CompositeComponent.cities}"

to this

value="#{compositeComponent.cities}"

-for Strings remove the converter , but for custom objects you must to write a own implemantation of the converter, I put an example into my repo in github.

I test two ways to handle JSF anottation and anothers stuff the project you must choose one, dont use both or you have some error on deploying stage.

        <!-- javax.* APIs -->
    <!-- old way -->
    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>8.0</version>
    <scope>provided</scope>
    </dependency>
    <!-- end old way -->
    <!-- new way -->
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-atinject_1.0_spec</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jcdi_2.0_spec</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-interceptor_1.2_spec</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-annotation_1.3_spec</artifactId>
        <version>1.0</version>
    </dependency>
qleoz12
  • 513
  • 5
  • 15
  • Thanks for answering and great you solved it. Did you in the end try running in de development mode? Since that would have given you direct indications of this root cause. And your 'new way' is wrong. If you are running a java ee server, there is no need at all to add the spec (api) jars to your project in a non-provided way. The 'old way' is the good way. And these jars are not about JSF Annotations, they are about injection (CDI annotations). And are you using jBoss 7.x (which is not a java-ee spec compliant server) or jBoss 7.x EAP? – Kukeltje Jan 03 '20 at 07:39
  • 1
    Oh and see your question was in **no way** related to the 'other one' like we already mentioned. – Kukeltje Jan 03 '20 at 11:11
  • I am using Jboss EAP 7.2 – qleoz12 Jan 03 '20 at 15:06