on 06-29-2009 12:49 PM
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);
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
Please post the exact context structure, including singleton-property settings.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.