我先为这个项目做了一个sql,zdsql:</p>
create table zdsql(
id integer primary key,
filter varchar(12),
value varchar(12),
descri varchar(12),
standard_number integer,
language varchar(12)
);
insert into zdsql values(1,'zdlj','1','1.rid',1,'en');
insert into zdsql values(2,'zdlj','2','2.ria',1,'en');
接下来,我制作了JSF,以下代码是我的xhtml的主要部分:
<h:outputLabel value="#{msgs.zdlj}" style="font-weight:bold" />
<p:selectOneMenu id="zdlj1" value="#{zsjBean.zdlj}">
<f:selectItems value="#{zdsqlBean.zdsqls}" var="bll1"
itemLabel="#{bll1.descri}" itemValue="#{bll1.value}" />
</p:selectOneMenu>
以下代码是 zdsqlBean 的主要部分:
package bean;
import java.util.List;
import java.util.logging.Level;
import javax.persistence.TypedQuery;
import model.Zdsql;
import util.DBDAO;
public class ZdsqlBean {
private List<Zdsql> zdsqls;
public ZdsqlBean() {
this.genzdljs();
}
public List<Zdsql> getZdsqls() {
System.out.println("zdsqls==");
return zdsqls;
}
public void setZdsqls(List<Zdsql> zdsqls) {
this.zdsqls = zdsqls;
}
public void genzdljs() {
try {
String queryString = "select m from Zdsql m where m.filter = :filter Order by m.id";
TypedQuery<Zdsql> query = DBDAO.getEntityManager().createQuery(
queryString, Zdsql.class);
query.setParameter("filter", "zdlj");
zdsqls = query.getResultList();
} catch (Exception re) {
DBDAO.log("genzdljs() failed", Level.SEVERE, re);
}
}
但是,我仍然没有得到正确的值。当我运行这个项目时,selectonemenu什么都没有,应该有两个selectitem,值应该和sql一样。