ActionListener for datatable....

G

gbattine

Hi guys,
i'm crazying with these datatables and with my problems with them...
i've read BalusC article and all the posts about datatables...but i
haven't found a clear response to my problem.
I've a datatable

<h:dataTable
value="#{biosamplesTable.biosamples}"
var="biosampleItem"
binding="#{biosamplesTable.biosampleDataTable}" border="3"
bgcolor="pink" >
<h:column >
<f:facet name="header">
<h:eek:utputText value="Organism" />
</f:facet>
<h:selectOneMenu value="#{biosampleItem.organism}">
<f:selectItems value="#{biosample.selectOrganism}"/>

</h:selectOneMenu>
</h:column>

<h:column>
<f:facet name="header">
<h:eek:utputText value="Treatment Protocol" />
</f:facet>
<h:inputText value="#{biosampleItem.treatmentProtocol}" />
</h:column>

<h:column >
<f:facet name="header">
<h:eek:utputText value="Extraction Method" />
</f:facet>
<h:inputText value="#{biosampleItem.extractionMethod}" />
</h:column>

<h:column>
<f:facet name="header">
<h:eek:utputText value="Actions" />
</f:facet>

<h:commandLink
value="Invia dati biosample"
actionListener="#{biosamplesTable.editBiosample}" id="editBiosample">

</h:commandLink>

</h:column>
<h:column>
<h:messages globalOnly="true"/>
</h:column>
</h:dataTable>



and it works fine,allowing user to send each row of data with
actionlistener.

Now i want to add an actionlistener to datatable that when it's clicked
it add a new column to mydatatable of empty values(i'm using this
datatable for input operations).
I thinks it's an easy question,i ask you to help me with some code..
this is my code...

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIColumn;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionEvent;
import javax.sql.DataSource;

public class BiosamplesTable {
private List biosamples= new ArrayList();

private HtmlDataTable biosampleDataTable;

private Biosample biosampleItem;

private int nrows;

private int load=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 < nrows; 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;
}




please help me and excuse me for my many posts about this problem,i've
learned much,but i'm not able to solve my problem.......
please help me..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top