0

我有 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”为空)。我不明白的是我的应用程序中没有参数文本以及什么参数?方法的参数?从一个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

更新:这是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;

    }
4

1 回答 1

0

您的具体问题是您正在生成SelectItem错误的 getter 方法中的对象列表。迁移用于在方法中生成列表的代码@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 生命周期中被多次调用,所以这首先是因为性能问题。此外,您应该在初始请求和回发期间拥有相同的列表以正确设置值。

于 2013-03-27T14:45:12.690 回答