星期三, 1月 30, 2013

[Alfresco] Tomcat/temp 的上傳暫存檔無法清除

alfresco:3.4.5 深埋很久的bug,用javascript webscript/java backed都會產生暫存檔無法清除的問題 有找到一些討論的訊息 https://issues.alfresco.com/jira/browse/ALF-2363

 =====
 Alfresco QA Team added a comment - 19-May-10 03:23 PM Validated against 3.3.0 beta 39. 
Temp files are removed according to tempFileCleanerTrigger settings in scheduled-jobs-context.xml.

 =====

 alfresco會透過tempFileCleanerTrigger 來清除檔案,相關設定在scheduled-jobs-context.xml。 設定檔路徑在以下/usr/local/TOMCAT/webapps/alfresco/WEB-INF/classes/alfresco

星期五, 1月 25, 2013

[JSP] jsp session getAttribute跟setAttribute都爆炸了 XD

機器上測試用OpenJDK做的session操作整個爆掉(不能取/不能建session)。
都會噴以下二個exception:
setAttribute: Session already invalidated
getAttribute: Session already invalidated

以下是成功於正常的Oracle JDK成功操作session的測試碼,移到新的環境就會爆掉XD

//try{

 HttpSession httpsession = request.getSession(false);
 
 if(httpsession == null){
  System.out.println("HttpSession null");
 }else{
  System.out.println("HttpSession:" + httpsession.getId());
 }
 
  if(httpsession.getAttribute("test") == null){
 
   //throw getAttribute: Session already invalidated
 //if(session.getAttribute("test") == null) { 
   System.out.println("Session not found");
   
   try{
    
    System.out.println("Start to craete session");
    
    //request.getSession(true).setAttribute("test", "HelloSession");
    //session.setAttribute("test", "HelloSession");
    //httpsession.setAttribute("test", "HelloSession");
    
    HttpSession newSession = request.getSession(true);
    if(newSession.isNew()){
     System.out.println("isNew session id:" + newSession.getId());
    }else{
     System.out.println("old session id:" + newSession.getId());
    }
   
    newSession.setAttribute("test", "HelloSession");
    
    System.out.println("Suceed to craete session");
  
    
   }catch(IllegalStateException illeagalStateEx){
    System.out.println("Fail to craete session:" 
          + illeagalStateEx.getMessage());
   }
   
  }else{
   
   System.out.println("Session found");
   
   String sessionValue = 
     (String)httpsession.getAttribute("test");
   
   System.out.println("sessionValue:" + sessionValue);
   
  }
//}catch(Exception ex){
 
 //System.out.println("Global Exception:" + ex.getMessage());

//}

星期一, 1月 21, 2013

[jQuery API] beforeunload 偵測頁面關閉或刷新

有時候你需要偵測使用者刷新或關閉頁面進行一些處理,可以使用beforeunload事件。 //refesh page event
 $(window).bind("beforeunload", function() {
   return "Are you sure?";
 });

When you add return false, a confirmation dialog shows up, delaying the page unload. Meanwhile, the AJAX request finishes. When no return statement is included, the page will immediately unloads, terminating all active connections (and breaking your AJAX request). 

目前測試發現如果使用者按上一頁的話雖會執行這個事件,但卻會造成正在執行的連線中斷(例如:上傳) 不過眼尖發現這個confirm dialog的按鈕其實長的不一樣XD 


[jQuery API] 取得$元素的內容

有時候取要取得目前jquery物件的html是什麼, 目前找到以下解法,如果有其他方法就跪求了XD
var $container = $("<div/>");
var content = $container.append($TargetElem).clone()).html();

[TOMCAT] 設定 session逾期時間

如何設定tomcat的 session逾期時間
單位:分鐘!!
 <session-config>
    <session-timeout>5</session-timeout>
  </session-config>
如果要設定成秒數的話要另外實作,根據下述的資料參考
http://www.velocityreviews.com/forums/t146162-tomcat-5-0-config-timeout-in-seconds.html

That's a strange question. Why do you want to do it?
Anyway, no, it's not possible. Not directly at least. You will have to
implement a session listener and call setMaxInactiveInterval on every
new session. There you can specify the interval in seconds

星期三, 1月 16, 2013

[jQuery plugin] jQuery File Upload

用了一陣子的jQuery File Upload,發現在FF使用小於2MB的檔案,Progress bar無法正常的讀取file bytes XD

See also:
https://github.com/blueimp/jQuery-File-Upload/issues/1905

星期五, 1月 11, 2013

[jQuery plugin] 秒 轉換 為時:分:秒格式

找到的秒數轉時分秒格式的範例
jQuery.fn.time_from_seconds = function() {
    return this.each(function() {
        var t = parseInt($(this).text(), 10);
        $(this).data('original', t);
        var h = Math.floor(t / 3600);
        t %= 3600;
        var m = Math.floor(t / 60);
        var s = Math.floor(t % 60);
        $(this).text((h > 0 ? h + ' hour' + ((h > 1) ? 's ' : ' ') : '') +
                     (m > 0 ? m + ' minute' + ((m > 1) ? 's ' : ' ') : '') +
                     s + ' second' + ((s > 1) ? 's' : ''));
    });
};
加強一下可以支援多國語言
/**
 * Time from seconds
 * Refer from 
 * @author ken tsai
 * @date 2013/1/13
 **/
;(function($) {
 
 $.fn.time_from_seconds = function() {
     return this.each(function() {
         var t = parseInt($(this).text(), 10);
         $(this).data('original', t);
         $(this).text($.timeFromSeconds(t));
     });
 };
 
 $.timeFromSeconds = function(t){
  
    var h = Math.floor(t / 3600);
       t %= 3600;
       var m = Math.floor(t / 60);
       var s = Math.floor(t % 60);
       
//       var conv = (h > 0 ? h + ' hour' + ((h > 1) ? 's ' : ' ') : '') +
//       (m > 0 ? m + ' minute' + ((m > 1) ? 's ' : ' ') : '') +
//       s + ' second' + ((s > 1) ? 's' : '');
       var hour = "", minute = "", second = "";
       if($.timeFromSeconds.defaults.plural){
        hour = (h > 0 ? h + " " + $.timeFromSeconds.defaults.hours + ((h > 1) ? "s " : " ") : " ");
        minute =  (m > 0 ? m + " " + $.timeFromSeconds.defaults.minutes + ((m > 1) ? "s " : " "):" ");
        second =  (s > 0 ? s + " " + $.timeFromSeconds.defaults.seconds + ((s > 1) ? "s " : " "): " ");
       }else{
        hour = (h > 0 ? h + " " + $.timeFromSeconds.defaults.hours: " ");
        minute =  (m > 0 ? m + " " + $.timeFromSeconds.defaults.minutes: " ");
        second =  (s > 0 ? s + " " + $.timeFromSeconds.defaults.seconds: " ");
       }
       return hour + minute + second;
 };

 $.timeFromSeconds.setDefaults = function(defaults){
  $.timeFromSeconds.defaults = defaults;
 };
 
 $.timeFromSeconds.defaults = {
  hours:"hour",
  minutes:"minute",
  seconds:"second",
  plural:true
 };
 
 
})(jQuery);

星期一, 12月 31, 2012

[jQuery UI] autocomplete 控制項

試很久才正常的自動完成控制項, 一開始用keyup的事件綁定後,向後端拿資料,再初始化自動完成控制項, 但就是會有異常的情況,包含後端包出來的JSON的客製的,別頁又可以正常work。 最後終於試了正常的方向,在這記錄一下,以免下次要用又搞很久Orz。 測試版本為jquery ui 1.9.1版
 $( "#user" ).autocomplete({
            source: function( request, response ) {
                $.ajax({
                    url: iANGEL + "manageuser/search/" + $("#user").val(),
     cache: false,
     type:"GET",
     dataType:"json",
                    success: function( data ) {
      //check response data 
      if(data.user_data.status == 200){
       response($.map( data.user_data.result, function( item ) {
        return item;
      
       }));
      }
                       
                    }
                });
            },
   select:function(event,ui){
    $.console("[AUTOCOMPLETE] select");
    //$.console(ui.item);
    $(this).val( ui.item.User_NickName).attr("data",ui.item.User_ID);
    return false;
   }
        }).data( "autocomplete" )._renderItem = function( ul, item ) {
       //$.console(item);
       
       return $( "<li>" )
        .data( "item.autocomplete", item )
        .append( "<a>" + item.User_NickName + "</a>" )
        .appendTo(ul);
  };

星期五, 12月 21, 2012

[jQuery] 頁面刷新處理 (F5鍵)

找了一些偵側頁面被觸發刷新的檢查的二個範例 第一種是補捉按鍵的keycode但是如果按瀏覽器的重新整理無法偵測
$(document).bind("keypress keydown keyup", function(e) {
 
   if(e.which === 116) {
         
         return false;
      }
      if(e.which === 82 && e.ctrlKey) {
       
      
          return false;
      }
 
 });
第二種是比較好的方法,連上一頁跟下一頁都能一起觸發
$(window).bind('beforeunload', function() {

    return "Are u sure to reload?";
});

星期四, 12月 20, 2012

[jQuery API] ajaxPrefilter

//before ajax request handler
<>
$.ajaxPrefilter(function( options, originalOptions, jqXHR ){
  $.console("[ajaxPrefilter] ajax url:" + options.url);  

 });

星期日, 12月 16, 2012

[Javascript] 日期計算的應用


常常會用到又會忘記的日期格式運算。
找了一些文章說用format("yyyy-MM-dd")可以格式化但一直爆炸XD
找到的應用會直接更新在這篇。



//取得現在的日期
var currentTime = new Date(); 
//往前推30天
currentTime.setDate(currentTime.getDate() + (-30));
//第一天跟最後一天
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

 
//格式化yyyy/mm/dd
function dateFormat(date){
  var d  = date.getDate();
  var day = (d < 10) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = (m < 10) ? '0' + m : m;
  var yy = date.getYear();
  var year = (yy < 1000) ? yy + 1900 : yy;
  
  var finalDate = year + "-" + m + "-" + d;
  return finalDate;
};

//日期相差的天數
function getDiffDays(endDate){
 var date1 = new Date();
  var date2 = new Date(Date.parse(endDate.replace("-", "/")));
  var date3 = date2.getTime() - date1.getTime();//時間差的毫秒数  
  var days = Math.floor(date3/(24*3600*1000));//相差天數
  return days;
};

星期一, 12月 10, 2012

[Javascript] Detect flash version

偵測客戶端目前有沒有裝Flash的外掛。

I agree with Max Stewart. SWFObject is the way to go. I'd like to supplement his answer with a code example. This ought to to get you started:
if(swfobject.hasFlashPlayerVersion("9.0.115"))
{
    alert("You have the minimum required flash version (or newer)");
}
else
{
    alert("You do not have the minimum required flash version");
}
Replace "9.0.115" with whatever minimum flash version you need. I chose 9.0.115 as an example because that's the version that added h.264 support.
If the visitor does not have flash, it will report a flash version of "0.0.0", so if you just want to know if they have flash at all, use:
if(swfobject.hasFlashPlayerVersion("1"))
{
    alert("You have flash!");
}
else
{
    alert("You do not flash :-(");
}

星期日, 12月 09, 2012

[Javascript] setTimeout

經常會使用的setTimeout方法,做個筆記

設定Timeout,預設只會執行一次,毫秒為單位

setTimeout(function() { myFunc(); }, 4000)

重覆執行setTimeout

function myFunc(){
  setTimeout(function(){ myFunc();},4000)
}

取消setTimeout

var timerID = setTimeout(function(){ myFunc();},4000)
clearTimeout(timerID );


設定條件停止


function myFunc(){
if(flag == true){
  setTimeout(function(){ myFunc();},4000)
}
}

星期四, 11月 29, 2012

[Javascript] 檢查IE Document Mode

客戶遇到ie無法正確指定文件模式的問題。 只要在ui加上<meta http-equiv="X-UA-Compatible" content="IE=edge">,即可。 不過要避免在它之前有其他script執行(網民建議)。 不過今天在客戶那邊處理的時候,之前把content內多加了一個IE=edge,chrome=1,會導致無法正確告訴ie使用最新的文件模式檢視(content)。 以下的語法可以偵測目前用戶的文件模式。
function checkIEDocumentMode(){
 
 if (window.navigator.appName == "Microsoft Internet Explorer")
 {
    if (document.documentMode){
     USERAGENT = document.documentMode;
    } // IE8
    else // IE 5-7
    {
     USERAGENT = 5; // Assume quirks mode unless proven otherwise
       if (document.compatMode)
       {
          if (document.compatMode == "CSS1Compat")
           USERAGENT = 7; // standards mode
       }
    }
    // the USERAGENT variable now contains the document compatibility mode.
    $.console("checkIEDocumentMode:" + USERAGENT);
    //var $metaTag = $("");
    //$metaTag.appendTo("head");
    //content="IE=Value" value types:5、6、7、8、9、10、EmulateIE7、EmulateIE8、Edge
 }
}

星期五, 11月 23, 2012

[jQuery] 價錢格式化

想要讓你網站顯示的數字讓使用者更容易閱讀嗎?
可以使用jquery price format 來快速完成唷
http://jquerypriceformat.com/


其他你感興趣的文章

Related Posts with Thumbnails