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);
}
是你的所有'include's在'server'或'shared'包? – Adam
嗨,亚当,我确信我已经全部包括在内了,因为我没有收到他们不在的任何错误信息。 – Glyn
'DateTimeFormat'有两个版本:'com.google.gwt.i18n.client'和'com.google.gwt.i18n.shared'包。第一个客户端只能在客户端使用,共享版本可以在客户端和服务器端使用。仔细检查这包括。 – Adam