struts2 and dojo grid - struts2

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

Related

Get selected combobox item

I have two comboboxes that get their data from read-only views. How do I get the selected values once the form is submitted? 
All of the Vaadin samples dealing with comboboxes use data binding to entity classes but I'm not able to find an example of how to do this without it.
You should be able to retrieve ComboBox#getValue() without any data binding.

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

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[].

Model binding to DataTable with no underlying database

I am bootstrapping myself through my very first ASP MVC project, and could use some suggestions regarding the most appropriate (data-side) model binding solution I should pursue. The project is 'small', which really just means I have very limited time for chasing down dead-ends, which cramps my available learning curve. Thanks heaps for reading!
Background: a simple address search app (ASP.NET MVC 3) that sends user form input to a vendor-sourced server, and presents the results returned from the server in a rules-driven format. There is no CRUD-style repository as such; this is an entirely read-only application. The vendor's .NET server API specifies the use DataTable objects (System.Data.DataTable) for both requests and replies.
Currently: I have a prototype under construction to validate server behavior and inform the application's design. There is a conventional MVC data model class for the input form which works great, auto-binding with the view just as you'd expect. When submitted, the controller passes this input model to my vendor API wrapper, which is currently binding to the request table medieval-style:
public DataTable GetGlobalCandidateAddresses(AddressInputModel input)
{
...
DataRow newRow = dataTable.NewRow();
newRow[0] = input.AddressLine1;
newRow[1] = input.AddressLine2;
newRow[2] = input.AddressLine3;
...
dataTable.Rows.Add(newRow);
...
This works fine; the inputs are fixed and have very light validation requirements. However, if there is a modern framework solution for quickly reflecting a DataTable from my model, that would be peachy.
My real conundrum, however, is on the reply. The table returned by the server contains a variable column-set, with any combination of at least 32 possible unordered fields on a per-transaction basis. Some of the column names contain compiler-invalid characters ("status.description") that won't map literally to a model property name. I will also have a need to dynamically map or combine some of the reply fields in the view model, based on a series of rules (address formats vary considerably by country), so not all fields are 1-to-1.
Just to get the prototype fired up and running, I am currently passing the reply DataTable instance all the way back to a strongly-typed view, which spins it out into the display exactly as is. This is nice for quickly validating the server replies, but is not sufficient for the real app (much less satisfying best practices!).
Question: what is my best tooling approach for binding DataTable rows and columns into a proper model class for display in a view, including some custom binding rules, where no underlying database is present?
Virtually all of the training materials I am consuming discuss classic database repository scenarios. The OnModelCreating override available in the Entity Framework seems ideal in some respects, but can you use a DBContext without a DB connection or schema?
If I have to roll my own model binder, are there any tricks I should consider? I've been away from .NET for a while (mostly Java & SQL), so I'm picking up LINQ as I go as well as MVC.
Thanks again for your attention!
Create a poco display model AddressDisplay and do custom object mapping from the data table to the display model. You can use data annotations for formatting but you can also do that in your custom mapping. You shouldn't need to create a custom model binder.
So create two poco models, AddressInput and AddressDisplay, you can use data annotations on AddressInput for validation. When AddressInput is posted back, map it to the outbound data table. When the response is received, map the inbound data table to AddressDisplay and return the view to the user.

JQGrid with xml file as data source

How can I edit a xml file using JQGrid? I am using ASP.Net MVC 3.5 with C#. Is it possible to return a JSon object from controller method for this purpose?
Everything is possible. But the most work which you have to do is independ from the jqGrid. Moreover general XML file can be not good represented in a grid. If the deepness of the XML file not so long, you can use subgrid feature of the jqGrid. One more restriction existing in the jqGrid can make the work more comple: jqGrid not support data with attributs other as ids. So if you will have to map attributes to the sub-elements on the server side to be able to use jqGrid.
The ASP.NET MVC site can for example read the XML file with respect of some desirialization methods and initialize the object with the same information as the XML has. Then can use the object to fill the jqGrid and modify the data. Because th data are no mo represented as a XML, the server can use JSON to communicate with the jqGrid. At the end one can use one from wel known serialization methods so save modified data in the XML file back.

MVC - Datagrid binding without a model

Ok, I'll explain. I need to create a datagrid in MVC on the fly (potentially multiple datagrids on a view) depending on a XML file being read in. The file gets looped through and may contain multiple grids of data, the headers and rows are set in the file. The problem being that my application won't know the content of the XML file before reading it so I can't apply it to an IEnumerable model. The idea being to make it generic so that it can read in any XML file I pass to it set up as below and put the data in a sortable datagrid. Is this at all possible with current controls out there? I have tried Teleriks MVC grid and while I can read the data into the grid, I cannot sort the data as this feature will only work when passed a DTO. I have a feeling what I'm looking for can't be done (unless I write a custom HTMLHelper or something) but no harm in asking I guess
My xml will be as such
<xml>
<REPORT>
<HEADERS>
<HEAD>Col1</HEAD>
<HEAD>Col2</HEAD>
</HEADERS>
<ROWS>
<ROW>Data1</ROW>
<ROW>Data2</ROW>
</ROWS>
</REPORT>
</xml>
Thanks
I would advise using the jquery grid. Then write a class to parse the xml and generate the grid javascript in the view, and a second action to parse the xml (again) and generate the json result. MVCCrud may help with the idea there is a generic jquery grid in there but it works off an IQueryable list so would need to be adapted.
I haven't seen a helper extension out there that does what you need.
There are some good ones that work with generic collections (such as Telerik's or MVCContrib's). The sample you provide cannot be translated in to a collection that would be handled by these however: the row needs to have cells that can be matched to the header elements.
<xml>
<REPORT>
<HEADERS>
<HEAD>Col1</HEAD>
<HEAD>Col2</HEAD>
</HEADERS>
<ROWS>
<ROW><CELL>Data1</CELL><CELL>Data2</CELL></ROW>
<ROW><CELL>Data2</CELL><CELL>Data4</CELL></ROW>
</ROWS>
</REPORT>
</xml>
If the XML can be deserialized into a generic collection, it is easy to populate the grid.
Hope this helps.
I'd look into the JQuery Grid. You have to munge the data into the format that it wants, but it gives you a lot of flexibility and nice UI for free. You will still need to write sort code, though.

Resources