By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,760 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,760 IT Pros & Developers. It's quick & easy.

Retrieving values of datatable..

P: 3
Hi guys,
i've a very important question for you,i'm stopped my work from 10 days to solve it,but nothing....
i hope your can help me.
I'm developing a jsf application and i've created a datatable with empty fields, so each row of my datatable is an input row...i've associated a button to each row and cliccking them i retrieve values inserted by user(for each row) and i put them into a database.
What i want now is avoiding to use a button for each row,i want one only button at the end of page that send to database the data inserted in each row.
I've started

Expand|Select|Wrap|Line Numbers
  1. public void SendData(ActionEvent e){
  2.         System.out.println("inizio vedi riga");
  3.         List values=(List) (getBiosampleDataTable()).getValue();
  4.         System.out.println("La dimensione  "+values.size());
  5.         for (int j=0;j<values.size();j++){
  6.  
  7.             Object obj=values.get(j);
  8.             System.out.println(((Biosample) obj).getOrganism());
  9.  
  10.  
  11.             //System.out.println((String) biosampleItem.getLabel());
  12.  
  13.         }
  14.  
  15.     }

that is,
with
Expand|Select|Wrap|Line Numbers
  1. List values=(List) (getBiosampleDataTable()).getValue();
i retrieve values of datatable into a list called values.
With
Expand|Select|Wrap|Line Numbers
  1. Object obj=values.get(j);
i try to read a single row into an object

and with

Expand|Select|Wrap|Line Numbers
  1. System.out.println(((Biosample) obj).getOrganism());
i try to print the organism value for row i.
Biosample is type of managed bean used to wrapp the single row.

My question is:
Each value i retrieve is NULL!!!!!
Why?
Please help me,it's my first post....
Oct 4 '06 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
Hi guys,
i've a very important question for you,i'm stopped my work from 10 days to solve it,but nothing....
i hope your can help me.
I'm developing a jsf application and i've created a datatable with empty fields, so each row of my datatable is an input row...i've associated a button to each row and cliccking them i retrieve values inserted by user(for each row) and i put them into a database.
What i want now is avoiding to use a button for each row,i want one only button at the end of page that send to database the data inserted in each row.
I've started

Expand|Select|Wrap|Line Numbers
  1. public void SendData(ActionEvent e){
  2.         System.out.println("inizio vedi riga");
  3.         List values=(List) (getBiosampleDataTable()).getValue();
  4.         System.out.println("La dimensione  "+values.size());
  5.         for (int j=0;j<values.size();j++){
  6.  
  7.             Object obj=values.get(j);
  8.             System.out.println(((Biosample) obj).getOrganism());
  9.  
  10.  
  11.             //System.out.println((String) biosampleItem.getLabel());
  12.  
  13.         }
  14.  
  15.     }

that is,
with
Expand|Select|Wrap|Line Numbers
  1. List values=(List) (getBiosampleDataTable()).getValue();
i retrieve values of datatable into a list called values.
With
Expand|Select|Wrap|Line Numbers
  1. Object obj=values.get(j);
i try to read a single row into an object

and with

Expand|Select|Wrap|Line Numbers
  1. System.out.println(((Biosample) obj).getOrganism());
i try to print the organism value for row i.
Biosample is type of managed bean used to wrapp the single row.

My question is:
Each value i retrieve is NULL!!!!!
Why?
Please help me,it's my first post....
Is there any data in the database?
what is the method SendData supposed to do and why does it take an ActionEvent if does not use it?
Oct 4 '06 #2

P: 3
my datatable is generated by a list with empty values(the user has to fill its fields).
I want the method send data takes data inserted by user in the rows...
that is,the user see a datatable with many input forms(empty).
The user fill each row of the datatable,click sendData button and the values now inserted go into db...
is it possible?
With my method i retrieve only null values(as i don't retrieve inserted values,but the initial values of datatable...).
I've used actionListener to have not navigation to another page,but result don't change with action...

With my old method i've associated a command button to each row,i clicked on it and datatable row inserted go into db.
What i want know is avoiding those command button for each row,and create an only function that does it for each row...is it possible?
This is my working old method
Expand|Select|Wrap|Line Numbers
  1. public void editBiosample(ActionEvent event) throws SQLException {
  2.  
  3.  
  4.                 setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());
  5.                 int index=getBiosampleDataTable().getRowIndex();
  6.  
  7.         if (conn != null) {
  8.             Experiment exp = (Experiment) ViewUtils
  9.             .eval("#{experiment}");
  10.             PreparedStatement pst3 = null;
  11.  
  12.             chiave=exp.getAutoKey();
  13.             pst3 = conn
  14.                     .prepareStatement("INSERT INTO  campione(id_campione,id_,organismo,protocollotrattamento,metodoestrazione,tipoamplificazione,protocolloibridazione,protocollomarcatura)     VALUES(null,?,?,?,?,?,?,?)");
  15.  
  16.             pst3.setInt(1, getChiave()+1);//per mantenere la coerenza con la transazione,l'id massimo della tabella precedente non  stato ancora incrementato!!
  17.             pst3.setString(2, getBiosampleItem().getOrganism());
  18.             pst3.setString(3, getBiosampleItem().getTreatmentProtocol());
  19.             pst3.setString(4, getBiosampleItem().getExtractionMethod());
  20.             pst3.setString(5, getBiosampleItem().getAmplification());
  21.             pst3.setString(6, getBiosampleItem().getHybridation());
  22.             pst3.setString(7, getBiosampleItem().getLabel());

Excuse my poor english and jsf experience...
Oct 4 '06 #3

10K+
P: 13,264
my datatable is generated by a list with empty values(the user has to fill its fields).
I want the method send data takes data inserted by user in the rows...
that is,the user see a datatable with many input forms(empty).
The user fill each row of the datatable,click sendData button and the values now inserted go into db...
is it possible?
With my method i retrieve only null values(as i don't retrieve inserted values,but the initial values of datatable...).
I've used actionListener to have not navigation to another page,but result don't change with action...

With my old method i've associated a command button to each row,i clicked on it and datatable row inserted go into db.
What i want know is avoiding those command button for each row,and create an only function that does it for each row...is it possible?
This is my working old method
Expand|Select|Wrap|Line Numbers
  1. public void editBiosample(ActionEvent event) throws SQLException {
  2.  
  3.  
  4.                 setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());
  5.                 int index=getBiosampleDataTable().getRowIndex();
  6.  
  7.         if (conn != null) {
  8.             Experiment exp = (Experiment) ViewUtils
  9.             .eval("#{experiment}");
  10.             PreparedStatement pst3 = null;
  11.  
  12.             chiave=exp.getAutoKey();
  13.             pst3 = conn
  14.                     .prepareStatement("INSERT INTO  campione(id_campione,id_,organismo,protocollotrattamento,metodoestrazione,tipoamplificazione,protocolloibridazione,protocollomarcatura)     VALUES(null,?,?,?,?,?,?,?)");
  15.  
  16.             pst3.setInt(1, getChiave()+1);//per mantenere la coerenza con la transazione,l'id massimo della tabella precedente non  stato ancora incrementato!!
  17.             pst3.setString(2, getBiosampleItem().getOrganism());
  18.             pst3.setString(3, getBiosampleItem().getTreatmentProtocol());
  19.             pst3.setString(4, getBiosampleItem().getExtractionMethod());
  20.             pst3.setString(5, getBiosampleItem().getAmplification());
  21.             pst3.setString(6, getBiosampleItem().getHybridation());
  22.             pst3.setString(7, getBiosampleItem().getLabel());

Excuse my poor english and jsf experience...
should be possible. you'd need to name the inputs cleverly so that you'd use them in a loop. Are you using JTextFields or HTML form inputs?
You could also use JTable
Oct 4 '06 #4

P: 3
Thanks for you reply but i've not understood very well....
i use this to insert data
Expand|Select|Wrap|Line Numbers
  1. <h:column>
  2.         <f:facet name="header">
  3.             <h:outputText value="#{msg.IdBiosample}" styleClass="outputText"/>
  4.         </f:facet>
  5.         <h:outputText value="Campione#{biosampleItem.id}" />
  6.     </h:column>
  7.  
  8.  
  9.     <h:column >
  10.         <f:facet name="header">
  11.             <h:outputText value="#{msg.Organism}" styleClass="outputText"/>
  12.         </f:facet>
  13.        <h:selectOneMenu value="#{biosampleItem.organism}">
  14.            <f:selectItems value="#{getDropList.selectOrganism}"/>
  15.  
  16.        </h:selectOneMenu>
  17.     </h:column>
  18.  
  19.     <h:column>
  20.         <f:facet name="header">
  21.             <h:outputText value="#{msg.Treatment}" styleClass="outputText"/>
  22.         </f:facet>
  23.         <h:inputText value="#{biosampleItem.treatmentProtocol}" styleClass="inputText"/>
  24.     </h:column>
  25.  
  26.  
what code i need to solve my problem?
Thanks very much,i hope you help me,you are my last hope....
Help me with easy code,please....i'm a newbie
Oct 4 '06 #5

10K+
P: 13,264
Thanks for you reply but i've not understood very well....
i use this to insert data
Expand|Select|Wrap|Line Numbers
  1. <h:column>
  2.         <f:facet name="header">
  3.             <h:outputText value="#{msg.IdBiosample}" styleClass="outputText"/>
  4.         </f:facet>
  5.         <h:outputText value="Campione#{biosampleItem.id}" />
  6.     </h:column>
  7.  
  8.  
  9.     <h:column >
  10.         <f:facet name="header">
  11.             <h:outputText value="#{msg.Organism}" styleClass="outputText"/>
  12.         </f:facet>
  13.        <h:selectOneMenu value="#{biosampleItem.organism}">
  14.            <f:selectItems value="#{getDropList.selectOrganism}"/>
  15.  
  16.        </h:selectOneMenu>
  17.     </h:column>
  18.  
  19.     <h:column>
  20.         <f:facet name="header">
  21.             <h:outputText value="#{msg.Treatment}" styleClass="outputText"/>
  22.         </f:facet>
  23.         <h:inputText value="#{biosampleItem.treatmentProtocol}" styleClass="inputText"/>
  24.     </h:column>
  25.  
  26.  
what code i need to solve my problem?
Thanks very much,i hope you help me,you are my last hope....
Help me with easy code,please....i'm a newbie
Sorry my friend but that's just as much I could contribute. You see I'm also new jsf. I only work with servlets, jsps and ejbs. I hope someone else will be able to help you. This java forum is usually quiet though. If you don't get help soon enough, you might have to try (I don't like doing this but ...) sun
Oct 4 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.