Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在JSF中的网页上显示系统日期?_Java_Jsf_Jsf 2 - Fatal编程技术网

Java 如何在JSF中的网页上显示系统日期?

Java 如何在JSF中的网页上显示系统日期?,java,jsf,jsf-2,Java,Jsf,Jsf 2,我想在jsf页面中显示当前的语言环境系统日期。我有下面的代码,但它不工作 <p:column styleClass="columnA">SOP Date</p:column> <p:column styleClass="columnB"> <h:outputText value="#{bean.currentDate}" /> </p:column> 例如: <h:outputText value="#{bean.cur

我想在jsf页面中显示当前的语言环境系统日期。我有下面的代码,但它不工作

<p:column styleClass="columnA">SOP Date</p:column>
<p:column styleClass="columnB">
    <h:outputText value="#{bean.currentDate}" />
</p:column>
例如:

<h:outputText value="#{bean.currentDate}">
   <f:convertDateTime type="date" pattern="#{bean.format}" timeZone="(here your timezone)"/>
 </h:outputText>

不起作用是什么意思?
我的意思是,系统日期没有使用上述代码显示在网页上。@PostConstruct不起作用?您是否在bean中的init方法之后检查了currentDate?请注意,为了安全起见,您应该将属性声明为
private
,并使用getter/setter将其公开。您不必传递字符串日期,您可以使用Date属性来显示日期。日期模式应该取自浏览器设置。当您可以在Bean中拥有另一个属性时,我将编辑答案。我粘贴的代码刚刚添加了sysout及其在服务器日志中填充系统日期,但没有显示在网页中。请将ViewScoped添加到Bean。
<h:outputText value="#{bean.currentDate}">
   <f:convertDateTime type="date" pattern="#{bean.format}" timeZone="(here your timezone)"/>
 </h:outputText>
@ManagedBean(name = "bean")
@ViewScoped
public class SopDate implements Serializable {

    public Date currentDate;
    public String format;  

    @PostConstruct
    public void init(){
       SopCurrentDate();
    }

    public void SopCurrentDate(){
       currentDate = new Date(); 
       format = "dd-MM-yyyy";
    }
      // getter and setter
}