英文:
Unable to print the values of Date and String objects to the console in glassfish server
问题
以下是翻译好的内容:
在一个 CDI 管理的 bean 中,我有如下代码,它调用了一个 Appointment 对象的 Date 类型属性的打印操作,我首先在 Date 对象上调用了 .toString()
,这样可以正常打印:
private String[] selectedApps;
private List<String> appStrings;
private List<Appointment> appointments;
@PostConstruct
public void init() {
appointments = appointmentBean.getAppointments();
appStrings = new ArrayList<>();
appointments.forEach((n) -> {
appStrings.add("START TIME: " + n.getStartTime().toString());
System.out.print("APPOINTMENT TIME STRING: " + n.getStartTime().toString());
});
}
public String deleteApps() {
if (selectedApps.length > 0) {
appointmentBean.deleteAppointment(selectedApps);
return "template.xhtml";
} else {
System.out.print("no apps selected");
return "";
}
}
然而,在一个 EJB 中,我有另一个方法 deleteAppointment(String[] appStrings)
,它尝试打印从 deleteApps()
方法传递过来的相同值,但却无法打印出来:
public void deleteAppointment(String[] appStrings) {
for (int i = 0; i < appStrings.length; i++) {
String startStr = (appStrings[i].substring(12)).trim();
System.out.print(startStr);
}
}
我在从 CDI bean 到 EJB 进行打印的值之间唯一的不同之处,就是我在字符串上调用了 .substring()
和 .trim()
方法。如果我不使用这些方法,而是尝试直接打印原始字符串,那么打印就会成功。在 EJB 方法 deleteAppointments
中没有任何错误、异常抛出,也没有任何输出被发送到控制台。我也没有找到解决这个问题的方法。
谢谢,Sam。
英文:
I have a CDI managed bean like this, which makes a call to print a Date type property of an Appointment object, I am calling .toString()
on the Date object first and this prints with no problems:
private String[] selectedApps;
private List<String> appStrings;
private List<Appointment> appointments;
@PostConstruct
public void init() {
appointments = appointmentBean.getAppointments();
appStrings = new ArrayList<>();
appointments.forEach((n) -> {
appStrings.add("START TIME: " + n.getStartTime().toString());
System.out.print("APPOINTMENT TIME STRING: " + n.getStartTime().toString());
});
}
public String deleteApps() {
if (selectedApps.length > 0) {
appointmentBean.deleteAppointment(selectedApps);
return "template.xhtml";
} else {
System.out.print("no apps selected");
return "";
}
}
However, in an EJB I have another method, deleteAppointment(String[] appStrings)
, which is trying to print these same values that have been passed to it from the deleteApps()
method and it is unable to do so:
public void deleteAppointment(String[] appStrings) {
for (int i = 0; i < appStrings.length; i++) {
String startStr = (appStrings[i].substring(12)).trim();
System.out.print(startStr);
}
}
The only difference in the value that I am attempting to print from the CDI bean to the EJB, is that I have called the .substring()
and .trim()
methods on the string and if i don't use those methods and simply try to print the original string, then the print is successful. There are no errors or exceptions being thrown and no output of any kind to the console from the EJB method deleteAppointments
. I have also been unable to find any solutions to this problem.
Thanks, Sam.
专注分享java语言的经验与见解,让所有开发者获益!
评论