This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSF and the fly likes Displaying values in the datatable! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Displaying values in the datatable!" Watch "Displaying values in the datatable!" New topic
Author

Displaying values in the datatable!

Kirtipur Itagol
Greenhorn

Joined: Oct 11, 2005
Posts: 23
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
darko kalevski
Greenhorn

Joined: Oct 31, 2005
Posts: 4
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying values in the datatable!
 
Similar Threads
Dynamic Component in JSF
selectOneMenu and dataTable
Opening a new window with a commandbutton
h:selectBooleanCheckbox
Problem with h:datatable