jsf - displaying values from database on the basis of dropdown menu selction -
hi creating jsf application . in fact made dropdown list , want display results according value selected dropdown. if can help.... thanks
here drop down
<h:form> <h:commandbutton action="sample?faces-redirect=true" value="submit"> <h:selectonemenu id="samplesearch" value="#{cbean.id}"> <f:selectitem id="id" itemlable="idtext" itemvalue="by text" /> <f:selectitem id="idnumeric" itemlable="idnumeric" itemvalue="number" /> <f:selectitem id="product" itemlable="product" itemvalue="main product" /> <f:selectitem id="lonumber" itemlable="lonumber" itemvalue="lonumber" /> <f:selectitem id="formula" itemlable="formula" itemvalue="by formula" /> </h:selectonemenu> </h:commandbutton> </h:form>
first, you're not allowed nest <h:selectonemenu>
component(s) within <h:commandbutton>
! here's proper structure of <h:form>
<h:form> <h:commandbutton action="sample?faces-redirect=true" value="submit" /> <h:selectonemenu id="samplesearch" value="#{cbean.id}"> <f:selectitem id="id" itemlable="idtext" itemvalue="by text" /> <f:selectitem id="idnumeric" itemlable="idnumeric" itemvalue="number" /> <f:selectitem id="product" itemlable="product" itemvalue="main product" /> <f:selectitem id="lonumber" itemlable="lonumber" itemvalue="lonumber" /> <f:selectitem id="formula" itemlable="formula" itemvalue="by formula" /> </h:selectonemenu> </h:form>
then, in order dropdown list options database, can consider using <f:selectitems>
component (and rid of <f:selectitem>
s) , pass list<t>
managed bean components value
property.
the selectonemenu
this:
<h:selectonemenu value="#{cbean.id}"> <f:selectitems value="#{cbean.values}" var="item" itemlabel="#{item.label}" itemvalue="#{item.value}"/> </h:selectonemenu>
as managed-bean, it's supposed provide public list<t> getvalues()
method, return list objects populate dropdown.
when t
complex java object, such item
has string property of label
, value
, use var
attribute hold of iteration variable in turn can use in itemvalue
and/or itemlabel
attribtues (if omit itemlabel
, label becomes same value).
let's say:
@managedbean @requestscoped public class cbean { public list<item> getvalues() { list<item> result = new arraylist<item>(); //..call-back web-service, db, etc. , populate result variable. return result; } }
the item
class this:
public class item { private string label; private string value; //getters, setters. }
you can read more here:
Comments
Post a Comment