问题
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));
}
}
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
- 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.
回答1:
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>
来源:https://stackoverflow.com/questions/59526324/jboss-error-picklist-render-using-showcase