on 11-27-2012 1:53 PM
Hi
can u pls help me how to create Dyanmic node and attributes by using text file .
text file contains metadata information like#
Label,DataType,readonly
Date,Date,false
EMP number,Integer,false
EMPName,String,false
SAL,Integer,false
by using above text file , need to create dynamic node and attributes and dynamic table.
can u pls help me on this how to create dynamic node and attributes binding which retrive from text file values
Hello,
Firstly, read the text file using StreamReader or any other IO stream reader class.
Once you have read the file, move the values into a data structure like array or hash map.
So now, you have in the code(@run time), the context name and type.
In your WD method (init()), use the following code to create a node:
for( // loop the array or hash map for all the entries >> ){
// For each entry create the context node and set its attributes
IWDNodeInfo dynNode = wdContext.getNodeInfo();
IWDNodeInfo subNode = dynNode.addChild("SubNode",null, true, false, true, false, false, true, null, null, null);
subNode.addAttribute(//array[i].getName(); //array[i].getType); Ex: "FirstName", "ddic:com.sap.dictionary.string"
........ and so on.
}
Hope it helps.
Regards,
Sharath
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sharath,
thanks for your replay..
Here i am able to read file and get the column details and line by line .
But when i create a dynamic table , getting Table but not editable and no property is not binding to the column .may be problem is getting bind value with Input filed.
Pls see my code below #
File file = new File("/XXXX/XXX/abc.txt");
br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null)
{
line = br.readLine();
String[] splts = line.split(",");
String col1 = splts[1];
IWDNodeInfo rootNodeInfo = wdContext.getNodeInfo();
IWDNodeInfo soNodeInfo = rootNodeInfo.addChild(
"Table",null,true,false,true,false,true,true,null,null,null)
IWDNode soNode = wdContext.getChildNode("Table", 0);
IWDNodeElement element=soNode.createAndAddElement();
table = (IWDTable) view.createElement(IWDTable.class, null);
table.setVisibleRowCount(6);
root.addChild(table);
table.setReadOnly(false);
nameColumn = (IWDTableColumn) view.createElement(IWDTableColumn.class, "column"+j);
IWDInputField editor = (IWDInputField) view.createElement(IWDInputField.class, "text"+j);
nameColumn.setTableCellEditor(editor);
editor.setReadOnly(false);
editor.bindValue(wdContext.getChildNode("CatsTable",IWDNode.LEAD_SELECTION).getNodeInfo().addAttribute("Label"+j,"ddic:com.sap.dictionary.string"));
IWDCaption caption = (IWDCaption) view.createElement(IWDCaption.class, "caption"+j);
table.setHeader(caption);
caption.setText(" Entry Screen");
IWDCaption caption1 = (IWDCaption) view.createElement(IWDCaption.class, null);
nameColumn.setHeader(caption1);
caption1.setText(col1);
When i deploy the above code , table will display but not columns binding other prorperties in text file like ( readonly,hasf4.....)
thank you
Clarify the following:
So, as i understand, you are able to create dynamic context node but unable to bind the dyn context to the dynamic view elements, right?
Are you able to ascertain that the dyn context is created before the dynamic view elements?
Do you face any error or exception? If so, at which line of the above code?
Regards.
Hi Sarath
your understand is correct , i am unable to create dynamic view elements by using text file .
text file contains#
Label,DataType,readonly,hasF4
Date,Date,false.false
EMP number,Integer,false,false
EMPName,String,false,false
SAL,Integer,false,true
I am gettting table but columns are not reading above text file prorperties of datatype,read only, has F4....
Can u pls guide me how to bind the properties to the bind value of input filed
waiting for your replay
As a rule, create the views in wdModifyView() and preferabbly only once i.e. if(firstTime).
Next, before you bind, try to print the contexts created adynamicattly. This is to check if the nodes are created as expected. Also, check the cardinality set to the dynamic table context node.(Many times its these properties, which make the table non-editable as no element is available set it to 1..n to have a default element from framework)
Do not perform any context manipulation in wdModifyView().
If possible, enable debugging and set break point when the table is created to check if the attributes are getting assigned.
Regards.
Hi...
can you pls explain how to bind text file values by using IWDNode createAndAddElement();
i am able to create dynamic node #
IWDNodeInfo soNodeInfo = rootNodeInfo.addChild(
"Table",null,true,false,true,false,true,true,null,null,null);
soNodeInfo.addAttribute("emp","ddic:com.sap.dictionary.integer");
soNodeInfo.addAttribute("empnumber","ddic:com.sap.dictionary.integer");
now my question is ,how to bind other prorpeties values in text file ( example : Datatype,read only,has F4) to the IWDNode.
Thank you...
"
br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null)
{
line = br.readLine();
String[] splts = line.split(",");
String col1 = splts[1];"
Instead of moving it into variables, move it into array.
Then look the array... and each row is equal one context node. You can choose to store the related attributes like data type, read only etc.. may be in another array... ex. main array can hold the key and another structure - hashmap can hold key and values like data type, read only etc. This is done while reading text file.. Perform the complete read and load .
In wd modify, get the first key and obtain its attributes from map. Create a element and then set the value.
Ex:
if(dynContext.name = table node){
// create the node
}else if(dynContext.name = input field{
// create input field
// assign the dyn cont attribute - bind
// assign the filed to root/table ui element
} so on.
Hi Sharath,
Thanks for your quick responses.
I am not able to understand your things mentoned on above, i am new to java.io packages.
if possible , can you pls explain with clearly with possible example.
i created one array
ArrayList<String> attributeslist = new ArrayList<String>();
attributeslist.add(col1);attributeslist.add(col2);attributeslist.add(col3);
attributeslist.add(col4); attributeslist.add(col5); attributeslist.add(col6);
for (int i=0;i<7;i++)
{
attributeslist.get(i);
}
Is this correct way i am writing , next how can i bind to IWDNode and bind to table .
Thank you..
Can any body help me how to create IWDNode and createAndAddElement() elements by using text file data.
Able to read text file , but unable to create elements .
Text file contains
AttributeName,Label,DataType,readonly,hasF4
ZZDATE,Date,Date,false,false
ZZEMP,EMP numbert,String,false,false
ZZEMPSalary,emp salary,String,false,false
waiting for your replay...
Try this:
for(int i=0; br.readLine()) != null; i++){
textLinesArray[i] = br.readLine();// move the current read line into array
}
// Let this array be static because this has to be used in the wdModifyView() to create the ui elements
for( int index = 0; index< textLinesArray.length; index++){
textLinesArray[index].split(","); // move the split values into a single array.
// The single array's first element - AttributeName; second element - Label; third element - //DataType; fourth element - readonly; fifth element - hasF4
Now, use IWDNODE and IWDNODEELEMENT to create nodes , elements and assign view elements.
}
Regards.
Hi sarath,
thanks for your replay.
i followed your steps and create elements by using IWDNode createandaddElements().
But now i am trying to create one dynamic table by using this IWDNodeInfo and IWDNode.
When i try to deploy, i am getting only empty table no rows no columns are not displaying.
can you pls check is any thing changes required in my code.
once again thanks for your early replay
//@@begin wdDoModifyView
IWDUIElementContainer root = (IWDUIElementContainer) view.getRootElement();
table = (IWDTable) view.createElement(IWDTable.class, null);
table.setVisibleRowCount(6);
root.addChild(table);
table.bindDataSource("CatsTable");
try {
File file = new File("/sapmnt/H4P/global/custom/Metadata_bhavana.txt");(server path of the text fle)
br = new BufferedReader(new FileReader(file));
String line = null;
for(int j=0; br.readLine() != null; j++){
textLinesArray[j] = br.readLine();
for( int index = 0; index< textLinesArray.length; index++){textLinesArray[index].split(",");
soNodeInfo.addAttribute(textLinesArray[0],"ddic:com.sap.dictionary.date");
soNodeInfo.addAttribute(textLinesArray[1],"ddic:com.sap.dictionary.string");
soNodeInfo.addAttribute(textLinesArray[2],"ddic:com.sap.dictionary.string");
IWDNodeElement element=soNode.createAndAddElement();
element.setAttributeValue("AttributeName",textLinesArray[0]);
element.setAttributeValue("Label",textLinesArray[1]);
//////added all elements
nameColumn = (IWDTableColumn) view.createElement(IWDTableColumn.class, "column"+j);
IWDInputField editor = (IWDInputField) view.createElement(IWDInputField.class, "text"+j);
nameColumn.setTableCellEditor(editor);
editor.bindValue(wdContext.getChildNode("Table",IWDNode.LEAD_SELECTION).getNodeInfo().getAttribute(textLinesArray[j]));
table.addColumn(nameColumn);
IWDCaption caption1 = (IWDCaption) view.createElement(IWDCaption.class, null);
nameColumn.setHeader(caption1);
caption1.setText(textLinesArray[j]);
}}
br.close();
}
} catch (Exception e) { e.getMessage(); }
after deploy this code, gettting empty table with out rows and columns.
can you pls check once , is any thing changes required in my code
Overview - feedback:
- Create the context nodes first- prefarably in the initi method of controller and not in wdModify View
- Code:
try {
File file = new File("/sapmnt/H4P/global/custom/Metadata_bhavana.txt");(server path of the text fle)
br = new BufferedReader(new FileReader(file));
String line = null;
for(int j=0; br.readLine() != null; j++){
textLinesArray[j] = br.readLine();
}// close the tag. First load all entries into array
Then loop the array.
Now the problem is more related to programming aqnd debug techniques.
Try to print the lenghts and contents of array, dyn nodes, elements etc... to test if your code is working as expected.
Regards,
Sharath
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.