smartgwt beginner- how to display xml entered in text area into tree - smartgwt

I am working with Smart GWT 3.0 LGPL- I am trying to display in a tree the entire block of XML entered by user into a text area.
I can get the nodelist from the xml entered by user, however in Smart GWT, Tree widget accepts only TreeNode[] members as data.
How do I convert the NodeList (obtained using GWT's inbuilt XML parser) into TreeNode[]? Is my approach correct(to display the xml in tree form)? Or is the solution to solve this problem completely different from what I am thinking?

I assume you use the SmartGWT's TreeGrid object to create the tree. The TreeGrid is just a specialized ListGrid and, as the later, it can be databounded to a Datasource, which can easily parse an XML. Look at this example. It should help you to create a solution to your problem. You can just show only one field in your TreeGrid, if all you need is a simple tree.
In the case that you can't access the xml data through a URL, like accessing them through your text area, after you have parsed them as a NodeList, you should iterate them and create an array of TreeNode objects. For each Something object you should set its associated TreeNode object's attributes using the setAttribute(attributeName, attributeValue) methods. Then create a Tree object, and starting from the root you can add the TreeNode objects using the various methods of the Tree, at the required position. Then a simple: treeGrid.setData(Tree tree) will load and show your data in your TreeGrid.

You can create an array TreeNode[] which have size as nodelist's length, and in a cycle to put on a value. And after that you can set in a tree this TreeNode[].

Related

Vaadin 14 TreeGrid - Cannot add the same item multiple times

Working on a project that will display hierarchies of "tasks". I'm running into a problem where it will not allow for multiple entries of the same object. From what I can tell, the "duplicate" item is under a different parent.
The domain data allows for this - a given task may appear in lots of places.
It would seem that this is intentional (maybe), but is there a way around this?
It's intentional to a degree; each Grid and TreeGrid data item is expected to be unique. You could work around this by creating your own implementation of the hierarchical DataProvider class (for example extend AbstractHierarchicalDataProvider) which overrides the getId method along with the other required methods. The return value of this method needs to be unique per item, as it's used as a hash key.
Well, this is probably not the best solution, but it works.
I added a field to the abstract super class that is initialized with the current time (long ms). When I am adding items to the tree grid, I check to see if the tree contains the item and if so, I randomize the field and then add it. The new field is marked #Transient so it's not persisted.

Can Orbeon controls have multiple values?

I think the answer is no, but the question has been put to me so I'd like to confirm. My understanding is that any custom XBL control that I create for use in Form Builder can have one and only one value. Is this correct?
I have always assumed this because the control name is then used in the data instance as the name of the node which contains the the value.
This question comes from the desire to have reusable components with multiple values, for example, an Address control so that addresses can be recorded consistently and the same set of fields does not need to be added many times. Orbeon does have some support for this in the form of Section Templates but because the control names stay the same in each instance of a Section Template this does not work well with our design.
The best idea I've had is that a custom control which records multiple values could encode all the values into a single text string for example in JSON. Of course, this is not ideal.
Are there any other options?
It is possible for controls to have multiple values. When that happens the values are typically stored in nested elements. I.e. a control could bound to an element <address>, and could create nested elements <street>, <city>,<country>, etc to store the different parts of the address.
In practice, you can look at how this is done in the Image Annotation annotation control (see wpaint.xbl), which creates nested elements <image> and <annotation>, leveraging the xxbl:mirror="true" functionality.

read the value of a child UISelectItems component in a parent custm component

I have developed a JSF custom component, based on UISelectOne component and I want implement a custom renderer for it. To specify the list of items I use a child UISelectItems component (through f:selectItems tag) to indicate a list of plain Java objects (not SelectItem objects).
However, when I want to implement Renderer.encodeEnd and get the value of the child UISelectItems component, instead of getting a list of SelectItems (as indicated in the documentation) I get my original list of plain Java objects.
I imagined that internally, UISelectItems will still be working with SelectItem object, however the custom tag will provide a mean to convert the list of Java objects into a list of SelectItem and I will only see, internally, SelectItem objects. Which is not the case.
Of course, I can just consider my own plain Java objects and proceed with the implementation of the encodeEn method. But I want the component to fully benefit from the fact that through f:selectItems you can specify any list of Java objects as long as you mention also itemValue and itemLabel attributes.
Thanks.

struts2 and dojo grid

I need an example for populating the dojo grid with the data coming from server. I have struts2 and dojo application in which action class is setting a model variable of type hashmap as the result containing different values that needs to be shown in the form of grid.
Now how can i represent this hashmap in the form of grid data. can you please giving a sample example application which converts the hashmap to json and then uses this json to populate the grid.
I use Jackson to serialize to JSON. Does each item in the map represent a row in the grid? How complex is the data that you are serializing?
https://github.com/FasterXML/jackson-core
If the data structure is simple, then you can probably get away with just using Jackson.
When you want to begin serializing more complex data structures, then you might need to enhance your serialization engine.
I have written some stuff that can do this. Too much to explain here but you can check out these blog posts and see the code on git hub:
http://swingingcode.blogspot.com/2012/04/json-serialization-engine-part-i.html
http://swingingcode.blogspot.com/2012/04/json-serialization-engine-part-ii.html
https://github.com/cswing/evinceframework/tree/master/web/src/java/com/evinceframework/web/dojo/json

FreeMarker hash lookup using object graph notation

I have 2 variables in parameters map populated from a struts2 tag, as follows:
obj - A java object with various child objects. It can be treated as a hash in freemarker template.
displayProperty - A string containing property name inside the obj. The name can be object graph containing multiple levels of drill down.
I want to display the given property of the obj using freemarker template. For example if displayProperty is entity.name, then it should essentially print value of obj.entity.name.
My freemarker template is ${obj[displayProperty]}, but it fails when displayProperty contains a dot.
One solution would be ('obj.' + displayProperty)?eval, although it involves generic expression parsing and so is not the fastest. The fastest running solution would be to create a custom method (TemplateMethodModelEx implementation) that you could use like ${walkProperty(obj, displayProperty)}, which would split the string at the dots, and call TempalteHashModel.get in a loop.

Resources