sending a value from a datatable column..

Discussion in 'Java' started by gbattine, Sep 6, 2006.

  1. gbattine

    gbattine Guest

    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">
    <h:panelGroup>
    <h:eek:utputText value="#{column}" />
    <h:commandLink actionListener="#{biosamplesTable.removeColumn}">
    <h:eek:utputText value="Elimina"/>
    </h:commandLink>
    </h:panelGroup>
    </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
    gbattine, Sep 6, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,339
    Kevin Spencer
    Aug 15, 2003
  2. jg
    Replies:
    1
    Views:
    722
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  3. MattB
    Replies:
    2
    Views:
    16,350
    MattB
    Nov 11, 2005
  4. keithb
    Replies:
    1
    Views:
    4,717
  5. Microsoft News Group

    Get a column value from a datatable

    Microsoft News Group, Sep 22, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    25,443
    Microsoft News Group
    Sep 24, 2006
Loading...

Share This Page