G
gbattine
Hi guys,
i've one important question for you....
I've developed a jsf datatable with 5 fixed columns and a button that
allows to user to add a dynamic column. I've a submit button for each
row of datatable that when it's clicked send the first 5 column values
into a table and the dynamic columns values added from user into
another table,as different rows.
For example
usa french england italy germany rome naples
i want that usa french england italy germany go as a row into a table
while rome and naples as different rows into another table.
My problem is with rome and naples that i'm not able to send into table
because i'vent understood how binding column value to bean
property...can you help me?
This is my jsp page(important code)
<t:columns value="#{biosamplesTable.columnDataModel}" var="column" >
<f:facet name="header">
<hanelGroup>
<hutputText value="#{column}" />
<h:commandLink actionListener="#{biosamplesTable.removeColumn}">
<hutputText value="Elimina"/>
</h:commandLink>
</hanelGroup>
</f:facet>
<h:inputText value="#{biosampleProperties.value}" />
</t:columns>
and this is my class
public class BiosamplesTable {
private List biosamples= new ArrayList();
private List columns;
private HtmlDataTable biosampleDataTable;
private int autokey2;
private Biosample biosampleItem;
private int nrows;
private DataModel mColumns;
private int load=0;
private String columnLabel;
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 void editBiosample(ActionEvent event) throws SQLException {
setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());
//biosamples.add(getBiosampleItem());
DataSource dataSource = Singleton.getInstance().getDataSource();
Connection conn = dataSource.getConnection();
for (int i=0;i<columns.size();i++){
PreparedStatement pst4 = null;
pst4 = conn.prepareStatement("INSERT INTO
proprietacampione(IdCampione,Valore) VALUES(?,?)");
pst4.setInt(1, autokey2);
pst4.setString(2,bio.getValue());
pst4.executeUpdate();
pst4.close();
}
conn.close();
FacesContext facesContext = FacesContext
.getCurrentInstance();
facesContext.addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_ERROR,"",
"Biosample aggiunto"));
}
}
public DataModel getColumnDataModel()
{
if (mColumns == null)
{
String[] result = new String[]{};
mColumns = new ListDataModel(new
ArrayList(Arrays.asList(result)));
}
return mColumns;
}
public void addColumn(ActionEvent e)
{
if(columnLabel!=null);//metter l'if
{
columns = (List) getColumnDataModel().getWrappedData();
columns.add(columnLabel);
}
}
public void removeColumn(ActionEvent e)
{
if (mColumns != null && mColumns.isRowAvailable())
{
Object column = mColumns.getRowData();
List columns = (List) getColumnDataModel().getWrappedData();
columns.remove(column);
}
}
public int getAutokey2(){
return autokey2;
}
public void setAutokey2(int autokey2){
this.autokey2=autokey2;
}
public String getColumnLabel(){
return columnLabel;
}
public void setColumnLabel(String columnLabel){
this.columnLabel=columnLabel;
}
public List getColumns(){
return columns;
}
public void setColumns(List columns){
this.columns=columns;
}
}
please help me
i've one important question for you....
I've developed a jsf datatable with 5 fixed columns and a button that
allows to user to add a dynamic column. I've a submit button for each
row of datatable that when it's clicked send the first 5 column values
into a table and the dynamic columns values added from user into
another table,as different rows.
For example
usa french england italy germany rome naples
i want that usa french england italy germany go as a row into a table
while rome and naples as different rows into another table.
My problem is with rome and naples that i'm not able to send into table
because i'vent understood how binding column value to bean
property...can you help me?
This is my jsp page(important code)
<t:columns value="#{biosamplesTable.columnDataModel}" var="column" >
<f:facet name="header">
<hanelGroup>
<hutputText value="#{column}" />
<h:commandLink actionListener="#{biosamplesTable.removeColumn}">
<hutputText value="Elimina"/>
</h:commandLink>
</hanelGroup>
</f:facet>
<h:inputText value="#{biosampleProperties.value}" />
</t:columns>
and this is my class
public class BiosamplesTable {
private List biosamples= new ArrayList();
private List columns;
private HtmlDataTable biosampleDataTable;
private int autokey2;
private Biosample biosampleItem;
private int nrows;
private DataModel mColumns;
private int load=0;
private String columnLabel;
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 void editBiosample(ActionEvent event) throws SQLException {
setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());
//biosamples.add(getBiosampleItem());
DataSource dataSource = Singleton.getInstance().getDataSource();
Connection conn = dataSource.getConnection();
for (int i=0;i<columns.size();i++){
PreparedStatement pst4 = null;
pst4 = conn.prepareStatement("INSERT INTO
proprietacampione(IdCampione,Valore) VALUES(?,?)");
pst4.setInt(1, autokey2);
pst4.setString(2,bio.getValue());
pst4.executeUpdate();
pst4.close();
}
conn.close();
FacesContext facesContext = FacesContext
.getCurrentInstance();
facesContext.addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_ERROR,"",
"Biosample aggiunto"));
}
}
public DataModel getColumnDataModel()
{
if (mColumns == null)
{
String[] result = new String[]{};
mColumns = new ListDataModel(new
ArrayList(Arrays.asList(result)));
}
return mColumns;
}
public void addColumn(ActionEvent e)
{
if(columnLabel!=null);//metter l'if
{
columns = (List) getColumnDataModel().getWrappedData();
columns.add(columnLabel);
}
}
public void removeColumn(ActionEvent e)
{
if (mColumns != null && mColumns.isRowAvailable())
{
Object column = mColumns.getRowData();
List columns = (List) getColumnDataModel().getWrappedData();
columns.remove(column);
}
}
public int getAutokey2(){
return autokey2;
}
public void setAutokey2(int autokey2){
this.autokey2=autokey2;
}
public String getColumnLabel(){
return columnLabel;
}
public void setColumnLabel(String columnLabel){
this.columnLabel=columnLabel;
}
public List getColumns(){
return columns;
}
public void setColumns(List columns){
this.columns=columns;
}
}
please help me