Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 在我的jsf页面中找不到任何记录_Jsf 2_Primefaces - Fatal编程技术网

Jsf 2 在我的jsf页面中找不到任何记录

Jsf 2 在我的jsf页面中找不到任何记录,jsf-2,primefaces,Jsf 2,Primefaces,我正在尝试从我的数据库中检索数据,它实际上适用于另一个表,但使用此表,在日志文件中只找到没有任何错误消息的记录这是我的代码: @ManagedBean @SessionScoped public class AnnonceBean implements java.io.Serializable { private static final long serialVersionUID = 1L; priv

我正在尝试从我的数据库中检索数据,它实际上适用于另一个表,但使用此表,在日志文件中只找到没有任何错误消息的记录这是我的代码:

                        @ManagedBean
                  @SessionScoped
     public class AnnonceBean implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private List<SelectItem> anonItems;
private DataModel annonces;
private Annonce newAnnonce = new Annonce();
private Annonce editAnnonce;
private DaoAnnonce aDao = new DaoAnnonce();

public List<SelectItem> getAnonItems() {
    if (anonItems == null) {
        anonItems = new ArrayList<SelectItem>();
        List<Annonce> annList = aDao.selectAll();
        for (Annonce an : annList) {
            anonItems.add(new SelectItem((Annonce) an, ((Annonce) an)
                    .getTitre()));
            anonItems.add(new SelectItem((Annonce) an, ((Annonce) an)
                    .getContenu()));
            anonItems.add(new SelectItem((Annonce) an, ((Annonce) an)
                    .getProfesseur().getPrenom()));

        }
    }
    return anonItems;
}

public AnnonceBean() {
    if (annonces == null) {
        annonces = new ListDataModel();
        annonces.setWrappedData(aDao.selectAll());
    }
}

public String creer() {
    return "add";
}

public String create() {
    aDao.ajouter(newAnnonce);
    newAnnonce = new Annonce();
    annonces.setWrappedData(aDao.selectAll());
    FacesMessage msg = new FacesMessage("Ajout effectué avec succés");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    return "list";

}

public String deleteGroupe() {
    Annonce a = (Annonce) annonces.getRowData();
    aDao.supprimer(a);
    FacesMessage msg = new FacesMessage("Suppression effectué avec succés");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    return null;
}

public String editAnnonce() {
    editAnnonce=(Annonce)annonces.getRowData();
    return "edit";
}
public String updateAnnonce(){
    aDao.modifier(editAnnonce);
    annonces.setWrappedData(aDao.selectAll());
    FacesMessage msg = new FacesMessage("Modification effectué avec succés");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    return "list";
}
这是我的Dao类代码

              public class DaoAnnonce {
private static final String JPA_UNIT_NAME="Portail";
private EntityManager entityManager;
protected EntityManager getEntityManager() {
    if (entityManager == null) {
        entityManager = Persistence.createEntityManagerFactory(
                JPA_UNIT_NAME).createEntityManager();
    }
    return entityManager;
}

 public   void ajouter(Annonce a)
    {
        EntityTransaction tx = getEntityManager().getTransaction();
        tx.begin();
        entityManager.persist(a);
        tx.commit();

    }
 public void modifier(Annonce a)
    {
        EntityTransaction tx = getEntityManager().getTransaction();
        tx.begin();
        entityManager.merge(a);
        tx.commit();

    }
 public  void supprimer(Annonce a)
    {


        EntityTransaction tx = getEntityManager().getTransaction();
        tx.begin();
        a=entityManager.merge(a); // important
        entityManager.remove(a);
        tx.commit();

    }
 public List<Annonce > selectAll() {
        List<Annonce > annonces =getEntityManager().createQuery("select a from Annonce  a").getResultList();
        return annonces;
    }
这就是jsf代码

                    <p:tab title="Annonces">
            <p:dataTable var="annonce" value="#{annonceBean.annonces}"
                editable="true">

                <p:ajax event="rowEdit" listener="#{tableBean.onEdit}" />
                <p:ajax event="rowEditCancel" listener="#{tableBean.onCancel}" />

                <p:column headerText="Titre" style="width:30%">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{annonce.titre}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{annonce.titre}" style="width:100%" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column headerText="Contenu" style="width:20%">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{annonce.contenu}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{annonce.contenu}" style="width:100%"
                                label="contenu" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column headerText="Professeur" style="width:24%">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{annonce.prenom}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{annonce.prenom}" style="width:100%"
                                label="prenom" />

                        </f:facet>
                    </p:cellEditor>
                </p:column>
            </p:dataTable>
        </p:tab>

我正在开发eclipse,我正在为bean AnnonceBean中的组件使用primefaces。没有称为getAnnonces的方法,但是有一个方法getAnonItems返回一个列表,这可能是您想要的。如果是这种情况,{annonceBean.annonces}应替换为{annonceBean.anonItems}。

仍然不起作用,并且annonces确实存在。我在托管数据库中声明了它Bean@MeknessiHamida我不明白你为什么要使用列表,你可能只需要列表。。。不,您的问题中没有getAnnones,请再次验证。我没有提到getter和setter,但它确实存在于我的代码中。如果是这样,您应该在行列表annonces=getEntityManager.createQuerySelecta from annonOnce a.getResultList之后立即中断;查看annonces中是否有内容。如果没有,请直接使用数据库客户端尝试查询。如果是,请验证ManagedBean的包导入。是否已验证您的查询实际返回结果?