Hi

to add columns, add a UIColumn component in childs of the datatable. As
far as i know, datatable aren't really made to be quite dyna,ic in
structure, i learned it at my expense. You probably will want to create
your own component. Another solution might be for you to remove the
datatable (nullify) in your binding. It already difficult to handle
change in datatable rows between request, changes in column might take a
lot of burden that can be avoided by using other components...

danielitob a écrit :
> Hi guys,
> i need your help for a question that i'm trying to solve from 10 days..
> Excuse me if i've posted some similar question recently but now the
> situation is clear..
> i've created a datatable with t:datatable for input scope.
> Each row is a form and a submit button at the end of row allows to user to
> send row data to db.
> This is my datatable
> <t:dataTable
>     value="#{biosamplesTable.biosamples}" 
>     var="biosampleItem"
>       binding="#{biosamplesTable.biosampleDataTable}" border="3" 
> bgcolor="pink" >
>     <h:column >
>         <f:facet name="header">
>             <h:outputText value="Organism" />
>         </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="Treatment Protocol" />
>         </f:facet>
>         <h:inputText value="#{biosampleItem.treatmentProtocol}" />
>     </h:column>
>
>     <h:column >
>         <f:facet name="header">
>             <h:outputText value="Extraction Method" />
>         </f:facet>
>         <h:inputText value="#{biosampleItem.extractionMethod}" />
>     </h:column>
>     
>             
>      <h:column>
>         <f:facet name="header">
>             <h:outputText value="Actions" />
>         </f:facet>
>         
>               
>         
>         <h:commandButton
>         value="Invia dati biosample"
> actionListener="#{biosamplesTable.editBiosample}" id="editBiosample">
>     
>         </h:commandButton>
>     
>
>     </h:column>
>        
> </t:dataTable>        
>
> this is my bean
> public class BiosamplesTable extends Visit {
>       private List biosamples = new ArrayList();
>
>               
>       private HtmlDataTable biosampleDataTable;
>
>       private Biosample biosampleItem;
>
>       
>       private int nrows;
>
>       private int load = 0;
>       private int load2 = 0;
>       public HtmlDataTable getBiosampleDataTable() {
>               return biosampleDataTable;
>       }
>
>       public void setBiosampleDataTable(HtmlDataTable biosampleDataTable) {
>               
>               this.biosampleDataTable = biosampleDataTable;
>       }
>
>       public Biosample getBiosampleItem() {
>               return biosampleItem;
>       }
>
>       public void setBiosampleItem(Biosample biosampleItem) {
>               this.biosampleItem = biosampleItem;
>       }
>
>       public List getBiosamples() throws Exception {
>               loadBiosamples();
>               // Reload after every request.
>
>               return biosamples;
>       }
>
>       public void setBiosamples(List biosamples) {
>               this.biosamples = biosamples;
>       }
>
>       public void loadBiosamples() throws Exception {
>
>               if (load == 0) {
>
>                       for (int i = 0; i < 3; i++) {
>                               Biosample biosample = new Biosample();
>                               biosamples.add(biosample);
>                               setBiosamples(biosamples);
>                               load = 1;
>                       }
>               } else {
>                       setBiosamples(biosamples);
>               }
>       }
>
>       public int getNrows() {
>               return nrows;
>       }
>
>       public void setNrows(int nrows) {
>               this.nrows = nrows;
>       }
>
>       public void editBiosample(ActionEvent event) throws SQLException {
>               System.out.println("entrato");
>               setBiosampleItem((Biosample) 
> getBiosampleDataTable().getRowData());
>               int id=getBiosampleDataTable().getRowIndex();
>               System.out.println("L'indice della riga
> è="+getBiosampleDataTable().getRowIndex());
>               System.out.println("Il valore è
> ="+getBiosampleItem().getTreatmentProtocol());
>               
>               try {
>               if (conn != null) {
>                               Experiment exp = (Experiment) 
> ViewUtils.eval("#{experiment}");
>                               PreparedStatement pst3 = null;
>                               pst3 = conn
>                                               .prepareStatement("INSERT INTO 
> campione(id_,organismo,protocollotrattamento,metodoestrazione)        
> VALUES(?,?,?,?)");
>
>                               pst3.setInt(1, exp.getAutoKey());
>                               pst3.setString(2, 
> getBiosampleItem().getOrganism());
>                               pst3.setString(3, 
> getBiosampleItem().getTreatmentProtocol());
>                               pst3.setString(4, 
> getBiosampleItem().getExtractionMethod());
>                               
>                               pst3.executeUpdate();
>                       
>                               pst3.close();
>                       } 
>
>               } 
>               catch (Exception p) {
>                       p.printStackTrace();
>               }
>
>       }
>
>       
> }
>
> It works fine and i can insert a row of data correctly.
> My question is:
> I want solving this situation.One user enters a value in a precedent page(2
> for example) and my application adds 2 columns to my existing datatable,for
> allowing to user to insert others 2 values for row....
> I've read all posts,all article and comments,but excuse me,i HAVEN'T
> UNDERSTOOD!!!!!
> Can someone help me,please?
> I'm crazying and without you i've to renounce...
> i want to know how add 2 columns and how retrieve their values for each
> row....please help me with code,i'm new of jsf and myfaces...
> i hope you help me..
>
>   

Reply via email to