无法将 Date 和 String 对象的值打印到 GlassFish 服务器的控制台。

huangapple 未分类评论52阅读模式
英文:

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&lt;String&gt; appStrings;
    private List&lt;Appointment&gt; appointments;    

    @PostConstruct
    public void init() {
        appointments = appointmentBean.getAppointments();
        appStrings = new ArrayList&lt;&gt;();
        appointments.forEach((n) -&gt; {
            appStrings.add(&quot;START TIME: &quot; + n.getStartTime().toString());
            System.out.print(&quot;APPOINTMENT TIME STRING: &quot; + n.getStartTime().toString());
        });  
    }

    public String deleteApps() {
        if (selectedApps.length &gt; 0) {
            appointmentBean.deleteAppointment(selectedApps);
            return &quot;template.xhtml&quot;;
        } else {
            System.out.print(&quot;no apps selected&quot;);
            return &quot;&quot;;
        }
    }

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 &lt; 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.

huangapple
  • 本文由 发表于 2020年4月10日 20:01:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/61139835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定