Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Displaying values in the datatable!

Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic