Java Juice
Champion

Champion

Champion (Taken with instagram)

Champion (Taken with instagram)

Survivor (Taken with instagram)

Survivor (Taken with instagram)

USA USA USA!! (Taken with instagram)

USA USA USA!! (Taken with instagram)

Taken with instagram

Terminator!

Taken with instagram

Terminator!

Best sweet potato pie recipe #in

After trying many recipes, here is the one that I go back to each year.

Dave Lieberman’s recipe makes makes a great pie out of simple ingredients and the crust is way better than the factory made pre-packaged ones that you would find on store shelves.

I usually make a lighter version by going light on butter and cream and using just egg whites.

Happy holidays!!!

parislemon:

Well, we all knew this was coming

In a sit down with Forbes’ Eric Savitz, Microsoft Chief Research and Strategy Officer Craig Mundie talks about how Microsoft has actually been doing what Siri offers for the past year with Tellme technology on Windows Phone. He dismisses Siri’s buzz as basically just good marketing and people being “infatuated” with Apple. 

Sadly, the majority of the time a company comes out with something that excites people, a competitor will come out and yell “FIRST!”. When Apple makes the product, it tends to happen every single time. And Microsoft is the worst at this type of “us first” nonsense. They don’t seem to realize that it just makes them look pathetic — or worse, highlights their own irrelevance in the space. 

I’m reminded of a line from the Mark Zuckerberg character in The Social Network:

“If you had invented Facebook, you would’ve invented Facebook.”

pepper spray fup.

pepper spray fup.

Datatables - Spring MVC Integration

Here is a possible solution to the Datatables - Spring MVC integration requirements that I had come up with earlier. I will walk through from the Controller to the Model objects and then the Datatables integration.

Step 1

Write your controller using semantic DataTablesRequest and DataTablesResponse classes as part of your controller methods.

@Controller
@RequestMapping(value="/api")
public class DataController {

    @RequestMapping(value="/data", method= RequestMethod.POST)
    public @ResponseBody
    DataTablesResponse<Object> getData(@RequestBody DataTablesRequest dtReq, HttpServletResponse response) {
        return new DataTablesResponse<Object>();
    }
}

Step 2

The DataTablesRequest and DataTablesResponse are the interface to Datatables in our Java system. I use standard Jackson annotations to serialize the JSON object into a Java object. Note that I have modified the standard Datatables API on the wire to make it possible to do a straight-forward serialization into a Java object.

The most notable change is how attributes such as sSearch_0=value1, sSearch_1=value2,...,sSearch_n=valuen are converted into an array like sSearch=[value1,value2,...,value3]

I am not handling all types of attributes and values right now, but this is the basic outline….

/**
 * {
 *  "sEcho":1,
 *  "iColumns":7,
 *  "sColumns":"",
 *  "iDisplayStart":0,
 *  "iDisplayLength":10,
 *  "amDataProp":[0,1,2,3,4,5,6],
 *  "sSearch":"",
 *  "bRegex":false,
 *  "asSearch":["","","","","","",""],
 *  "abRegex":[false,false,false,false,false,false,false],
 *  "abSearchable":[true,true,true,true,true,true,true],
 *  "iSortingCols":1,
 *  "aiSortCol":[0],
 *  "asSortDir":["asc"],
 *  "abSortable":[true,true,true,true,true,true,true]
 * }
 *
 * @author inder
 */
public class DataTablesRequest implements Serializable{

    @JsonProperty(value = "sEcho")
    public String echo;

    @JsonProperty(value = "iColumns")
    public int numColumns;

    @JsonProperty(value = "sColumns")
    public String columns;

    @JsonProperty(value = "iDisplayStart")
    public int displayStart;

    @JsonProperty(value = "iDisplayLength")
    public int displayLength;

    //has to be revisited for Object type dataProps.
    @JsonProperty(value = "amDataProp")
    public List<Integer> dataProp;

    @JsonProperty(value = "sSearch")
    public String searchQuery;

    @JsonProperty(value = "asSearch")
    public List<String> columnSearches;

    @JsonProperty(value = "bRegex")
    public boolean hasRegex;

    @JsonProperty (value = "abRegex")
    public List<Boolean> regexColumns;

    @JsonProperty (value = "abSearchable")
    public List<Boolean> searchColumns;

    @JsonProperty (value = "iSortingCols")
    public int sortingCols;

    @JsonProperty(value = "aiSortCol")
    public List<Integer> sortedColumns;

    @JsonProperty(value = "asSortDir")
    public List<String> sortDirections;

    @JsonProperty(value = "abSortable")
    public List<Boolean> sortableColumns;

    public DataTablesRequest() {
    }
}

DataTablesResponse is represented here:

/**
 * The data tables response.
 * @author inder
 */
public class DataTablesResponse <T> implements Serializable {

    @JsonProperty(value = "iTotalRecords")
    public int totalRecords;

    @JsonProperty(value = "iTotalDisplayRecords")
    public int totalDisplayRecords;

    @JsonProperty(value = "sEcho")
    public String echo;

    @JsonProperty(value = "sColumns")
    public String columns;

    @JsonProperty(value = "aaData")
    public List<T> data = new ArrayList<T>();

    public DataTablesResponse() {
    }
}

Step 3

Finally the jQuery code which converts the Datatables request into a JSON object, which is POSTed to the server. Look closely at the stringify_aoData method - it will convert the various sub-attributes of the aoData object into an object represented that can be consumed easily by the server.

Also, you can convert the modifiers array into a dictionary/map to avoid the scan which is currently being done for each attribute.

    $(document).ready(function() {
        var stringify_aoData = function (aoData) {
            var o = {};
            var modifiers = ['mDataProp_', 'sSearch_', 'iSortCol_', 'bSortable_', 'bRegex_', 'bSearchable_', 'sSortDir_'];
            jQuery.each(aoData, function(idx,obj) {
                if (obj.name) {
                    for (var i=0; i < modifiers.length; i++) {
                        if (obj.name.substring(0, modifiers[i].length) == modifiers[i]) {
                            var index = parseInt(obj.name.substring(modifiers[i].length));
                            var key = 'a' + modifiers[i].substring(0, modifiers[i].length-1);
                            if (!o[key]) {
                                o[key] = [];
                            }
                            console.log('index=' + index);
                            o[key][index] = obj.value;
                            //console.log(key + ".push(" + obj.value + ")");
                            return;
                        }
                    }
                    //console.log(obj.name+"=" + obj.value);
                    o[obj.name] = obj.value;
                }
                else {
                    o[idx] = obj;
                }
            });
            return JSON.stringify(o);
        };

        $('#example').dataTable( {
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "/api/data",
            "fnServerData": function ( sSource, aoData, fnCallback ) {
                $.ajax( {
                    dataType: 'json',
                    contentType: "application/json;charset=UTF-8",
                    type: 'POST',
                    url: sSource,
                    data: stringify_aoData(aoData),
                    success: fnCallback,
                    error : function (e) {
                        alert (e);
                    }
                } );
            }
        } );
    } );

Hope this helps with your next Datatables-Java project!

Mount Shashta from I-5.

Mount Shashta from I-5.