Recursive loop in java to create tree structure in jsp page - jsf

I used tomahawk tree2 component to display directory structure in a JSP page. I have maintained parent and child folder relationship in a database table. Example DB table looks as below.
When i pass 7 as PARENT_FOLDER_ID to the table i get 87 and 587 as it's sub-folders. Again 87 and 587 contains 6067 and 12704 as their sub-folders. This example only has 2 level relationship.
I need to traverse this relationship until last sub-folder(Which doesn't contains folders.From the example 2117, 2177, 2312, 2379, 6067, 12704 are last folders.). How to achieve this traversing process in java. Please help me to find the solution.
Thank you.

Recursive approach:
public void processChilds(int parentID) {
List childs=selectChilds(parentID);//call method which return list of sub folders of the parameter
for(int i=0;i<childs.size();i++) {
processChilds(childs.get(i));//call processChilds() for each child
}
}
And Implement the selectChilds(int parentID) as your requirement and that must return list of sub folders.

Related

How do I find all elements which have a css class in coded ui?

I need to find all Html controls which have a given css class.
var htmlControl = new HtmlControl(document);
htmlControl.SearchProperties[HtmlControl.PropertyNames.Class] = #class;
var uiTestControlCollection = htmlControl.FindMatchingControls();
Using the class name works when there is just one css class on the control. If I have more than one css classes applied on the element, can I search for the element by specifying just one css class and not all of them?
Thanks
You can perform a partial match, like so:
htmlControl.SearchProperties.Add(HtmlControl.PropertyNames.Class, #class, PropertyExpressionOperator.Contains);
var uiTestControlCollection = htmlControl.FindMatchingControls();
The main draw back of this is that it is just a simple string compare. To illustrate, imagine you have two controls A and B. A has class "Test" and B has classes "testdiv topnav". Now if you perform a search for "test", both controls A and B will be selected.
To match a class exactly, you can provide a close as match as possible using the above method and write a helper function to:
Loop through the collection
Get the class of each control
Split the class string on the spaces
Loop through this array and test each for an exact match
Keep the elements where a class matches exactly
Note: This is clearly non-optimal - I'm all ears if someone has a better solution.
Cheers,
Seb

Why isn't J2ME able to create recursive directory creation?

I want to create recursive directories ( for example : Connector.open("file:///Phone:/folder_1/folder_2/", Connector.READ_WRITE); ). The problem is that the two folders , here folder_1 and folder_2, are not mentioned explicitly but instead there is only one String parameter provided from a method. For example :
private void myMethod(String path)
{
fcDir = (FileConnection) Connector.open("file:///Phone:/"+path+"/", Connector.READ_WRITE);
...
}
And in runtime the two folders are not created ! So I must create separately two FileConnection in order to create the two folders ! So why J2ME is not able to make a recursive directory creation ?
you may also try thing new way. you can make your method recursive, now pass one vector & integer parameter, vector's element will be the list of directories you want to create and integer will specify the number of time method should call it self.
i.e. for folder_1 & folder_2 you can pass parameter as method_name ( folderVector, 2 ). here folderVector variable contains two String element as folder_1 & folder_2. Now you need to call your method recursively such that , each time second parameter decrements it's value with one down. Run this method till it is greater than zero.
This is the one way you can do it recursively.

Find by String in a GWT ListBox

I would like to find the index of an item inside a GWT Listbox by specifying a String value.
For example, if I had a GWT ListBox comprising the following items: "Randy", "Bob" and "Helen", the method i'm looking to implement would return the value 1 if I called it with parameter "Bob".
From what i'm seeing in the ListBox javadoc, ther does not seem to be any quick method to do this.
Any ideas?
Thanks in advance!
My idea of implementation as TextBox doesn't provide this out of the box. Store all the items in a list and in the order you want them to be part of ListBox.
List<String> orderedItems=new ArrayList<String>
orderedItems.add(0,"Randy");
orderedItems.add(1,"Bob");
orderedItems.add(2,"Helen");
//adding items in the same order as they are in List is the key
for(String item:items)
{
lb.addItem(item);
}
then you can find the index using List's indexOf(..) method

J2ME Record deletion problem in RecordStore

I am using a recordstore to store some data,and each data is being shown in form of list elements.In my application,i am having a feature in which i can delete a particular list element.When i perform this action,item is getting deleted from the list but it is not working with the record.
I dont know why?
Can any one help me?
My code snippet is:
int x=list.getSelectedIndex();
list.delete(x);
try
{
rs_store.deleteRecord(x);
}
catch(Exception error)
{
System.out.print("error");
}
display.setCurrent(list);
Thanks in advance
If the indices of the items in your List are supposed to correspond with the indices of items in your RecordStore, then your problem may be down to the fact that RecordStore entries are 1-based, not 0-based.
So element 0 in your list will correspond to record 1 etc.

I need a ObservableCollection of tree levels

i need to create a ObservableCollection<> for tree o more levels in c# like this:
Group 1
Group 2
Group 1
Group 2
Group 1
Group 2
Group 3
thanks in advance,
Timmy Leonard
make a "node" class that contains an observable collection of child nodes, like this:
class node
{
// add some data properties in here, too
public ObservableCollection<node> children;
}
// declare an instance, in the data model (or where-ever)
ObservableCollection<node> RootLevel = new ObservableCollection<node>();
I could probably give you a better answer if I knew what platform your trying to do this for. (WPF or Silverlight, etc)

Resources