Retrieving values of datatable..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gbattine
    New Member
    • Oct 2006
    • 3

    Retrieving values of datatable..

    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

    Code:
    public void SendData(ActionEvent e){
    		System.out.println("inizio vedi riga");
    		List values=(List) (getBiosampleDataTable()).getValue();
    		System.out.println("La dimensione è "+values.size());
    		for (int j=0;j<values.size();j++){
    			
    			Object obj=values.get(j);
    			System.out.println(((Biosample) obj).getOrganism());
    			
    			
    			//System.out.println((String) biosampleItem.getLabel());
    			
    		}
    		
    	}

    that is,
    with
    Code:
    List values=(List) (getBiosampleDataTable()).getValue();
    i retrieve values of datatable into a list called values.
    With
    Code:
    Object obj=values.get(j);
    i try to read a single row into an object

    and with

    Code:
    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....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by gbattine
    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

    Code:
    public void SendData(ActionEvent e){
    		System.out.println("inizio vedi riga");
    		List values=(List) (getBiosampleDataTable()).getValue();
    		System.out.println("La dimensione è "+values.size());
    		for (int j=0;j<values.size();j++){
    			
    			Object obj=values.get(j);
    			System.out.println(((Biosample) obj).getOrganism());
    			
    			
    			//System.out.println((String) biosampleItem.getLabel());
    			
    		}
    		
    	}

    that is,
    with
    Code:
    List values=(List) (getBiosampleDataTable()).getValue();
    i retrieve values of datatable into a list called values.
    With
    Code:
    Object obj=values.get(j);
    i try to read a single row into an object

    and with

    Code:
    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?

    Comment

    • gbattine
      New Member
      • Oct 2006
      • 3

      #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
      Code:
      public void editBiosample(ActionEvent event) throws SQLException {
      		
      		
      				setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());
      				int index=getBiosampleDataTable().getRowIndex();
      				
      		if (conn != null) {
      			Experiment exp = (Experiment) ViewUtils
      			.eval("#{experiment}");
      			PreparedStatement pst3 = null;
      			
      			chiave=exp.getAutoKey();
      			pst3 = conn
      					.prepareStatement("INSERT INTO  campione(id_campione,id_,organismo,protocollotrattamento,metodoestrazione,tipoamplificazione,protocolloibridazione,protocollomarcatura)	 VALUES(null,?,?,?,?,?,?,?)");
      
      			pst3.setInt(1, getChiave()+1);//per mantenere la coerenza con la transazione,l'id massimo della tabella precedente non è stato ancora incrementato!!
      			pst3.setString(2, getBiosampleItem().getOrganism());
      			pst3.setString(3, getBiosampleItem().getTreatmentProtocol());
      			pst3.setString(4, getBiosampleItem().getExtractionMethod());
      			pst3.setString(5, getBiosampleItem().getAmplification());
      			pst3.setString(6, getBiosampleItem().getHybridation());
      			pst3.setString(7, getBiosampleItem().getLabel());

      Excuse my poor english and jsf experience...

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by gbattine
        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
        Code:
        public void editBiosample(ActionEvent event) throws SQLException {
        		
        		
        				setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());
        				int index=getBiosampleDataTable().getRowIndex();
        				
        		if (conn != null) {
        			Experiment exp = (Experiment) ViewUtils
        			.eval("#{experiment}");
        			PreparedStatement pst3 = null;
        			
        			chiave=exp.getAutoKey();
        			pst3 = conn
        					.prepareStatement("INSERT INTO  campione(id_campione,id_,organismo,protocollotrattamento,metodoestrazione,tipoamplificazione,protocolloibridazione,protocollomarcatura)	 VALUES(null,?,?,?,?,?,?,?)");
        
        			pst3.setInt(1, getChiave()+1);//per mantenere la coerenza con la transazione,l'id massimo della tabella precedente non è stato ancora incrementato!!
        			pst3.setString(2, getBiosampleItem().getOrganism());
        			pst3.setString(3, getBiosampleItem().getTreatmentProtocol());
        			pst3.setString(4, getBiosampleItem().getExtractionMethod());
        			pst3.setString(5, getBiosampleItem().getAmplification());
        			pst3.setString(6, getBiosampleItem().getHybridation());
        			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

        Comment

        • gbattine
          New Member
          • Oct 2006
          • 3

          #5
          Thanks for you reply but i've not understood very well....
          i use this to insert data
          Code:
          <h:column>
                  <f:facet name="header">
                      <h:outputText value="#{msg.IdBiosample}" styleClass="outputText"/>
                  </f:facet>
                  <h:outputText value="Campione#{biosampleItem.id}" />
              </h:column>
              
              
              <h:column >
                  <f:facet name="header">
                      <h:outputText value="#{msg.Organism}" styleClass="outputText"/>
                  </f:facet>
                 <h:selectOneMenu value="#{biosampleItem.organism}">
                 	<f:selectItems value="#{getDropList.selectOrganism}"/>
                 	   
                 </h:selectOneMenu>
              </h:column>
              
              <h:column>
                  <f:facet name="header">
                      <h:outputText value="#{msg.Treatment}" styleClass="outputText"/>
                  </f:facet>
                  <h:inputText value="#{biosampleItem.treatmentProtocol}" styleClass="inputText"/>
              </h:column>
          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

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by gbattine
            Thanks for you reply but i've not understood very well....
            i use this to insert data
            Code:
            <h:column>
                    <f:facet name="header">
                        <h:outputText value="#{msg.IdBiosample}" styleClass="outputText"/>
                    </f:facet>
                    <h:outputText value="Campione#{biosampleItem.id}" />
                </h:column>
                
                
                <h:column >
                    <f:facet name="header">
                        <h:outputText value="#{msg.Organism}" styleClass="outputText"/>
                    </f:facet>
                   <h:selectOneMenu value="#{biosampleItem.organism}">
                   	<f:selectItems value="#{getDropList.selectOrganism}"/>
                   	   
                   </h:selectOneMenu>
                </h:column>
                
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="#{msg.Treatment}" styleClass="outputText"/>
                    </f:facet>
                    <h:inputText value="#{biosampleItem.treatmentProtocol}" styleClass="inputText"/>
                </h:column>
            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

            Comment

            Working...