on 06-13-2005 11:20 AM
hai everybody
in webdynpro we know how to create at design time
but i want to create it at runtime that is dynmamically i want to set the rows and coloums of the table at run time
Thanks & Regards
sravan
I guess this should work,
Suppose you want to dynamically create a Table (say Category) having a column called Category Code, then in the wdDoModifyView() hook method, just add the following code snippet,
if (firstTime) {
//Create the Table UI Element
IWDTable table = (IWDTable) view.createElement(IWDTable.class, null);
//Set the Table Header
IWDCaption tableCaption = (IWDCaption) view.createElement(IWDCaption.class, null);
tableCaption.setText("Category Table Contents");
table.setHeader(tableCaption);
//Create and add a Column UI element for the above table
IWDTableColumn column = (IWDTableColumn) view.createElement(IWDTableColumn.class, null);
table.addColumn(column);
//Set the required column header using the caption (Category Code here)
IWDCaption caption = (IWDCaption) view.createElement(IWDCaption.class, null);
caption.setText("Category Code");
column.setHeader(caption);
//Create a TableCellEditor and bind it to an attribute of the Category Node in the context
IWDTextView editor = (IWDTextView) view.createElement(IWDTextView.class, null);
editor.bindText("tb_Category.cat_code");
column.setTableCellEditor(editor);
//Finally add the Table UI element to the view
IWDUIElementContainer root = (IWDUIElementContainer) view.getRootElement();
root.addChild(table);
}
You need to follow the same procedure for adding multiple columns to the table.
Hope this answers your question!
Regards
Kishan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use the same code provided by Bharat .
IWDTableColumn colum = (IWDTableColumn)
view.createElement(
IWDTableColumn.class, null);
table.addColumn(column);
// use TextView for displaying
// attribute "Data.City"
IWDTextView editor = (IWDTextView)
view.createElement(IWDTextView.class, null);
editor.bindText("Data.City");
column.setTableCellEditor(editor);
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In the code i have mentioned i have binded it with
Data
--No
--Name
Likewise bind it with some node and bind each table column with a attribute in that node.
At run time just populate the node and it will get populated in the table directly.
Regards
Bharathwaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Bharathwaj thanx for ur code
i did as u said but i got output only dummy table with two columns no data in the table . for getting the data dynamically into the table should i write any java class and one more thing bharath in the view there is only one default Root Container. should i insert any view elements in the view
Thanks in Advance
sravan.
Hi ,
Do you have the context structure as mentioned.
And are you puttin data into that node. If yes check the node size.
If no ..use the code given by Santosh to populate the node.. (change it appropriately to suit ur node names)
//Create table node element
IPrivate<View name>.IDataElement elem = wdContext.nodeData().createDataElement();
// Set data to the column attributes
elem.setNo("1");
elem.setName("Armin");
//Add the node element to the result/table node
wdContext.nodeData().addElement(1, elem);
This is for a node with structure
Data
-- No
-- Name
And this is a sample for adding one set of data.
Regards
Bharathwaj
My Code added ! I am not sure if this is what u have mentioned Armin !
I would suggest a small change in the code given by Bharathwaj
Instead of
IWDTextView editor = (IWDTextView)
view.createElement(IWDTextView.class, null);
write the following code
IWDTableCellEditor editor = (IWDTableCellEditor)
view.createElement(IWDTextView.class, null);
If you need some other element as the cell editor you can just change the class name given in the createElement method call.
how to insert data dynmically in the table and show in the table
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Let me assume the node which is bound to the table UI element is "vnResultTable" and the columns are bound to the "vaCol1", "vaCol2" attributes.
Refer the following code
// no of iterations
int nOutputCount = 5;
for(int j=0;j<nOutputCount;j++){
//Create table node element
IPrivate<<View name>>.IVnResultTableElement objResultTableElement = wdContext.nodeVnResultTable().createVnResultTableElement();
// Set data to the column attributes
objResultTableElement.setVaCol1("Column 1 data");
objResultTableElement.setVaCol1("Column 2 data");
//Add the node element to the result/table node
wdContext.nodeVnResultTable().addElement(j, objResultTableElement);
}
Hope this is helpful. If you need any further help, do let me know.
Regards,
Santhosh.C
hi,
Go the tables property and set visiblerowcount to the number you want
To do it dynamically
Put this code in the modifyview
final IWDTable tbl= (IWDTable)view.getElement("tblname");
tbl.setVisibleRowCount(<get it from context which stores the value required)
regards
Bharathwaj
Message was edited by: Bharathwaj R
hai i need to insert no. of columns at run time
i.e., in the context i create a value node which is a datasource to the table and three value attributes with No. , Name , and Age. i want to insert more columns
should i need to create the value attributes in the context manually or there is any procedure through which we can create value attributes in the context at runtime dynmically
If possible, create the context attributes at design time, it's easier. Adding table columns can then be done in wdDoModifyView() with code like shown before.
Generally, you can do (almost) everything which can be done at design time also via the API.
Can you describe your use case more exactly?
Armin
Hi,
To add a attribute to a node use
IWDNodeInfo node = wdContext.node<name>.getNodeInfo();
node.addAttribute("Attribute",
"ddic:com.sap.dictionary.string or ur type required");
To bind it
<textviewobject).bindValue("Attribute");
To access the getter and setter methods
wdContext.current<node name>Element().
setAttributeValue("Attribute", null);
wdContext.current<node name>Element().
getAttributeValue("Attribute", null);
But i would suggest creating all the attributes in the beginning and do the binding alone at run-time.
Regards
Bharathwaj
hai bharath could you be more precise please
right now i created a table dynamically in this i created one ValueNode <b>Data</b> and 3 value attributes to that node which are the 3 columns in my table.
What i need is i want to create a column at runtime
let us say attribute is <b>city</b>
so where should i write the code
it would be nice if u provide me the code
Thanks & Regards
sravan
Hi,
IWDNodeInfo nodeinfo = wdContext.nodeData.getNodeInfo();
nodeinfo.addAttribute("City",
"ddic:com.sap.dictionary.string");
will create a attribute of type string under the node Data.
You can write this code anywhere.You must be having some action say onAdd after which this new attribute has to be created .Then write it in that part.(onActiononAdd)
Is that sufficient ?
regards
Bharathwaj
bharath i'm trying to add a value attribute City to a ValueNode Data and inserting data into that column using follwoing but im unable it is giving erros at bind value and at getAttribute. please help me
IWDNodeInfo nodeinfo = wdContext.nodeData().getNodeInfo();
nodeinfo.addAttribute("City","ddic:com.sap.dictionary.string");
IWDTextView editor = (IWDTextView)view.createElement(IWDTextView.class, null);
editor.bindValue("City");
//To access the getter and setter methods
wdContext.currentDataElement().setAttributeValue("City", null);
wdContext.currentDataElement().getAttributeValue("City", null);
Hi,
What are the errors.. Do you get the error when u deploy the application or while typing itself.
I think the case u are using is different.Are u using "City" or "city". I have given the code for "City".If u use "city" it will give errors.
And in binding it with a column since it is under a node Data, u have to give "Data.city" or "Data.City" (i.e whatever nodename.attrname)
Rgds
Bharathwaj
Message was edited by: Bharathwaj R
Hi,
The binding should be with the value node name.
IWDTextView editor = (IWDTextView)view.createElement(IWDTextView.class, null);
editor.bindValue("Data.City");
//Create the node element object
IPrivate<<View name>>.IDataElement objResultTableElement = wdContext.nodeData().createDataElement();
//set data to the attributes
objResultTableElement.setAttributeValue("City", null);
//add the node element to the node
wdContext.nodeData().addElement(objResultTableElement);
Hope this is want you are looking for.
Regards,
Santhosh.C
hai everybody please checy out the following the code
by doing so i can create rows in a table dynamically at ryntime of my choice. But i want to insert columns of my choice at runtime using some forloop.
IWDTable table=null;
if (firstTime)
{
// create table and then bind table data source to context node "Data"
table=(IWDTable)view.createElementIWDTable.class,null);
table.setVisibleRowCount(6);
table.bindDataSource("Data");
}
int rowCount = 12;
for(int j=0;j<rowCount;j++){
//Create table node element
IPrivateDynNodeAttributeView.IDataElement objdataElement = wdContext.nodeData().createDataElement();
wdContext.nodeData().addElement(j, objdataElement);
}
IWDUIElementContainer root =(IWDUIElementContainer) view.getRootElement();
root.addChild(table);
Hi,
You must be having some condition after which you should add the column.If so check that condition and add if it is satisfied.
If their is no condition, there might not be a need to go for dynamic attributes.Anyway in this case u can put it as i have shown.
if (firstTime)
{
// create table and then bind table data source to context node "Data"
table=(IWDTable)view.createElementIWDTable.class,null);
table.setVisibleRowCount(6);
IWDNodeInfo nodeinfo = wdContext.nodeData().getNodeInfo();
nodeinfo.addAttribute("City","ddic:com.sap.dictionary.string");
table.bindDataSource("Data");
}
int rowCount = 12;
for(int j=0;j<rowCount;j++){
//Create table node element
IPrivateDynNodeAttributeView.IDataElement objdataElement = wdContext.nodeData().createDataElement();
wdContext.nodeData().addElement(j, objdataElement);
}
IWDUIElementContainer root =(IWDUIElementContainer) view.getRootElement();
root.addChild(table);
Regards
Bharathwaj
Hi,
Ya u can find it mentioned in the thread itself.
Anyway i have executed this code,this is working ..Put this in the place where i have mentioned(after setting visible row count.)
IWDNodeInfo nodeinfo = wdContext.nodeData().getNodeInfo();
nodeinfo.addAttribute("City","ddic:com.sap.dictionary.string");
IWDTextView editor = (IWDTextView)view.createElement(IWDTextView.class, null);
editor.bindText("Data.City");
IWDTableColumn c = (IWDTableColumn)view.createElement(IWDTableColumn.class,null);
c.setTableCellEditor(editor);
table.addColumn(c);
table.bindDataSource("Data");
Regards
Bharathwaj
Hi,
Try this ..
The only requirement is u need a Data node with attributes No and Name in it !
if (firstTime)
{
// create table
IWDTable table = (IWDTable)
view.createElement(IWDTable.class, null);
// bind table data source to context node "Data"
table.bindDataSource("Data");
// create and add first table column
{
IWDTableColumn colum = (IWDTableColumn)
view.createElement(
IWDTableColumn.class, null);
table.addColumn(column);
// use TextView for displaying
// attribute "Data.No"
IWDTextView editor = (IWDTextView)
view.createElement(IWDTextView.class, null);
editor.bindText("Data.No");
column.setTableCellEditor(editor);
}
// create and add second table column
{
IWDTableColumn colum = (IWDTableColumn)
view.createElement(
IWDTableColumn.class, null);
table.addColumn(column);
// use TextView for displaying
// attribute "Data.Name"
IWDTextView editor = (IWDTextView)
view.createElement(IWDTextView.class, null);
editor.bindText("Data.Name");
column.setTableCellEditor(editor);
}
// add table into view layout as child of
// root container
IWDUIElementContainer root =
(IWDUIElementContainer) view.getRootElement();
root.addChild(table);
}
(With help from Armin !)
Regards
bharathwaj
Message was edited by: Bharathwaj R
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thats a fentastic code, thanks,
This way we have to create one column for each attribute.Is it possible to iterate through the datasource node and get the columns created for all the elements by writing code for just one element.
we can internally use if else to create different type of columns for different elements.
PS: i am very new to this world
Regards
Nitin
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.