cancel
Showing results for 
Search instead for 
Did you mean: 

Binding Dynamic table with Dynamic node

Former Member
0 Kudos

Hi, All

How to bind dynamic node to dynamic table????

i am using below code.using this table is filled with node data,but if 1st column is having 5 rows then 2nd column is displaying

values from 6 rows and first 5 rows r blank for that column.

can anybody tell what is a problem???

if( firstTime)

{

IWDTransparentContainer TableContainer = (IWDTransparentContainer)view.createElement(IWDTransparentContainer.class,"TC1");

IWDGridLayout TableLayout =(IWDGridLayout) TableContainer.createLayout(IWDGridLayout.class);

IWDTransparentContainer rootUIElementContainer= (IWDTransparentContainer)view.getElement("RootUIElementContainer");

rootUIElementContainer.addChild(TableContainer);

IWDTable my_table = (IWDTable)view.createElement(IWDTable.class,filename);

IWDNodeInfo nodeInfo= wdContext.getChildNode(filename,0).getNodeInfo();

my_table.bindDataSource(nodeInfo);

for (Iterator attributes = nodeInfo.iterateAttributes(); attributes.hasNext() ; )

{

IWDAttributeInfo attribute = (IWDAttributeInfo) attributes.next();

String attributeName = attribute.getName();

IWDTableColumn column = (IWDTableColumn) view.createElement(IWDTableColumn.class, null);

IWDCaption caption =(IWDCaption)view.createElement(IWDCaption.class, null);

caption.setText(attributeName);

column.setHeader(caption);

my_table.addColumn(column);

IWDTextView editor = (IWDTextView) view.createElement(IWDTextView.class, null);

editor.bindText(nodeInfo.getAttribute(attributeName));

editor.setWrapping(true);

column.setTableCellEditor(editor);

}

TableContainer.addChild(my_table);

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

try to give ids to the uielement created..

int count =0;

for (Iterator attributes = nodeInfo.iterateAttributes(); attributes.hasNext() ; )

{

IWDAttributeInfo attribute = (IWDAttributeInfo) attributes.next();

String attributeName = attribute.getName();

IWDTableColumn column = (IWDTableColumn) view.createElement(IWDTableColumn.class, attributeNamecount"col");

IWDCaption caption =(IWDCaption)view.createElement(IWDCaption.class, attributeNamecount"cap");

caption.setText(attributeName);

column.setHeader(caption);

my_table.addColumn(column);

IWDTextView editor = (IWDTextView) view.createElement(IWDTextView.class, attributeNamecount"edit");

editor.bindText(nodeInfo.getAttribute(attributeName));

editor.setWrapping(true);

column.setTableCellEditor(editor);

count++;

}

Revert if you are still facing problems.

Best Wishes

Idhaya R

Former Member
0 Kudos

hi..

thanks for reply.i have tried ur solution,but same problem.

is it becoz am creating IWDTextView editor for each element of attribute????

Former Member
0 Kudos

Hi ,

Try to use this code.. It works for me..

Here the table is added to rootuielementcontainer

//Populating the table So that it can be editable..

IWDView view = (IWDView)wdControllerAPI;

//Creating Table

String Id = "UserDataTable";

view.createElement(IWDTable.class,Id);

IWDTable UserTable = (IWDTable) view.getElement(Id);

UserTable.bindDataSource(wdContext.nodeUserData().getNodeInfo());

IWDTableColumn Col;

IWDInputField Inp;

IWDCaption Cap;

String ColId = "Col";

String InpId = "Inp";

String HeadId = "Head";

String CurrCol ;

String CurrInp;

String CurrCapt;

int count = 0;

for (java.util.Iterator j= wdContext.nodeUserData().getNodeInfo().iterateAttributes(); j.hasNext();)

{

//Creating ids for current columns..

CurrCol = ColId+count;

CurrInp = InpId+count;

CurrCapt = HeadId+count;

//Creating Correspondin UI Elements for the generated ids..

view.createElement(IWDTableColumn.class,CurrCol);

view.createElement(IWDInputField.class,CurrInp);

view.createElement(IWDCaption.class,CurrCapt);

//Getting the UI elements generated to set the values..

Col = (IWDTableColumn) view.getElement(CurrCol);

Inp = (IWDInputField) view.getElement(CurrInp);

Cap=(IWDCaption) view.getElement(CurrCapt);

//Getting the Attribute Info..

IWDAttributeInfo AttInfo = (IWDAttributeInfo)j.next();

Cap.setText(AttInfo.getName());

Inp.bindValue(AttInfo);

//Setting values for the column , text view and caption..

Col.bindAccessibilityDescription(AttInfo);

Col.setTableCellEditor(Inp);

Col.setHeader(Cap);

//Adding the column to the table..

UserTable.addColumn(Col);

count++;

}

IWDUIElementContainer root =

(IWDUIElementContainer) view.getRootElement();

root.addChild(UserTable);

UserTable.setVisibleRowCount(10);

Best Wishes

Idhaya R

Former Member
0 Kudos

hi

thanks for help

i think problem is with node creation.

Former Member
0 Kudos

Hi Sufi,

Try to use this get the details from the excel to the node..

Add jx.jar to your build path..

ExcelFile u2013 ValueAttribute of type resource to store the file

UserData u2013 Here node created at design time itself. Only value attributes are added at runtime.

Once the node is created try to test it by using the nodes commented.. Write this code in the view controller..

Else you need to do context mapping also dynamically..

InputStream InpStream = null;

if (wdContext.currentContextElement().getExcelFile()!=null)

{

if (wdContext.currentContextElement().getExcelFile().getResourceType().getFileExtension().equalsIgnoreCase("xls"))

{

try {

InpStream = wdContext.currentContextElement().getExcelFile().read(true);

} catch (IOException e) {

wdComponentAPI.getMessageManager().reportException(e.getMessage(),true);

}

}

else

{

wdComponentAPI.getMessageManager().raiseInvalidContextAttributeException((IWDNodeElement)wdContext.currentContextElement(),wdContext.getNodeInfo().getAttribute("ExcelFile"),"Please choose an excel file",true);

}

}

else

{

wdComponentAPI.getMessageManager().reportException("Please select an file",true);

}

if (InpStream!=null)

{

try {

Workbook workbook = Workbook.getWorkbook(InpStream);

Sheet sheet = workbook.getSheet(0);

int columnCount = sheet.getColumns();

int rowCount = sheet.getRows();

for (int i = 0; i <rowCount; i++)

{

if(i!=0) {

IPrivate<ViewName>.IUserDataElement UserDataEle = wdContext.createUserDataElement();

if (wdContext.nodeUserData().size()==0)

{

wdContext.nodeUserData().bind(UserDataEle);

} else

{

wdContext.nodeUserData().addElement(UserDataEle);

}

wdContext.nodeUserData().moveLast();

}

for (int j = 0; j<columnCount; j++)

{

if (i==0)

{

wdContext.nodeUserData().getNodeInfo().addAttribute(sheet.getCell(j,0).getContents(),"com.sap.dictionary.string");

}

else

{

// Setting the values..

wdContext.nodeUserData().currentUserDataElement().setAttributeValue(sheet.getCell(j,0).getContents(),sheet.getCell(j,i).getContents());

} } } } catch (FileNotFoundException e) {

wdComponentAPI.getMessageManager().reportException("FileNotFound EXception occured"+e.getMessage(),true);

} catch (IOException e) {

wdComponentAPI.getMessageManager().reportException("IO Exception occured"+e.getMessage(),true);

}

catch (BiffException e)

{

wdComponentAPI.getMessageManager().reportException("Biff Exception occured"+e.getMessage(),true);

}

catch (Exception e)

{

wdComponentAPI.getMessageManager().reportException("Exception occured"+e.getMessage(),true);

}

}

//For testing wheter the values are populated correctlyu2026

// wdContext.nodeUserData().moveFirst();

//

// for (int i = 0; i<wdContext.nodeUserData().size();i++)

// {

// for (java.util.Iterator j= wdContext.nodeUserData().getNodeInfo().iterateAttributes(); j.hasNext();)

// {

// IWDAttributeInfo AttInfo = (IWDAttributeInfo)j.next();

//

// wdComponentAPI.getMessageManager().reportSuccess("For the element"i" for the attribute "AttInfo.getName()" the value is "+ wdContext.nodeUserData().currentUserDataElement().getAttributeAsText(AttInfo.getName()));

//

// }

//

// wdContext.nodeUserData().moveNext();

// }

//

Best Wishes

Idhaya R

Edited by: IdhayaR on Jun 30, 2009 8:21 AM

Former Member
0 Kudos

hi IdhayaR

i am trying ur solution but got error on following statement

IPublicUserCreateApp.IUserDataElement UserDataEle = wdContext.createUserDataElement();

plz Explain what does it mean.i am unable to get I<node_name>DataElement

Former Member
0 Kudos

The node should be created at desgin time..

IPrivate<ViewName>.I<Node_Name>Element = UserDataEle = wdContext.create<Node_Name>Element();

Best Wishes

Idhaya R

Former Member
0 Kudos

hi

Its done

Thanks a lot.

Answers (1)

Answers (1)

Former Member
0 Kudos

Please post the exact context structure, including singleton-property settings.

Armin

Former Member
0 Kudos

hi Armin

The scenario is i want to read the excel sheet and create context stucture for it.The structure should be as follows:

Node(ExcelData)

- Attribute1(column1)

-Element(data in column1)

- Attribute2(column2)

-Element2(data in column2)