on 06-15-2009 7:40 AM
Hi Colleagues,
Could anyone please let me know How to Built an array Dynamically according to some input parameter and How can this array be binded to context.
Thanks & Regards
Swetha
Hi,
Create one node called "DataNode" with two attributes key, value.
//You need to populate this hashmap dynamically from user input
HashMap hmElements=new HashMap();
hmElements.put("google","www.google.com");
hmElements.put("gmail","www.gmail.com");
//Now call the below method by passing the above hashmap
//Method to populate the node data from hashmap data
public void loadElements(HashMap hm)
{
String key=null;
Strinv value=null;
Iterator iter = hm.keySet().iterator();
while (iter.hasNext()) {
key = (String) iter.next();
value = (String) hm.get(key);
IPrivateTestView.IDataNodeElement element=wdContext.createDataNodeElement();
element.setKey(key);
element.setValue(value);
wdContext.nodeDataNode().addElement(element);
}//end of while
}
Regards,
Charan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swetha,
You can either use the way which is described above or use this approach.
1) Create a node in the context named dataNode with 2 attributes. these 2 attribtes will represent the attributes which you wanted to put in the 2 D array. In this case lets say: siteName and siteLink. These are 2 attributes.
2) Use the hashmap instead of array. Please note that I have again used the generics. Use following code:
HashMap<String, String> valueContainer = new HashMap<String, String>();
valueContainer.put("google", "www.google.com");
valueContainer.put("gmail", "www.gmail.com");
3) Create the node elements in the same way:
String siteName=null;
Strinv siteURL=null;
Iterator iter = valueContainer.keySet().iterator();
while (iter.hasNext()) {
key = (String) iter.next();
value = (String) valueContainer.get(key);
IPrivateTestView.IDataNodeElement element=wdContext.createDataNodeElement();
element.setSiteName(siteName);
element.setSiteURL(siteURL);
wdContext.nodeDataNode().addElement(element);
}
I hope this helps!! Please revert back in case you need any further help!
Thanks and Regards
Pravesh
Hi Swetha,
Just create a attribute of type arraylist, under some node. Then you can initialise a array and fill the value to that array, at runtime like this :
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("Value1");
arrayList.add("Value2");
The values in the array can be aything depending upon your requirement. You can get the values at runtime and can fill the arraylist. (NOTE: Please note that I have used the templates here to define that my arraylist will contain String object only. See this: ArrayList<String> arrayList = new ArrayList<String>();. You can set this type to any object, according your requirement.)
Then use this code to set the attribute which you have created in the context.
wdContext.node<NODE_NAME>().set<ATTRIBUTE_NAME>(arrayList);
I hope this solves the issue. please revert back in case you need any further help on this.
Thanks and Regards,
Pravesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pravesh,
Thank you for the reply,
HEre my requirement is like
Array should hold two values title and link.( two dimentional array)
these two are the attributes for a node
Depending on the array size ...node size varies
for Eg :
Array 0: google , www.google.com
Array 1: gmail , www.gmail.com
elements to the array will be added manually depending upon the requirement( sometimes only one title and link...ans sometimes two rows( 2titles and 2 links)....and if arraysize is 1 then node size should be 1...if arraysize is 2 then node size should be 2.
Please let me know how to proceed
Thanks & Regards
Swetha
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.