简体   繁体   English

如何使用以下命令从我的bean中的XHTML检索值 <p:ajax> 在素面?

[英]How to retrieve a value from XHTML in my bean using <p:ajax> on primefaces?

2.8 and Primefaces 6.0 And i want to retrieve the value of a date from my xhtml to make specific treatments Before submitting my form. 2.8和Primefaces 6.0并且我想在提交表单之前从我的xhtml中检索日期的值以进行特定处理。

But the value of the date is always null in the bean Before submitting. 但是,在提交之前,bean中的日期值始终为null。

Here is my XHTML 这是我的XHTML

                            <p:outputLabel for="dateDebut" value="Date Debut"/>
                        <p:calendar id="dateDebut" value="#{etpBean.dateDebut}" required="true">
                            <p:ajax listener="#{etpBean.listenerDateDebut}" event="change"/>
                        </p:calendar>

And here is my function in my bean 这是我在bean中的功能

public Date listenerDateDebut(){
    return dateDebut;
}

From the PrimeFaces 6 documentation : PrimeFaces 6文档中

Ajax Behavior Events Ajax行为事件

Calendar provides a dateSelect ajax behavior event to execute an instant ajax selection whenever a date is selected. 日历提供了dateSelect ajax行为事件,以便在选择日期时立即执行ajax选择。 If you define a method as a listener, it will be invoked by passing an org.primefaces.event.SelectEvent instance. 如果将方法定义为侦听器,则将通过传递org.primefaces.event.SelectEvent实例来调用该org.primefaces.event.SelectEvent

 <p:calendar value="#{calendarBean.date}"> <p:ajax event="dateSelect" listener="#{bean.handleDateSelect}" update="msg" /> </p:calendar> <p:messages id="msg" /> 
 public void handleDateSelect(SelectEvent event) { Date date = (Date) event.getObject(); //Add facesmessage } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM