使用展示柜呈现Jboss错误选择列表 [英] Jboss Error picklist render using showcase
问题描述
相关链接: PrimeFaces PickList使用OmniFaces validateAll会导致NullPointerException
此问题与该链接相似,因为当我调试picklistRender时,我得到了以前在链接中显示的相同错误,具有相同的症状,但是我正在阅读所有问题
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
我试图找出解决我的示例工作的方法,例如展示橱窗p:picklist,但文档说的却不尽如人意,我尝试了
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.
环境
-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;
}
}
转换器
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));
}
}
-
问题 对于PickListRenderer,NPE在第78行,然后在PickListRenderer内部为128:
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);
与模型相关的NPE变量在encodeMarkup中始终为null,之后使用该模型为null调用encodeList.
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
stackTrace https://pastebin.com/wLKZWReg
- 这两个问题是相关的,因为在另一个问题上,他们可以解决该问题,但是我跟踪他们提出的所有内容,但是我无法弄清楚,是的,两个问题都是相似的,它们之间的差异很小,但对于我是同一个场景
7:如果与mojarra不相关,请删除mojarra标签. 8:在JSF开发模式下运行jsf应用程序.
7: If it is not mojarra related, please remove the mojarra tag. 8: Run you jsf application in JSF development mode.
是的,我尝试通过mojarra解决此错误测试或测试myfaces,因为我没有删除mojarra的标签.
yes I trying to resolve this error testing with mojarra or testing myfaces for that I dont remove the tag of mojarra.
推荐答案
问题
-在xhtml上固定Bean的名称Bean的名称通常以小写字母开头(对于我来说,是
-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}"
对此
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.
我测试了两种处理JSF置换的方法,而另一种则填充了项目 您必须选择一个,不要同时使用两者,否则在部署阶段会出现一些错误.
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>
这篇关于使用展示柜呈现Jboss错误选择列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!