Skip to Content
avatar image
Former Member

Data Binding between UI Element Table and Record Set

Hi All,

I have a record set returned with values but I am not sure how I am supposed to bind this to the UI element of type table in webdynpro. Can someone please help?

The code is as enclosed below:

ResultSet rs;

try {

InitialContext ctx = new InitialContext();

javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/MSDE");

java.sql.Connection con = ds.getConnection();

java.sql.Statement stmt = con.createStatement();

rs = stmt.executeQuery("SELECT * from tblCRD");

while (rs.next()){

wdContext.nodeData().currentDataElement().setField1(rs.getString("Test1"));

wdContext.nodeData().currentDataElement().setField2(rs.getString("Test2"));

}

con.close();

}

catch(Exception e)

{

wdContext.currentContextElement().setTxtErrormessage("Folgender Fehler hat sich ergeben:"+e.getMessage());

}

Thanks in advance.

Best regards,

Divya

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Dec 14, 2005 at 10:17 PM

    I suppose "Data" is a node with cardinality 0:N.

    Bind the "dataSource" property of the table to node "Data".

    Create 2 table columns with TextView cell editors, bind the "text" property of the TextView editors to the attributes "Field1" and "Field2".

    In the loop over the result set, create and add new "Data" node elements:

    while (rs.next())
    {
      IDataElement data = wdContext.nodeData().createDataElement();
      wdContext.nodeData().addElement(data);
      data.setField1(rs.getString("Test1"));
      data.setField2(rs.getString("Test2"));
    }
    

    Armin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 15, 2005 at 03:50 AM

    Hi Divya,

    In while loop you are not creating new record but just overridding values in one record.

    Instead of that,

    you can write following code there.

    while (rs.next())

    {

    Iprivate<viewame>.IDataElement ele = wdContext.nodeData().createDataElement();

    wdContext.nodeData().addElement(ele);

    data.set<attribute name>(rs.getString(<Field name>));

    }

    It will add new record for each record in recordset.

    Now, bind this node with Table element.

    You will get data in table UI element.

    Regards,

    Bhavik

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 15, 2005 at 04:26 AM

    Hi Divya,

    Check with this code,I have set the table having a two coloum.

    try{

    InitialContext ctx=new InitialContext();

    DataSource ds=(DataSource)ctx.lookup("jdbc/SAPJ2EDB");

    Connection con=ds.getConnection();

    Statement stmt=con.createStatement();

    ResultSet rs1=stmt.executeQuery("select * from TMP_TECHNOLOGY");

    while(rs1.next()){

    String id1=rs1.getString("SUBJECTID");

    String name=rs1.getString("name");

    IPrivatePermission_Adminview.INode_subElement x=wdContext.nodeNode_sub().createNode_subElement();

    wdContext.nodeNode_sub().addElement(x);

    wdContext.currentNode_subElement().

    setPermission_subjectid(id1);

    wdContext.currentNode_subElement().

    setPermission_name(name);

    wdContext.nodeNode_sub().moveNext();

    }

    Regards,

    Vijayakhanna Raman

    Add comment
    10|10000 characters needed characters exceeded