Friday, January 24, 2014

TableTools in JQuery modal bug

Hi,

It really annoyed me that DataTable-TableTools (http://datatables.net/extras/tabletools/) export to Excel button did not work on my page with Chrome and IE whereas it worked with Firefox. I digged out everything about browsers and flash support etc. Changed the code,  searched the web and everything... No solution! So I quit (a very rare situation :))...

After a while, I did use the same TableTools code on another page and it worked in all of these browsers. So I figured it out that this bug was about Jquery modal because in the first case, TableTools table was placed in a modal. I did a refined search and immediately found this:

$('.dialog').dialog({
                    modal: true,
                    zIndex: 1
                });
 
 
"JQuery UI has a bug where if ran in a modal, it removes the click functions from certain elements due to its default z-index."


I added this extra property: zIndex: 1 to my problematic page and it worked like a charm.

Cheers,



Tuesday, January 14, 2014

Play Framework manual access log

Hi,

I needed access log in my Play Framework project but neither I had time for installing&integrating another webserver nor the following module supports X-Forwarded-For (from now on: XFF) IP:
http://www.playframework.com/modules/accesslog

So I wrote my own... The following methods generate the following output whether the client reaches your application directly (bypassing the loadbalancer) or using load balancer so that its real IP is given in header's XFF key value (of course if your loadbalancer supports that... In my case, it is F5-BigIP):

ACCESS LOG(BSM) - <IP> - <ComputerName> - Tue Jan 14 13:12:30 EET 2014

    public static void getAuth(String page)
    {  
        String direct_ip = Http.Request.current.get().remoteAddress;
        String xff_ip = null;
        if (Http.Request.current.get().headers.get("x-forwarded-for")!=null)
            xff_ip = Http.Request.current.get().headers.get("x-forwarded-for").toString();    

        String lookableIP = direct_ip;       
        if (xff_ip!=null)
        {
            xff_ip = xff_ip.substring(1,xff_ip.length()-1);            
            lookableIP = xff_ip;
        }       
        String computerName = nslookup(lookableIP);
        Date date = new Date();
        Logger.warn("ACCESS LOG("+page+") - " + lookableIP + " - " + computerName + " - " + date);       
   
    }
    private static String nslookup(String host)
    {
        try {
            InetAddress inetHost = InetAddress.getByName(host);
            return inetHost.getHostName();
            } catch(UnknownHostException ex) {
            return "N/A";
        }
    }


Note: Play Framework version: 1.2

Bye,

Jquery template (jquery-tmpl) with Play Framework

Hi,

In order to use Jquery templates in your Play Framework project here is what you need to do in your html:

<script id="template" type="text/x-jquery-tmpl">
<div>${'$'}{rating}</div>
 </script>

Play will convert this into ${rating}, which should be the documented case:
https://github.com/BorisMoore/jquery-tmpl

Note: In this case, I used Play Framework 1.2

Cheers,