关于JSF和Primesfaces,我遇到了一个问题。我有一个带有列表的表单,如:
<h:form>
<h:outputText value="Filtrer par client" for="filtreClient" />
<p:selectOneMenu id="filtreClient" value="#{actionBean.action.codeClient}" effect="fade">
<f:selectItem itemLabel="Sélectionnez" itemValue="" />
<f:selectItems value="#{clientDao.listeClient}" />
</p:selectOneMenu>
</h:form>
它返回给我这个error ==>SEVERE: javax.faces.FacesException: Erreur d’argument : le paramètre «text» est null.
(这意味着参数"text"为空)。我不明白的是,我没有一个参数文本在我的应用程序和什么参数?参数从一个方法?from a httpRequest
?
你见过那种错误吗?
这是我的堆栈跟踪:
SEVERE: javax.faces.FacesException: Erreur d’argument : le paramètre «text» est null.
javax.faces.FacesException: Erreur d’argument : le paramètre «text» est null.
at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:142)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:809)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
at servlet.Login.doPost(Login.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException: Erreur d’argument : le paramètre «text» est null.
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.writeText(HtmlResponseWriter.java:877)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeOption(SelectOneMenuRenderer.java:368)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeSelectItems(SelectOneMenuRenderer.java:333)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeInput(SelectOneMenuRenderer.java:114)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:91)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:65)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
... 36 more
Update:这是创建列表的ClientDao
:
public class ClientDao implements IClient, Serializable {
/**
*
*/
private static final long serialVersionUID = 1951697664353493098L;
public static String GET_ALL_CLIENT = "SELECT c.codeClient, c.nom , c.prenom FROM Client c ORDER BY c.name ASC ";
@PersistenceContext(unitName = "dev")
EntityManager em;
private List<SelectItem> listeClient;
private List<Client> resListeClient;
private SelectItem selectItem;
public List<SelectItem> getListeClient() {
try {
EntityManagerFactory emf = null;
emf = Persistence.createEntityManagerFactory("dev");
em = emf.createEntityManager();
Query requete = em.createQuery("SELECT c FROM Client c ORDER BY c.nom ASC");
resListeClient = requete.getResultList();
listeClient = new ArrayList<SelectItem>();
for (Client c : resListeClient) {
if (c.getNom() != null) {
selectItem = new SelectItem();
selectItem.setValue(c.getCodeClient());
selectItem.setLabel(c.getNom() + " " + c.getPrenom());
listeClient.add(selectItem);
}
}
} catch (NoResultException e) {
System.out.println("Aucun client trouvé" + e.getMessage()
+ e.getCause());
} finally {
if (em != null) {
em.close();
}
}
return listeClient;
// return null;
}
您的具体问题是您正在生成getter方法中错误的SelectItem
对象列表。迁移@PostConstruct
方法中生成列表的代码,并且在getter中只返回该列表:
@PostConstruct
public void init() {
try {
EntityManagerFactory emf = null;
emf = Persistence.createEntityManagerFactory("dev");
em = emf.createEntityManager();
Query requete = em.createQuery("SELECT c FROM Client c ORDER BY c.nom ASC");
resListeClient = requete.getResultList();
listeClient = new ArrayList<SelectItem>();
for (Client c : resListeClient) {
if (c.getNom() != null) {
selectItem = new SelectItem();
selectItem.setValue(c.getCodeClient());
selectItem.setLabel(c.getNom() + " " + c.getPrenom());
listeClient.add(selectItem);
}
}
} catch (NoResultException e) {
System.out.println("Aucun client trouvé" + e.getMessage()
+ e.getCause());
} finally {
if (em != null) {
em.close();
}
}
}
public List<SelectItem> getListeClient() {
return listeClient;
}
Getter在JSF生命周期中被调用多次,所以这首先是因为性能问题。此外,您应该在初始请求和回发期间拥有相同的列表,以正确设置值。