Skip to Content
author's profile photo Former Member
Former Member

How to add multiple records in table thru form via Submit button

Hi all

i have small requirement as follows.

i have a view in which i have 3 UI elements one is webdynpro form,Table UI element and third one is submit button.

now at runtime when i will enter the details in the form and click on the submit button then those record details has been stored in Table. then next time again when i submit the form with details then the table contains all records of current and existing ...so table has to maintain mutile records thru form via submit form..

i need sample code on the same.

points are always rewardable

Thanks

Sunil

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2008 at 05:43 AM

    Assume you have three fields in the form: Name, dob and address

    First define your context:

    at root context: create three attributes

    name of type string

    dob of type date

    address of type string

    now for table you must create a node name tNode and copy the same attributes into tNode.

    your context should look like this:

    context
      + name
      + dob
      + address
      + tNode
          + name
          + dob
          + address

    I hope you know how to map context attributes to the table and form elements. now you can put following code in your submit button action:

    	IPrivate<your view name>.ITNodeElement item = wdContext.createTNodeElement();
    		
    	item.setName(wdContext.currentContextElement().getName());
    	item.setDob(wdContext.currentContextElement().getDob());
    	item.setAddress(wdContext.currentContextElement().getAddress());
    
    	wdContext.nodeTNode().addElement(item);
    
    	//This will clear your form data
    	wdContext.currentContextElement().setName("");
    	wdContext.currentContextElement().setDob(null);
    	wdContext.currentContextElement().setAddress("");
    
    ;

    This will show records into UI table as you insert them.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2008 at 02:17 PM

    hi!

    you can do that by just using the addElement() method in a action for submit button.

    this is a sample code to add records in table.

    //create node

    IPrivateSDNView.ITableDataNode node = wdContext.nodeTableData();

    IPrivateSDNView.ITableDataElement ele = null;

    //iterate through table

    for(int i=0;i<tableRecords.length;i++)

    {

    //create table element

    ele = node.createTableDataElement();

    // set your data to all attributes

    ele.setId();

    //add element

    node.addElement(ele);

    }

    thanks

    vishal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2008 at 04:30 AM

    Hi,

    For this first you need to create the element for your node using:

    node.create<Node Name>Element();

    And then add it to the node using:

    wdContext.node<Node Name>().addElement();

    Hope this helps.

    Cheers,

    Manoj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2008 at 06:07 AM

    Hi,

    I had worked on same requirement, It is simple just use ArrayLIst.

    Let Assume you have three fields Number,Name and Marks. You want to take input of three fields in Form from User and show all the appended values in Table. The following is sample code for that

    1) //Declare a ArrayList in Public Part

    //@@begin others

    ArrayList list=new ArrayList();

    //@@end

    2) // Under your Action Button do the following code

    public void onActionupdate(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

    {

    //@@begin onActionupdate(ServerEvent)

    //Create an Element of node that is pointed to table on each action.

    IPrivateExcelviw.IAbcElement ele = wdContext.createAbcElement();

    //set the values to your table element getting values from form node

    ele.setNo(wdContext.currentAbcElement().getNo());

    ele.setName(wdContext.currentAbcElement().getName());

    ele.setMarks(wdContext.currentAbcElement().getMarks());

    //Add the element to the ArrayList

    list.add(ele);

    //Invalidate the Form node such that the values in Form will be cleared

    wdContext.nodeAbc().invalidate();

    //Bind ArrayList to the node that is pointed to Table UI wdContext.nodeAbc().bind(list);

    //@@end

    }

    Here in this example I had used only one node (ABC) for both Form and Table element. Hope you understand this and your requirement is solved. Revert me if you need any clarifications on this.

    Regards

    Raghu

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.