Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying values in the datatable!

Kirtipur Itagol
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a drop down list which has a list of items from the database. And I have a add button. I want my jsp page to display the item selected as soon as user hits the add button. The display will be in the datatable created under the same page. What are the basic concepts for this process if I'm using hibernate, db2 and jsf?
Any advice will be greatly appreciated!
darko kalevski
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you go like this:

in your jsp page:

<h anelGrid columns="1">
<h:commandButton value="#{poraki.pregled_kopce}" actionListener="#{bean_file.clickButton}"/>
</h anelGrid>

this is the button. bean_file.clickButton is:
bean_file is the managed bean defined within your app, clickButton is a method that is called once user clicks the button. that method should do the query and return the data to the dataTable listed below.

<h anelGrid columns="1" styleClass="proba" rendered="#{prijaviIspit.prikaziTabela}">
<h ataTable value="#{prijaviIspit.dataModel}" var="e" first="#{prijaviIspit.redenBroj}" rows="15" styleClass="TabelaDiplomirani" headerClass="heder" rowClasses="nepar, par">
<f:facet name="header">
<h:commandLink actionListener="#{prijaviIspit.sortZbor}" >
<h:graphicImage value="/media/indeks.jpg" styleClass="slikiLinkovi" />
</h:commandLink >
<h utputText value="#{e.MK}"/>
</h ataTable>
</h anelGrid>

where prijaviIspit.prikaziTabela should return true or false, which tells whether to render (display) the dataTable or not. initially is false, cause you want it to be displayed once user click add button.

in the backing bean (.java file), some stuff you need:

private DataModel data;
private ResultSet rs;

create methods like:

public DataModel getDataModel(){
return data;
//prikaziTabela is boolean variable telling whether to display the dataTable or not. you should define it in the bean file.
public boolean isPrikaziTabela(){
return prikaziTabela;
public ResultSet getRs(){
return rs;
public void setRs(ResultSet a){;

//kategorija is a variable that is used for getting the selected
//item from the drop down list
//I have implemented mine drop down list and filled with data using
//map and hashtable
//you need import java.util.Map;import java.util.Hashtable;
//you can read Core Javaserver faces, there is nice text about querying data from databases...

public void clickButton(ActionEvent e){
if(kategorija.equals("0")) {
if (!kategorija.equals("0") && podkategorija.equals("0")){

//vadenje na zborovite za default jazikot i izbranata kategorija
//rs=y.vratiRezultat("select "+jazik+" from tglossary where CategoryID="+profesor);
data= new ResultSetDataModel();

rs=y.vratiRezultat("select count(*) from tglossary where CategoryID=10");
} catch (Exception q) {
//its true when the query is ok and pressed add buton

it might be complex but you have to dive into it so you can understand what i'm talking about. i dont know how you populate your dropdown list but this is my way...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic