2016-09-25 76 views
0

我正在使用GWT,Java,iText來生成PDF並希望重新格式化日期。但是,此代碼,在服務器端,導致客戶端上的「連接失敗」的消息(也有日誌中沒有錯誤消息),無輸出:如果在服務器端使用iText導致連接失敗

  String storedName = " "; 
      DateTimeFormat sdf = DateTimeFormat.getFormat("dd-MM-yyyy"); 

      for (final Transcript scoutNamesDescription : listymAwards) { 

       if (scoutNamesDescription.getSection().equals(storedName)){ 
        table.addCell(" "); 
       }else{ 
        storedName = scoutNamesDescription.getSection(); 
        table.addCell(scoutNamesDescription.getSection()); 
       } 
       table.addCell(scoutNamesDescription.getAwardName()); 

       Date awardedDate = sdf.parse(scoutNamesDescription.getAwardedDate()); 
       String awardedString = DateTimeFormat.getFormat("dd-MM-yyyy").format(awardedDate); 
       table.addCell(awardedString);  
      } 
      preface.add(table); 
      document.add(preface); 

當我註釋掉日期格式化這工作。

我曾嘗試與更換格式化:

System.out.println(scoutNamesDescription.getAwardedDate()); 
       formatedDate = StringUtils.substring(scoutNamesDescription.getAwardedDate(), 8, 2) + 
         StringUtils.substring(scoutNamesDescription.getAwardedDate(), 4, 4) + 
         StringUtils.substring(scoutNamesDescription.getAwardedDate(), 0, 2); 
       System.out.println(formatedDate); 

,這也產生兩個之間的println同樣的錯誤。

基於安德烈·沃爾金的答覆,我有以下:

  String storedName = null; 
      DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd"); 
      DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy"); 

      for (final Transcript scoutNamesDescription : listymAwards) { 

       if (scoutNamesDescription.getSection().equals(storedName)){ 
        table.addCell(" "); 
       }else{ 
        storedName = scoutNamesDescription.getSection(); 
        table.addCell(scoutNamesDescription.getSection()); 
       } 
       table.addCell(scoutNamesDescription.getAwardName()); 

       Date awardedDate = df1.parse(scoutNamesDescription.getAwardedDate()); 
       String awardedString = df2.format(awardedDate); 
       table.addCell(awardedString); 
      } 
      preface.add(table); 
      document.add(preface); 
     } 
+0

是你的所有'include's在'server'或'shared'包? – Adam

+0

嗨,亞當,我確信我已經全部包括在內了,因爲我沒有收到他們不在的任何錯誤信息。 – Glyn

+0

'DateTimeFormat'有兩個版本:'com.google.gwt.i18n.client'和'com.google.gwt.i18n.shared'包。第一個客戶端只能在客戶端使用,共享版本可以在客戶端和服務器端使用。仔細檢查這包括。 – Adam

回答

相關問題