All posts by stackoverflow

Like functionality in sharepoint custom aspx page

I want to enable “like” functionality (i.e.) count of likes on custom “aspx ” page created on SharePoint site. Below is the jQuery code for like functionality that I have found.

var likepage = {
    //Likes the current page. 
    LikePage: function () {
        likepage.getUserLikedPage(function(likedPage, likeCount) {

            var aContextObject = new SP.ClientContext();
            EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function() {
                        _spPageContextInfo.pageListId.substring(1, 37),
                        _spPageContextInfo.pageItemId, !likedPage);

                    function() {
                        var elements = document.getElementsByClassName('likecount');
                        if (likedPage) {
                        } else {
                        for (var i = 0; i < elements.length;i++) {
                            elements[i].innerHTML = likeCount;
                    }, function(sender, args) {
                        // Custom error handling if needed


    // Checks if the user already liked the page, and returns the number of likes. 
    getUserLikedPage: function (cb) {
        var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
        var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
        var item = list.getItemById(_spPageContextInfo.pageItemId);

        context.load(item, "LikedBy", "ID", "LikesCount");
        context.executeQueryAsync(Function.createDelegate(this, function (success) {
            // Check if the user id of the current users is in the collection LikedBy. 
            var $v_0 = item.get_item('LikedBy');
            if (!SP.ScriptHelpers.isNullOrUndefined($v_0)) {
                for (var $v_1 = 0, $v_2 = $v_0.length; $v_1 < $v_2; $v_1++) {
                    var $v_3 = $v_0[$v_1];
                    if ($v_3.$1E_1 === _spPageContextInfo.userId) {
                        cb(true, item.get_item('LikesCount'));
            cb(false, item.get_item('LikesCount'));
            Function.createDelegate(this, function (sender, args) { 
            //Custom error handling if needed 
    initialize: function () {
        var elements = document.getElementsByClassName('likecount');
        likepage.getUserLikedPage(function(likedPage, likesCount) {
            for (var i = 0; i < elements.length; i++) {
                elements[i].innerHTML = likesCount;

read more

JPA when to use Path of entity type instead of Join?

An example in JPA spec:

CriteriaQuery<Customer> q = cb.createQuery(Customer.class);
Root<Customer> customer = q.from(Customer.class);
Join<Customer, Order> order = customer.join(Customer_.orders);
q.where(cb.equal(cb.treat(order.get(Order_.product), Book.class)

order.product is a path in the where clause. If it is not join, how to access
the name attribute of the product(Book)? Is it actually a table join when translated to SQL? If this is the case, what is the difference between path
and join in this example?

read more

Looking for the puppy owner’s name that had the puppy most serviced by the Puppy Grooming

I have couple of tables:
The first one: Owner

Owner_ID    Owner_Name      
   1           Sam  
   2          Andrea
   3          Gabriela

Second one:

Puppy_ID   servided_date
1               01/25/2012
2               02/18/2012
3               05/14/2012

Third One:

Puppy's table

Puppy_ID     Owner_ID
1               1
2               2
3                3

I have this code:

Select owner_name
from puppy p, owner o 
where p.owner_id = o.owner_ID

From here I am stuck. I was thinking of a join between the tables but I am not sure

read more