2016-09-25 8 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); 

そして、これは、2つのprintlnの間で同じエラーを生成します。

アンドレイVolginの回答に基づいて、私は次があります。

  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

ていますか? – Adam

+0

こんにちはアダム、私はすべてが含まれていると私は信じて、私は通常、そこにないときに発生するエラーメッセージが表示されません。 – Glyn

+0

'DateTimeFormat'には、' com.google.gwt.i18n.client'と 'com.google.gwt.i18n.shared'パッケージの2つのバージョンがあります。最初のクライアントはクライアント側でのみ使用され、共有バージョンはクライアント側とサーバー側の両方で使用できます。これは注意深くチェックしてください。 – Adam

答えて

1

あなたは、サーバー側でGWTコードを使用することはできません。この場合、必要はありません。書式設定の日付の

使用する標準のJavaツールを: `server`または` shared`パッケージ内のすべてのあなたの `include`sが Convert java.util.Date to String

関連する問題