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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Displaying values in the datatable!

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
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!
Kirtipur
 
Greenhorn
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">
<h:column>
<f:facet name="header">
<h:commandLink actionListener="#{prijaviIspit.sortZbor}" >
<h:graphicImage value="/media/indeks.jpg" styleClass="slikiLinkovi" />
</h:commandLink >
</f:facet>
<h utputText value="#{e.MK}"/>
</h:column>
</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(){
data.setWrappedData(getRs());
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){
this.rs=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")) {
errIndex=true;
prikaziTabela=false;
}
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);
rs=null;
prv=0;
data= new ResultSetDataModel();

strani=0;
strana=1;
rs=y.vratiRezultat("select count(*) from tglossary where CategoryID=10");
try{
rs.next();
strani=rs.getInt(1);
} catch (Exception q) {
q.printStackTrace();
}
//its true when the query is ok and pressed add buton
prikaziTabela=true;
}
}

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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic