cancel
Showing results for 
Search instead for 
Did you mean: 

Reg Row Selection in a Table UI Element

jnmurthi
Participant
0 Kudos

Hi All,

Can anyone help me in writing code to select a row from a table.

I need to read the data from a row selected in a table and print it in the next page of my application.

I request anyone to send me some coding line on how to select a row from a table and read data from it.

Regards,

Murthy.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member751941
Active Contributor
0 Kudos

Hi Narayana,

Follow the steps.

Step1: Create a WD Component.

Step2: Under Component Controller create a

i) 2 Node “EmployeeInfo” and “EmployeeRecord” with attribute “EmployeeName” and “Position” of cardinality 0..n for both the node and a context attribute “WindowInstance” of type “com.sap.tc.webdynpro.services.session.api.IWDWindow”

Step3: Go to the Diagram View. Do the mapping between “EmployeeView” and “Component Controller” and between “DisplayView” and “Component Controller”

Step4: Design 2 Views layout

i>EmployeeView

Layout like

-


Employee Name | Employee Position

-


EmployeeInfo.EmployeeName| EmployeeInfo.Position

-


EmployeeInfo.EmployeeName| EmployeeInfo.Position

-


DisplayResultButton

ii>DisplayView

Layout like

-


Employee Name | Employee Position

-


EmployeeRecord.EmployeeName | EmployeeRecord.Position

-


EmployeeRecord.EmployeeName | EmployeeRecord.Position

-


CloseWindowButton

Step5: Create 2 Windows

1>EmployeeWindow

2>DisplayWindow.

Under “EmployeeWindow” add the “EmployeeView”

and “DisplayWindow” add the “DisplayView”

Step5: Associate action “DisplayResult” with the “DisplayResultButton” and use this code inside the Implementation of “EmployeeView”

public void wdDoInit()

{

//@@begin wdDoInit()

//initialize nodes

wdContext.nodeEmployeeInfo().addElement(wdContext.createEmployeeInfoElement());

wdContext.nodeEmployeeRecord ().addElement(wdContext.createEmployeeRecordElement());

//@@end

}

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

{

//@@begin onActionDisplayResult(ServerEvent)

try

{

IPrivateDisplayView.IEmployeeRecordElement empRec =

wdContext.createEmployeeRecordElement();

int n = wdContext.nodeEmployeeInfo().size();

int leadSelected = wdContext.nodeEmployeeInfo().getLeadSelection();

// loop backwards to avoid index troubles

for (int i = 0; i < n ; i++) {

if (wdContext.nodeEmployeeInfo().isMultiSelected(i) || leadSelected == i) {

empRec.setEmployeeName(wdContext.nodeEmployeeInfo().getElementAt(i).getAttributeValue("EmployeeName"));

empRec.setPosition(wdContext.nodeEmployeeInfo().getElementAt(i).getAttributeValue("Position"));

wdContext.nodeEmployeeRecord().addElement(empRec);

}

}

catch(Exception e)

{

e.printStackTrace();

}

}

IWDWindowInfo windowInfo =(IWDWindowInfo) wdComponentAPI.getComponentInfo().findInWindows(

"DisplayWindow");

// create the Window

IWDWindow window = wdComponentAPI.getWindowManager().createWindow(windowInfo, true);

window.setWindowPosition(WDWindowPos.CENTER);

window.setTitle("WindowTitle");

window.setWindowSize(200,200);

// Save WindowInstance in Context

wdContext.currentContextElement().setWindowInstance(window);

// and show the window

window.show();

//wdThis.wdFirePlugInDisplay();

//@@end

}

Step6: Associate action “CloseWindow” with the “CloseWindowButton

” and use this code inside implementation of “DisplayView”

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

{

//@@begin onActionCloseWindow(ServerEvent)

IWDWindow window = wdContext.currentContextElement().getWindowInstance();

window.destroyInstance();

//@@end

}

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5f699f90-0201-0010-14a4-8950177281ed">Developing with Tables in WebDynpro</a>

Regards,

Mithu

Former Member
0 Kudos

Hello Narayana

Assume

EMP(Node)

---EMPNo(Attribute)

---EMPName(Attribute)

---Salary(Attribute)

This above EMP node is binded with TableUI element.

You are displaying data in Table .Select any row from Table

Click in submit button

onActionSubmit()

{

wdContext.currentEMPElement().getEMPNo();

wdContext.currentEMPElement().getEMPName();

wdContext.currentEMPElement().getSalary();

}

With above u get current selected Row from Table.

Then accroding to requirement you go ahead.

Rgds

-SS

jnmurthi
Participant
0 Kudos

hi

Thank you

its working.

Regards,

Murthy.