In JSF,how to get parameter values form my sql to jsf the page? -
i first made sql, zdsql, project:
create table zdsql( id integer primary key, filter varchar(12), value varchar(12), descri varchar(12), standard_number integer, language varchar(12) ); insert zdsql values(1,'zdlj','1','1.rid',1,'en'); insert zdsql values(2,'zdlj','2','2.ria',1,'en');
next, made jsf, following codes maining of 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>
the follwing codes maining of 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 zdsql m m.filter = :filter order 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); } }
however, still don't right values. when run project, selectonemenu has nothing, should have 2 selectitems, values should same sql.
from comments, problem haven't configured zdsqlbean
managed bean. there 2 ways this:
add configuration in faces-config.xml file:
<managed-bean> <managed-bean-name>zdsqlbean</managed-bean-name> <managed-bean-class>bean.zdsqlbean</managed-bean-class> <managed-bean-scope>none</managed-bean-scope> </managed-bean>
since jsf 2, use
@managedbean
annotation decorate class.@managedbean(name="zdsqlbean") //name optional public class zdsqlbean { //class definition }
this covered in decent jsf tutorial, can find in stackoverflow jsf wiki. if you're learning/reading jsf 1.x resources, drop them , go jsf 2. note it's in version 2.2.
Comments
Post a Comment